7 class ModelView : Window
10 background = lightBlue;
11 anchor = { left = 0, top = 0, right = 0, bottom = 0 };
13 FillModeValue fillMode;
14 bool moving, lightMoving;
15 char fileName[MAX_LOCATION];
19 fovDirection = vertical,
21 position = { 0, 0, -10 },
22 eulerOrientation = Euler { 30, 0, 0 },
26 Object cameraTarget { };
29 Euler startOrientation;
32 orientation = Euler { pitch = 50, yaw = 45 };
33 diffuse = white, specular = white;
34 }; // light.diffuse.r = light.diffuse.g = light.diffuse.b = 1; light.specular.r = light.specular.g = light.specular.b = 1;
39 userData = this, delay = 0.05;
43 model.frame++; //Animate(model.frame + 1);
50 property char * modelFile
54 strcpy(fileName, value);
56 get { return fileName; }
59 void OnUnloadGraphics()
61 model.Free(displaySystem);
62 delete model; // At the moment the reload preserving hierarchy position is not working, causing things to be misplaced in some models
68 DisplaySystem displaySystem = parent.displaySystem;
71 if(_class.count == 1 && parent.displaySystem)
73 displaySystem.ClearMaterials();
74 displaySystem.ClearTextures();
75 displaySystem.ClearMeshes();
79 void OnResize(int w, int h)
81 camera.Setup(w, h, null);
85 bool OnLeftButtonDown(int x, int y, Modifiers mods)
87 if(!moving && !lightMoving)
92 display.StartSelection(x,y, 0,0);
93 display.SetCamera(null, camera);
94 display.CollectHits();
95 display.DrawObject(model);
96 if(display.GetHits(list))
101 display.SetCamera(null, null);
102 display.StopSelection();
108 startOrientation = camera.eulerOrientation;
117 bool OnLeftButtonUp(int x, int y, Modifiers mods)
127 bool OnRightButtonDown(int x, int y, Modifiers mods)
129 if(!moving && !lightMoving)
133 startOrientation = light.orientation;
140 bool OnRightButtonUp(int x, int y, Modifiers mods)
150 bool OnMouseMove(int x, int y, Modifiers mods)
156 startOrientation.yaw - (x - startPosition.x),
157 startOrientation.pitch + (y - startPosition.y),
161 camera.eulerOrientation = euler;
167 light.orientation = Euler
169 startOrientation.yaw - (x - startPosition.x),
170 startOrientation.pitch + (y - startPosition.y),
179 bool OnKeyDown(Key key, unichar ch)
184 fillMode = (fillMode == wireframe) ? solid : wireframe;
190 bool OnKeyHit(Key key, unichar ch)
192 switch((SmartKey) key)
194 case wheelDown: case minus: camera.position.z *= 1.1111111f; Update(null); break;
195 case wheelUp: case plus: camera.position.z *= 0.9f; Update(null); break;
196 case up: camera.position.y += camera.position.z / 20; Update(null); break;
197 case down: camera.position.y -= camera.position.z / 20; Update(null); break;
198 case left: camera.position.x += camera.position.z / 20; Update(null); break;
199 case right: camera.position.x -= camera.position.z / 20; Update(null); break;
201 case pageDown: model.Animate(model.frame + 1); break;
202 case pageUp: model.Animate(model.frame - 1); break;
203 case home: model.Animate(model.startFrame); break;
204 case end: model.Animate(model.endFrame); break;
210 bool OnLoadGraphics()
212 if(model.Load(fileName, null, displaySystem))
214 float r = model.radius;
215 cameraTarget.transform.position =
217 (model.max.x + model.min.x) / 2,
218 (model.max.y + model.min.y) / 2,
219 (model.max.z + model.min.z) / 2
224 camera.position = { 0, 0, -r * 2 };
225 camera.eulerOrientation = Euler { 30, 0, 0 };
226 light.orientation = Euler { pitch = 50, yaw = 45 };
228 if(r * 2 < camera.zMax / 10)
230 while(r * 2 < camera.zMax / 100)
237 while(r * 2 > camera.zMax / 10)
243 camera.target = cameraTarget;
249 void OnRedraw(Surface surface)
251 //display.fogColor = blue;
252 display.fogDensity = 0; //0.000001f;
254 surface.Clear(depthBuffer);
257 display.SetLight(0, light);
258 display.SetCamera(surface, camera);
260 //display.SetLight(0, light);
262 display.fillMode = fillMode;
263 display.DrawObject(model);
264 display.fillMode = solid;
266 display.SetCamera(surface, null);
268 surface.SetForeground(black);
274 light.orientation.Yaw(0);
278 void SetFormat(char * format)