26 |
|
|
27 |
#include <Foundation/NSTimer.h> |
#include <Foundation/NSTimer.h> |
28 |
#include <AppKit/NSOpenGL.h> |
#include <AppKit/NSOpenGL.h> |
29 |
|
#include <AppKit/NSEvent.h> |
30 |
|
//#include <Foundation/NSPoint.h> |
31 |
|
|
32 |
#include "ModelView.h" |
#include "ModelView.h" |
33 |
#include "Common/Camera.h" |
#include "Common/Camera.h" |
37 |
|
|
38 |
@implementation ModelView |
@implementation ModelView |
39 |
|
|
40 |
|
NSPoint pointOld; |
41 |
|
NSPoint pointNew; |
42 |
|
float translateX; |
43 |
|
float translateY; |
44 |
|
float translateZ; |
45 |
|
|
46 |
|
|
47 |
- (id) initWithFrame: (NSRect)frameRect |
- (id) initWithFrame: (NSRect)frameRect |
48 |
pixelFormat: (NSOpenGLPixelFormat *)format |
pixelFormat: (NSOpenGLPixelFormat *)format |
49 |
{ |
{ |
117 |
|
|
118 |
glLoadIdentity(); |
glLoadIdentity(); |
119 |
glTranslatef(0.0,0.0,-100.0); |
glTranslatef(0.0,0.0,-100.0); |
120 |
|
glTranslatef(translateX,0.0,0.0); |
121 |
|
glTranslatef(0.0,translateY,0.0); |
122 |
|
glTranslatef(0.0,0.0,translateZ); |
123 |
|
|
124 |
|
|
125 |
glRotatef(-90,1.0,0.0,0.0); |
glRotatef(-90,1.0,0.0,0.0); |
126 |
|
glRotatef(pointNew.x,0.0,0.0,1.0); |
127 |
|
glRotatef(pointNew.y,1.0,0.0,0.0); |
128 |
|
|
129 |
[_model displayWithCamera: _cam]; |
[_model displayWithCamera: _cam]; |
130 |
|
|
132 |
[[self openGLContext] flushBuffer]; |
[[self openGLContext] flushBuffer]; |
133 |
} |
} |
134 |
|
|
135 |
|
- (void)mouseDown: (NSEvent *)theEvent |
136 |
|
{ |
137 |
|
pointOld = [NSEvent mouseLocation]; |
138 |
|
}; |
139 |
|
|
140 |
|
- (void)mouseDragged: (NSEvent *)theEvent |
141 |
|
{ |
142 |
|
NSPoint tmp = [NSEvent mouseLocation]; |
143 |
|
pointNew.x += (tmp.x - pointOld.x)/80.0; |
144 |
|
pointNew.y += (tmp.y - pointOld.y)/80.0; |
145 |
|
}; |
146 |
|
|
147 |
|
- (void) scrollWheel: (NSEvent *) theEvent |
148 |
|
{ |
149 |
|
translateZ = translateZ + ([theEvent deltaY]*10.0); |
150 |
|
|
151 |
|
printf("X %f \n\n", [theEvent deltaX]); |
152 |
|
printf("Y %f \n\n", [theEvent deltaY]); |
153 |
|
printf("Z %f \n\n", [theEvent deltaZ]); |
154 |
|
} |
155 |
|
|
156 |
|
- (BOOL)performKeyEquivalent: (NSEvent *) theEvent |
157 |
|
{ |
158 |
|
printf("coucou\n"); |
159 |
|
printf("event code = %d\n", [theEvent keyCode]); |
160 |
|
// printf("event char = %d\n", [theEvent characters]); |
161 |
|
|
162 |
|
printf("event code wnated = %d\n", NSUpArrowFunctionKey); |
163 |
|
|
164 |
|
switch([theEvent keyCode]) |
165 |
|
{ |
166 |
|
case 98: |
167 |
|
translateY+=5; |
168 |
|
break; |
169 |
|
case 100: |
170 |
|
translateX-=5; |
171 |
|
break; |
172 |
|
case 102: |
173 |
|
translateX+=5; |
174 |
|
break; |
175 |
|
case 104: |
176 |
|
translateY-=5; |
177 |
|
break; |
178 |
|
default: |
179 |
|
/* do nothing*/ |
180 |
|
break; |
181 |
|
|
182 |
|
} |
183 |
|
return YES; |
184 |
|
|
185 |
|
} |
186 |
|
|
187 |
|
|
188 |
|
// - (void)otherMouseDown: (NSEvent *)theEvent |
189 |
|
// { |
190 |
|
// pointOld = [NSEvent mouseLocation]; |
191 |
|
// }; |
192 |
|
|
193 |
|
// - (void)otherMouseUp: (NSEvent *)theEvent |
194 |
|
// { |
195 |
|
// NSPoint tmp = [NSEvent mouseLocation]; |
196 |
|
|
197 |
|
// translate = translateX + (tmp.x - pointOld.x)/1000.0; |
198 |
|
// }; |
199 |
|
|
200 |
@end |
@end |