7 class ModelView : Window
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);
58 void OnUnloadGraphics()
60 model.Free(displaySystem);
61 delete model; // At the moment the reload preserving hierarchy position is not working, causing things to be misplaced in some models
67 DisplaySystem displaySystem = parent.displaySystem;
70 if(_class.count == 1 && parent.displaySystem)
72 displaySystem.ClearMaterials();
73 displaySystem.ClearTextures();
74 displaySystem.ClearMeshes();
78 void OnResize(int w, int h)
80 camera.Setup(w, h, null);
84 bool OnLeftButtonDown(int x, int y, Modifiers mods)
86 if(!moving && !lightMoving)
90 startOrientation = camera.eulerOrientation;
97 bool OnLeftButtonUp(int x, int y, Modifiers mods)
107 bool OnRightButtonDown(int x, int y, Modifiers mods)
109 if(!moving && !lightMoving)
113 startOrientation = light.orientation;
120 bool OnRightButtonUp(int x, int y, Modifiers mods)
130 bool OnMouseMove(int x, int y, Modifiers mods)
136 startOrientation.yaw - (x - startPosition.x),
137 startOrientation.pitch + (y - startPosition.y),
141 camera.eulerOrientation = euler;
147 light.orientation = Euler
149 startOrientation.yaw - (x - startPosition.x),
150 startOrientation.pitch + (y - startPosition.y),
159 bool OnKeyDown(Key key, unichar ch)
164 fillMode = (fillMode == wireframe) ? solid : wireframe;
170 bool OnKeyHit(Key key, unichar ch)
172 switch((SmartKey) key)
174 case wheelDown: case minus: camera.position.z *= 1.1111111f; Update(null); break;
175 case wheelUp: case plus: camera.position.z *= 0.9f; Update(null); break;
176 case up: camera.position.y += camera.position.z / 20; Update(null); break;
177 case down: camera.position.y -= camera.position.z / 20; Update(null); break;
178 case left: camera.position.x += camera.position.z / 20; Update(null); break;
179 case right: camera.position.x -= camera.position.z / 20; Update(null); break;
181 case pageDown: model.Animate(model.frame + 1); break;
182 case pageUp: model.Animate(model.frame - 1); break;
183 case home: model.Animate(model.startFrame); break;
184 case end: model.Animate(model.endFrame); break;
190 bool OnLoadGraphics()
192 if(model.Load(fileName, null, displaySystem))
194 float r = model.radius;
195 cameraTarget.transform.position =
197 (model.max.x + model.min.x) / 2,
198 (model.max.y + model.min.y) / 2,
199 (model.max.z + model.min.z) / 2
204 camera.position = { 0, 0, -r * 2 };
205 camera.eulerOrientation = Euler { 30, 0, 0 };
206 if(r * 2 < camera.zMax / 10)
208 while(r * 2 < camera.zMax / 100)
215 while(r * 2 > camera.zMax / 10)
221 camera.target = cameraTarget;
227 void OnRedraw(Surface surface)
229 //display.fogColor = blue;
230 display.fogDensity = 0; //0.000001f;
232 surface.SetBackground(lightBlue);
233 surface.Clear(colorAndDepth);
237 display.SetCamera(surface, camera);
239 display.SetLight(0, light);
241 display.fillMode = fillMode;
242 display.DrawObject(model);
243 display.fillMode = solid;
245 display.SetCamera(surface, null);
247 surface.SetForeground(black);
253 light.orientation.Yaw(0);
257 void SetFormat(char * format)