3 ModelViewer modelViewer { };
5 class eModelApp : GuiApplication
8 //driver = "Direct3D8";
12 class ModelViewer : Window
14 text = "Transparent Cube Demo";
16 borderStyle = sizable;
20 anchor = { left = 0, top = 0, right = 0, bottom = 0 };
25 position = Vector3D { 0, 0, -250 },
26 orientation = Euler { 120, 30, 0 },
30 Cube model { size = { 100, 100, 100 } };
32 bool moving, lightMoving;
36 Euler startOrientation;
41 // orientation = Euler { pitch = 50, yaw = 45 };
42 orientation = Euler { pitch = 10, yaw = 30 };
45 void OnUnloadGraphics()
47 displaySystem.ClearMaterials();
48 displaySystem.ClearTextures();
49 displaySystem.ClearMeshes();
52 void OnResize(int w, int h)
54 camera.Setup(w, h, null);
58 bool OnLeftButtonDown(int x, int y, Modifiers mods)
60 if(!moving && !lightMoving)
64 startOrientation = camera.orientation;
71 bool OnLeftButtonUp(int x, int y, Modifiers mods)
81 bool OnRightButtonDown(int x, int y, Modifiers mods)
83 if(!moving && !lightMoving)
87 startOrientation = light.orientation;
94 bool OnRightButtonUp(int x, int y, Modifiers mods)
104 bool OnMouseMove(int x, int y, Modifiers mods)
110 startOrientation.yaw - (x - startPosition.x),
111 startOrientation.pitch + (y - startPosition.y),
112 startOrientation.roll
115 camera.orientation = euler;
121 light.orientation = Euler
123 startOrientation.yaw - (x - startPosition.x),
124 startOrientation.pitch + (y - startPosition.y),
125 startOrientation.roll
133 bool OnKeyDown(Key key, unichar ch)
137 case escape: Destroy(0); return false;
142 bool OnKeyHit(Key key, unichar ch)
144 switch((SmartKey) key)
146 case wheelDown: case minus: camera.position.z *= 1.1111111f; Update(null); break;
147 case wheelUp: case plus: camera.position.z *= 0.9f; Update(null); break;
152 bool OnLoadGraphics()
154 if(model.Create(displaySystem))
161 PrimitiveGroup group;
165 sprintf(name, "Cube Face %d", c+1);
166 material = displaySystem.GetMaterial(name);
169 material.flags = { noFog = true, doubleSided = true, translucent = true };
170 material.opacity = 0.5f;
171 material.diffuse.r = material.diffuse.g = material.diffuse.b = 1;
172 material.ambient = material.diffuse;
173 material.baseMap = displaySystem.GetTexture(name);
174 if(!material.baseMap)
176 material.baseMap = Bitmap { };
178 sprintf(name, "tex%d.bmp", c+1);
179 if(c == 3) strcpy(name, "glass.bmp");
181 material.baseMap.LoadMipMaps(name, null, displaySystem);
182 displaySystem.AddTexture(name, material.baseMap);
186 model.mesh.ApplyTranslucency(model);
187 camera.target = model;
195 void OnRedraw(Surface surface)
197 display.fogColor = blue;
198 display.fogDensity = 0.000001f;
200 surface.Clear(depthBuffer);
204 display.antiAlias = true;
205 display.SetLight(0, light);
207 display.SetCamera(surface, camera);
209 display.ambient = ColorRGB { 0.2f, 0.2f, 0.2f };
211 display.DrawObject(model);
213 display.SetCamera(surface, null);