1 |
/* All Rights reserved */ |
/* All Rights reserved */ |
2 |
|
|
3 |
#include <AppKit/AppKit.h> |
#include <AppKit/AppKit.h> |
4 |
|
#include <GL/gl.h> |
5 |
#include "ModelView.h" |
#include "ModelView.h" |
6 |
#include "CameraControl.h" |
#include "CameraControl.h" |
7 |
#include "Common/Camera.h" |
#include "Common/Camera.h" |
9 |
|
|
10 |
@implementation CameraControl |
@implementation CameraControl |
11 |
|
|
12 |
|
- (void) initialize: (id)sender |
|
- (void) validate: (id)sender |
|
13 |
{ |
{ |
14 |
|
[_cameraPositionZ setDoubleValue: 100.0]; |
15 |
|
[_cameraPositionY setDoubleValue: 0.0]; |
16 |
|
[_cameraPositionX setDoubleValue: 0.0]; |
17 |
|
|
18 |
|
[_cameraZFar setDoubleValue: 10000]; |
19 |
|
[_cameraZNear setDoubleValue: 0.1]; |
20 |
|
[_cameraAspect setDoubleValue: 1.0]; |
21 |
|
[_cameraFovy setDoubleValue: 60]; |
22 |
|
|
23 |
|
[_decalageVertical setDoubleValue: 0]; |
24 |
|
[_decalageHorizontal setDoubleValue: 0]; |
25 |
|
[_zoom setDoubleValue: 0]; |
26 |
|
[_slideVertical setDoubleValue: 0]; |
27 |
|
[_slideHorizontal setDoubleValue: 0]; |
28 |
|
[_slideZoom setDoubleValue: 0]; |
29 |
|
[_headingAngle setDoubleValue: 0]; |
30 |
|
[_pitchAngle setDoubleValue: 0]; |
31 |
|
[_rollAngle setDoubleValue: 0]; |
32 |
|
|
33 |
|
_camera = [_camera initWithFovy: 60 |
34 |
|
aspect: 1 |
35 |
|
zNear: 0.1 |
36 |
|
zFar: 10000 |
37 |
|
eye: MakeCoord(0.0,0.0,100.0) |
38 |
|
center: MakeCoord(0.0,0.0,0.0) |
39 |
|
up: MakeCoord(0.0,1.0,0.0)]; |
40 |
|
|
41 |
_camera = [_camera initWithFovy: [_cameraFovy doubleValue] |
// [_cameraView setCam: _camera]; |
42 |
aspect: [_cameraAspect doubleValue] |
} |
|
zNear: [_cameraZNear doubleValue] |
|
|
zFar: [_cameraZFar doubleValue] |
|
|
eye: MakeCoord([_cameraPositionX floatValue], |
|
|
[_cameraPositionY floatValue], |
|
|
[_cameraPositionZ floatValue]) |
|
|
center: MakeCoord([_cameraPositionX floatValue] |
|
|
+ [_cameraDirectionX floatValue], |
|
|
[_cameraPositionY floatValue] |
|
|
+ [_cameraDirectionY floatValue], |
|
|
[_cameraPositionZ floatValue] |
|
|
+ [_cameraDirectionZ floatValue]) |
|
|
|
|
|
up: MakeCoord([_cameraUpX floatValue], |
|
|
[_cameraUpY floatValue], |
|
|
[_cameraUpZ floatValue]) ]; |
|
43 |
|
|
44 |
|
- (void) validate: (id)sender |
45 |
[_cameraView setCam: _camera]; |
{ |
46 |
|
ASSIGN(_camera, [_cameraView cam]); |
47 |
|
|
48 |
|
[_camera initWithFovy: [_cameraFovy doubleValue] |
49 |
|
aspect: [_cameraAspect doubleValue] |
50 |
|
zNear: [_cameraZNear doubleValue] |
51 |
|
zFar: [_cameraZFar doubleValue] |
52 |
|
eye: MakeCoord(0.0,0.0,100.0) |
53 |
|
center: MakeCoord(0.0,0.0,0.0) |
54 |
|
up: MakeCoord(0.0,1.0,0.0)]; |
55 |
|
|
56 |
|
[_camera rotateAroundViewHeading: [_headingAngle doubleValue]]; |
57 |
|
[_camera rotateAroundViewPitch: [_pitchAngle doubleValue]]; |
58 |
|
[_camera rotateRoll: [_rollAngle doubleValue]]; |
59 |
|
|
60 |
|
[_camera moveTo: MakeCoord([_cameraPositionX doubleValue], |
61 |
|
[_cameraPositionY doubleValue], |
62 |
|
[_cameraPositionZ doubleValue])]; |
63 |
|
|
64 |
|
[_camera move: MultCoord([_camera dir],[_zoom intValue])]; |
65 |
|
[_camera move: MultCoord([_camera ortho],-[_decalageHorizontal intValue])]; |
66 |
|
[_camera move: MultCoord([_camera up],-[_decalageVertical intValue])]; |
67 |
|
|
68 |
} |
} |
69 |
|
|
70 |
- (id) init |
- (id) init |
71 |
{ |
{ |
72 |
self = [super init]; |
self = [super init]; |
73 |
_camera = [_cameraView cam]; |
_camera = [_cameraView cam]; |
|
coord_t ortho = [_camera ortho]; |
|
74 |
coord_t eye = [_camera eye]; |
coord_t eye = [_camera eye]; |
|
coord_t dir = SubCoord([_camera center],[_camera eye]); |
|
|
coord_t up = [_camera up]; |
|
75 |
|
|
76 |
[_cameraOrthoZ setStringValue: [NSString stringWithFormat: @"%g", ortho.z]]; |
[_cameraPositionZ setDoubleValue: eye.z]; |
77 |
[_cameraOrthoY setStringValue: [NSString stringWithFormat: @"%g", ortho.y]]; |
[_cameraPositionY setDoubleValue: eye.y]; |
78 |
[_cameraOrthoX setStringValue: [NSString stringWithFormat: @"%g", ortho.x]]; |
[_cameraPositionX setDoubleValue: eye.x]; |
79 |
[_cameraUpZ setStringValue: [NSString stringWithFormat: @"%g", up.z]]; |
|
80 |
[_cameraUpY setStringValue: [NSString stringWithFormat: @"%g", up.y]]; |
[_cameraZFar setDoubleValue: [_camera zFar]]; |
81 |
[_cameraUpX setStringValue: [NSString stringWithFormat: @"%g", up.x]]; |
[_cameraZNear setDoubleValue: [_camera zNear]]; |
82 |
[_cameraDirectionZ setStringValue: [NSString stringWithFormat:@"%g", dir.z]]; |
[_cameraAspect setDoubleValue: [_camera aspect]]; |
83 |
[_cameraDirectionY setStringValue: [NSString stringWithFormat:@"%g", dir.y]]; |
[_cameraFovy setDoubleValue: [_camera fovy]]; |
84 |
[_cameraDirectionX setStringValue: [NSString stringWithFormat:@"%g", dir.x]]; |
|
85 |
[_cameraPositionZ setStringValue: [NSString stringWithFormat:@"%g", eye.z]]; |
[_decalageVertical setDoubleValue: 0]; |
86 |
[_cameraPositionY setStringValue: [NSString stringWithFormat:@"%g", eye.y]]; |
[_decalageHorizontal setDoubleValue: 0]; |
87 |
[_cameraPositionX setStringValue: [NSString stringWithFormat:@"%g", eye.x]]; |
[_zoom setDoubleValue: 0]; |
88 |
[_cameraZFar setStringValue: [NSString stringWithFormat:@"%g", |
[_slideVertical setDoubleValue: 0]; |
89 |
[_camera zFar]]]; |
[_slideHorizontal setDoubleValue: 0]; |
90 |
[_cameraZNear setStringValue:[NSString stringWithFormat:@"%g", |
[_slideZoom setDoubleValue: 0]; |
91 |
[_camera zNear]]]; |
[_headingAngle setDoubleValue: 0]; |
92 |
[_cameraAspect setStringValue: [NSString stringWithFormat:@"%g", |
[_pitchAngle setDoubleValue: 0]; |
93 |
[_camera aspect]]]; |
[_rollAngle setDoubleValue: 0]; |
94 |
[_cameraFovy setStringValue: [NSString stringWithFormat:@"%g", |
|
|
[_camera fovy]]]; |
|
95 |
return self; |
return self; |
96 |
} |
} |
97 |
|
|
98 |
- (void) update |
- (void) update |
99 |
{ |
{ |
100 |
_camera = [_cameraView cam]; |
_camera = [_cameraView cam]; |
|
coord_t ortho = [_camera ortho]; |
|
101 |
coord_t eye = [_camera eye]; |
coord_t eye = [_camera eye]; |
|
coord_t dir = SubCoord([_camera center],[_camera eye]); |
|
|
coord_t up = [_camera up]; |
|
102 |
|
|
103 |
[_cameraOrthoZ setStringValue: [NSString stringWithFormat: @"%g", ortho.z]]; |
[_cameraPositionZ setDoubleValue: eye.z]; |
104 |
[_cameraOrthoY setStringValue: [NSString stringWithFormat: @"%g", ortho.y]]; |
[_cameraPositionY setDoubleValue: eye.y]; |
105 |
[_cameraOrthoX setStringValue: [NSString stringWithFormat: @"%g", ortho.x]]; |
[_cameraPositionX setDoubleValue: eye.x]; |
106 |
[_cameraUpZ setStringValue: [NSString stringWithFormat: @"%g", up.z]]; |
|
107 |
[_cameraUpY setStringValue: [NSString stringWithFormat: @"%g", up.y]]; |
[_cameraZFar setDoubleValue: [_camera zFar]]; |
108 |
[_cameraUpX setStringValue: [NSString stringWithFormat: @"%g", up.x]]; |
[_cameraZNear setDoubleValue: [_camera zNear]]; |
109 |
[_cameraDirectionZ setStringValue: [NSString stringWithFormat:@"%g", |
[_cameraAspect setDoubleValue: [_camera aspect]]; |
110 |
dir.z]]; |
[_cameraFovy setDoubleValue: [_camera fovy]]; |
111 |
[_cameraDirectionY setStringValue: [NSString stringWithFormat:@"%g", |
|
112 |
dir.y]]; |
[_decalageVertical setDoubleValue: 0]; |
113 |
[_cameraDirectionX setStringValue: [NSString stringWithFormat:@"%g", |
[_decalageHorizontal setDoubleValue: 0]; |
114 |
dir.x]]; |
[_zoom setDoubleValue: 0]; |
115 |
[_cameraPositionZ setStringValue: [NSString stringWithFormat:@"%g", eye.z]]; |
|
116 |
[_cameraPositionY setStringValue: [NSString stringWithFormat:@"%g", eye.y]]; |
[_slideVertical setDoubleValue: [_decalageVertical doubleValue]]; |
117 |
[_cameraPositionX setStringValue: [NSString stringWithFormat:@"%g", eye.x]]; |
[_slideHorizontal setDoubleValue: [_decalageHorizontal doubleValue]]; |
118 |
[_cameraZFar setStringValue: [NSString stringWithFormat:@"%g", |
[_slideZoom setDoubleValue: [_zoom doubleValue]]; |
119 |
[_camera zFar]]]; |
|
120 |
[_cameraZNear setStringValue: [NSString stringWithFormat:@"%g", |
[_headingAngle setDoubleValue: 0]; |
121 |
[_camera zNear]]]; |
[_pitchAngle setDoubleValue: 0]; |
122 |
[_cameraAspect setStringValue: [NSString stringWithFormat:@"%g", |
[_rollAngle setDoubleValue: 0]; |
|
[_camera aspect]]]; |
|
|
[_cameraFovy setStringValue: [NSString stringWithFormat:@"%g", |
|
|
[_camera fovy]]]; |
|
123 |
} |
} |
124 |
|
|
125 |
- (void) fax: (id)sender |
- (void) fax: (id)sender |
148 |
|
|
149 |
- (void) takeIntValueFrom: (id)sender |
- (void) takeIntValueFrom: (id)sender |
150 |
{ |
{ |
151 |
/* insert your code here */ |
if (sender == _zoom) |
152 |
|
{ |
153 |
|
[_slideZoom setIntValue: [_zoom intValue]]; |
154 |
|
} |
155 |
|
if (sender == _slideZoom) |
156 |
|
{ |
157 |
|
[_zoom setIntValue: [_slideZoom intValue]]; |
158 |
|
} |
159 |
|
if (sender == _decalageVertical) |
160 |
|
{ |
161 |
|
[_slideVertical setIntValue: [_decalageVertical intValue]]; |
162 |
|
} |
163 |
|
if (sender == _slideVertical) |
164 |
|
{ |
165 |
|
[_decalageVertical setIntValue: [_slideVertical intValue]]; |
166 |
|
} |
167 |
|
if (sender == _decalageHorizontal) |
168 |
|
{ |
169 |
|
[_slideHorizontal setIntValue: [_decalageHorizontal intValue]]; |
170 |
|
} |
171 |
|
if (sender == _slideHorizontal) |
172 |
|
{ |
173 |
|
[_decalageHorizontal setIntValue: [_slideHorizontal intValue]]; |
174 |
|
} |
175 |
|
|
176 |
|
[self validate: self]; |
177 |
} |
} |
178 |
|
|
179 |
|
|
188 |
/* insert your code here */ |
/* insert your code here */ |
189 |
} |
} |
190 |
|
|
191 |
|
- (void) changeMode: (id)sender |
192 |
|
{ |
193 |
|
if (sender == _modePoints) |
194 |
|
{ |
195 |
|
[_modePolygon setState: NO]; |
196 |
|
[_modeFilsDeFer setState: NO]; |
197 |
|
|
198 |
|
[_modePoints setEnabled: NO]; |
199 |
|
[_modeFilsDeFer setEnabled: YES]; |
200 |
|
[_modePolygon setEnabled: YES]; |
201 |
|
|
202 |
|
[_cameraView changeModeAff: GL_POINT]; |
203 |
|
} |
204 |
|
|
205 |
|
if (sender == _modeFilsDeFer) |
206 |
|
{ |
207 |
|
[_modePolygon setState: NO]; |
208 |
|
[_modePoints setState: NO]; |
209 |
|
|
210 |
|
[_modePoints setEnabled: YES]; |
211 |
|
[_modeFilsDeFer setEnabled: NO]; |
212 |
|
[_modePolygon setEnabled: YES]; |
213 |
|
|
214 |
|
[_cameraView changeModeAff: GL_LINE]; |
215 |
|
} |
216 |
|
|
217 |
|
if (sender == _modePolygon) |
218 |
|
{ |
219 |
|
[_modePoints setState: NO]; |
220 |
|
[_modeFilsDeFer setState: NO]; |
221 |
|
|
222 |
|
[_modePoints setEnabled: YES]; |
223 |
|
[_modeFilsDeFer setEnabled: YES]; |
224 |
|
[_modePolygon setEnabled: NO]; |
225 |
|
|
226 |
|
[_cameraView changeModeAff: GL_FILL]; |
227 |
|
} |
228 |
|
|
229 |
|
} |
230 |
|
|
231 |
@end |
@end |