1 /*
2  * ViewpointDialog.cpp
3  *
4  * Copyright (C) 2000 Stephen F. White, 2018 J. "MUFTI" Scheurich
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program (see the file "COPYING" for details); if
18  * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19  * Cambridge, MA 02139, USA.
20  */
21 
22 #include "stdafx.h"
23 #include "ViewpointDialog.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include "swt.h"
27 #include "resource.h"
28 #include "Scene.h"
29 #include "NodeViewpoint.h"
30 
ViewpointDialog(SWND parent,int idd,Scene * scene)31 ViewpointDialog::ViewpointDialog(SWND parent, int idd, Scene *scene)
32   : Dialog(parent, idd)
33 {
34     Node *viewpoint = scene->getCamera();
35     m_dist = 0;
36     Vec3d vec = viewpoint->getPosition();
37     if (viewpoint)
38         m_dist = sqrt((vec.x * vec.x) + (vec.y * vec.y) + (vec.z * vec.z));
39     m_viewpointData = NULL;
40     LoadData();
41 }
42 
~ViewpointDialog()43 ViewpointDialog::~ViewpointDialog()
44 {
45 }
46 
47 void
SaveData()48 ViewpointDialog::SaveData()
49 {
50     char buf[128];
51 
52     swGetText(swGetDialogItem(m_dlg, IDC_DISTANCE), buf, 128);
53     m_dist = atof(buf);
54     if (swGetCheck(swGetDialogItem(m_dlg, IDC_VIEWPOINT_X_MINUS))) {
55         m_data[0] = 10;
56         m_data[1] = 0;
57         m_data[2] = 0;
58         m_data[3] = 0;
59         m_data[4] = 1;
60         m_data[5] = 0;
61         m_data[6] = M_PI / 2;
62         m_viewpointData = (float *)&m_data;
63     } else if (swGetCheck(swGetDialogItem(m_dlg, IDC_VIEWPOINT_X_PLUS))) {
64         m_data[0] = -10;
65         m_data[1] = 0;
66         m_data[2] = 0;
67         m_data[3] = 0;
68         m_data[4] = 1;
69         m_data[5] = 0;
70         m_data[6] = -M_PI / 2;
71         m_viewpointData = (float *)&m_data;
72     } else if (swGetCheck(swGetDialogItem(m_dlg, IDC_VIEWPOINT_Y_MINUS))) {
73         m_data[0] = 0;
74         m_data[1] = 10;
75         m_data[2] = 0;
76         m_data[3] = 1;
77         m_data[4] = 0;
78         m_data[5] = 0;
79         m_data[6] = -M_PI / 2;
80         m_viewpointData = (float *)&m_data;
81     } else if (swGetCheck(swGetDialogItem(m_dlg, IDC_VIEWPOINT_Y_PLUS))) {
82         m_data[0] = 0;
83         m_data[1] = -10;
84         m_data[2] = 0;
85         m_data[3] = 1;
86         m_data[4] = 0;
87         m_data[5] = 0;
88         m_data[6] = M_PI / 2;
89         m_viewpointData = (float *)&m_data;
90     } else if (swGetCheck(swGetDialogItem(m_dlg, IDC_VIEWPOINT_Z_MINUS))) {
91         m_data[0] = 0;
92         m_data[1] = 0;
93         m_data[2] = 10;
94         m_data[3] = 1;
95         m_data[4] = 0;
96         m_data[5] = 0;
97         m_data[6] = 0;
98         m_viewpointData = (float *)&m_data;
99     } else if (swGetCheck(swGetDialogItem(m_dlg, IDC_VIEWPOINT_Z_PLUS))) {
100         m_data[0] = 0;
101         m_data[1] = 0;
102         m_data[2] = -10;
103         m_data[3] = 0;
104         m_data[4] = 1;
105         m_data[5] = 0;
106         m_data[6] = M_PI;
107         m_viewpointData = (float *)&m_data;
108     }
109     m_validDist = swGetCheck(swGetDialogItem(m_dlg,
110         IDC_SET_NAVIGATION_INFO_AVATARSIZE3));
111 }
112 
113 bool
Validate()114 ViewpointDialog::Validate()
115 {
116     bool radioButtons[6];
117 
118     radioButtons[0] = swGetCheck(swGetDialogItem(m_dlg, IDC_VIEWPOINT_X_PLUS));
119     radioButtons[1] = swGetCheck(swGetDialogItem(m_dlg, IDC_VIEWPOINT_Y_PLUS));
120     radioButtons[2] = swGetCheck(swGetDialogItem(m_dlg, IDC_VIEWPOINT_Z_PLUS));
121     radioButtons[3] = swGetCheck(swGetDialogItem(m_dlg, IDC_VIEWPOINT_X_MINUS));
122     radioButtons[4] = swGetCheck(swGetDialogItem(m_dlg, IDC_VIEWPOINT_Y_MINUS));
123     radioButtons[5] = swGetCheck(swGetDialogItem(m_dlg, IDC_VIEWPOINT_Z_MINUS));
124 
125     bool first = radioButtons[0];
126     for (int i = 1; i < 6; i++)
127         if (first && radioButtons[i])
128             return false;
129     return true;
130 }
131 
132 void
LoadData()133 ViewpointDialog::LoadData()
134 {
135     char buf[128];
136 
137     mysnprintf(buf, 128, "%f", m_dist);
138     swSetText(swGetDialogItem(m_dlg, IDC_DISTANCE), buf);
139 
140     swSetCheck(swGetDialogItem(m_dlg, IDC_SET_NAVIGATION_INFO_AVATARSIZE3), 1);
141 }
142