7 class CubeApp : GuiApplication
22 position = { 0, 0, -200 },
23 orientation = Euler { 0, 0, 0 },
30 orientation = Euler { pitch = 10, yaw = 30 };
36 orientation = Euler { pitch = 20, yaw = -30 };
45 clientSize = { 400, 400 };
56 static Time lastTime = 0;
57 Time time = GetTime(), diffTime = lastTime ? (time - lastTime) : 0;
58 if(spin.yaw || spin.pitch)
60 int signYaw = 1, signPitch = 1;
61 Radians yaw = spin.yaw, pitch = spin.pitch;
62 Quaternion orientation = cube.transform.orientation;
63 Euler tSpin { yaw * (double)diffTime, pitch * (double)diffTime, 0 };
64 Quaternion thisSpin = tSpin, temp;
66 if(yaw < 0) { yaw = -yaw; signYaw = -1; }
67 if(pitch < 0) { pitch = -pitch; signPitch = -1; }
68 yaw -= (double)diffTime / 3 * yaw;
69 pitch -= (double)diffTime / 3 * pitch;
70 if(yaw < 0.0001) yaw = 0;
71 if(pitch < 0.0001) pitch = 0;
73 spin.yaw = yaw * signYaw;
74 spin.pitch = pitch * signPitch;
76 temp.Multiply(orientation, thisSpin);
77 orientation.Normalize(temp);
79 cube.transform.orientation = orientation;
80 cube.UpdateTransform();
87 void OnUnloadGraphics()
91 for(group = cube.mesh.groups.first, c = 0; c<6; c++, group = group.next)
94 delete group.material;
100 char * hiragana[6] = { "あ", "い", "う", "え", "お", "ん" };
103 PrimitiveGroup group;
105 DisplaySystem lfbSystem { };
107 cube.Create(displaySystem);
108 lfbSystem.Create("LFB", null, false);
109 //font = lfbSystem.LoadFont("Arial Unicode MS", 180, 0);
110 //font = lfbSystem.LoadFont("MingLiu", 150, 0);
111 font = lfbSystem.LoadFont("FreeSans.ttf", 175, 0);
113 for(group = cube.mesh.groups.first, c = 0; c<6; c++, group = group.next)
117 textures[c] = Bitmap { };
118 textures[c].Allocate(null, 256, 256, 0, pixelFormat888, false);
120 surface = textures[c].GetSurface(0,0, null);
121 surface.TextFont(font);
122 surface.SetBackground(ColorAlpha { 255/*64*/, beige });
123 surface.Clear(colorBuffer);
124 surface.SetForeground(ColorAlpha { 255/*128*/, ColorHSV { 60 * c, 100, 50 }});
125 surface.TextExtent(hiragana[c], strlen(hiragana[c]), &tw, &th);
126 //surface.WriteText((256 - tw) / 2, (256 - th) / 2 /*+ 20*/, hiragana[c], strlen(hiragana[c]));
127 surface.WriteText(12,-45, hiragana[c], strlen(hiragana[c]));
128 surface.SetBackground({ 255 /*64*/, ColorHSV { (90 + 60 * c) % 360, 75, 50 }} );
129 surface.Area(5,5, 250,20);
130 surface.Area(5,5, 20,250);
131 surface.Area(235,5, 250,250);
132 surface.Area(5, 235, 250,250);
134 textures[c].MakeDD(displaySystem);
136 group.material = { opacity = 1, diffuse = white, ambient = white, flags = { doubleSided = true, translucent = true }, baseMap = textures[c] };
139 lfbSystem.UnloadFont(font);
142 cube.transform.scaling = { 100, 100, 100 };
143 cube.transform.position = { 0, 0, 0 };
144 cube.transform.orientation = Euler { 50, 50 };
145 cube.UpdateTransform();
149 void OnResize(int w, int h)
151 camera.Setup(w, h, null);
154 void OnRedraw(Surface surface)
156 surface.Clear(colorAndDepth);
158 display.SetLight(0, light);
159 display.SetLight(1, light2);
160 display.SetCamera(surface, camera);
161 display.fogDensity = 0;
162 display.DrawObject(cube);
163 display.SetCamera(surface, null);
170 bool OnLeftButtonDown(int x, int y, Modifiers mods)
172 clickTime = GetTime();
174 startClick = { x, y };
179 bool OnLeftButtonUp(int x, int y, Modifiers mods)
189 bool OnMouseMove(int x, int y, Modifiers mods)
193 Time time = GetTime(), diffTime = Max(time - clickTime, 0.01);
194 spin.yaw += Degrees { (x - startClick.x) / (25.0 * (double)diffTime) };
195 spin.pitch += Degrees { (startClick.y - y) / (25.0 * (double)diffTime) };
196 startClick = { x, y };
202 bool OnKeyHit(Key key, unichar ch)
204 if(key == wheelDown || key == wheelUp)
209 else if(key == wheelUp)
211 Move(position.x + size.w / 2 - w / 2, position.y + size.h / 2 - w / 2, w, w);
217 bool OnKeyDown(Key key, unichar ch)
219 if(key == escape) Destroy(0);