3 class MyApp : GuiApplication
6 // driver = "Direct3D";
12 position = Vector3D { 0, 0, -200 },
13 orientation = Euler { 0, 0, 0 },
21 orientation = Euler { pitch = 10, yaw = 30 };
28 orientation = Euler { pitch = 20, yaw = -30 };
31 class FunkaColorCube : Object
34 bool Create(DisplaySystem displaySystem)
39 InitializeMesh(displaySystem);
43 if(mesh.Allocate({ vertices = true, texCoords1 = true, colors = true }, 24, displaySystem))
45 Vector3Df vertices[24] =
47 { -(float)size.x/2,-(float)size.y/2,-(float)size.z/2 },
48 { (float)size.x/2,-(float)size.y/2,-(float)size.z/2 },
49 { (float)size.x/2, (float)size.y/2,-(float)size.z/2 },
50 { -(float)size.x/2, (float)size.y/2,-(float)size.z/2 },
51 { -(float)size.x/2,-(float)size.y/2, (float)size.z/2 },
52 { (float)size.x/2,-(float)size.y/2, (float)size.z/2 },
53 { (float)size.x/2, (float)size.y/2, (float)size.z/2 },
54 { -(float)size.x/2, (float)size.y/2, (float)size.z/2 },
56 { -(float)size.x/2,-(float)size.y/2,-(float)size.z/2 },
57 { (float)size.x/2,-(float)size.y/2,-(float)size.z/2 },
58 { (float)size.x/2, (float)size.y/2,-(float)size.z/2 },
59 { -(float)size.x/2, (float)size.y/2,-(float)size.z/2 },
60 { -(float)size.x/2,-(float)size.y/2, (float)size.z/2 },
61 { (float)size.x/2,-(float)size.y/2, (float)size.z/2 },
62 { (float)size.x/2, (float)size.y/2, (float)size.z/2 },
63 { -(float)size.x/2, (float)size.y/2, (float)size.z/2 },
65 { -(float)size.x/2,-(float)size.y/2,-(float)size.z/2 },
66 { (float)size.x/2,-(float)size.y/2,-(float)size.z/2 },
67 { (float)size.x/2, (float)size.y/2,-(float)size.z/2 },
68 { -(float)size.x/2, (float)size.y/2,-(float)size.z/2 },
69 { -(float)size.x/2,-(float)size.y/2, (float)size.z/2 },
70 { (float)size.x/2,-(float)size.y/2, (float)size.z/2 },
71 { (float)size.x/2, (float)size.y/2, (float)size.z/2 },
72 { -(float)size.x/2, (float)size.y/2, (float)size.z/2 }
74 Pointf texCoords[24] =
76 { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 },
77 { 1, 0 }, { 0, 0 }, { 0, 1 }, { 1, 1 },
78 { 1, 0 }, { 0, 0 }, { 0, 1 }, { 1, 1 },
79 { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 },
80 { 0, 1 }, { 1, 1 }, { 1, 1 }, { 0, 1 },
81 { 0, 0 }, { 1, 0 }, { 1, 0 }, { 0, 0 }
83 ColorRGBAf colors[24] =
85 red, magenta, teal, white,
86 blue, cyan, black, pink,
87 orange, powderBlue, lightGreen, violet,
88 green, gray, lightBlue, blanchedAlmond,
89 purple, forestGreen, slateGray, lavender,
90 yellow, lime, salmon, tomato
92 uint16 indices[6][4] =
94 // up, front, down, back, right, left
105 CopyBytes(mesh.vertices, vertices, sizeof(vertices));
106 CopyBytes(mesh.texCoords, texCoords, sizeof(texCoords));
107 CopyBytes(mesh.colors, colors, sizeof(colors));
111 PrimitiveGroup group;
112 group = mesh.AddPrimitiveGroup(quads, 4);
115 CopyBytes(group.indices, indices[c], sizeof(indices[c]));
116 mesh.UnlockPrimitiveGroup(group);
119 mesh.ComputeNormals();
123 SetMinMaxRadius(true);
129 property Vector3Df size { set { size = value; } };
140 class Test3D : Window
144 borderStyle = sizable;
150 //BitmapResource texture { "http://www.ecere.com/images/knot.png", window = this };
151 FunkaColorCube cube { };
152 Material cubeMat { opacity = 1.0f, diffuse = white, ambient = white, flags = { doubleSided = true, translucent = true } };
154 bool OnLoadGraphics()
156 cube.Create(displaySystem);
157 //cubeMat.baseMap = texture.bitmap;
158 cube.mesh.ApplyMaterial(cubeMat);
159 cube.mesh.ApplyTranslucency(cube);
160 cube.transform.scaling = { 100, 100, 100 };
161 cube.transform.position = { 0, 0, 0 };
162 cube.transform.orientation = Euler { 50, 50 };
163 cube.UpdateTransform();
167 void OnResize(int w, int h)
169 camera.Setup(w, h, null);
172 void OnRedraw(Surface surface)
174 surface.Clear(depthBuffer);
176 display.SetLight(0, light);
177 display.SetLight(1, light2);
178 display.fogDensity = 0;
179 display.SetCamera(surface, camera);
180 display.DrawObject(cube);
181 display.SetCamera(surface, null);