1 namespace gfx3D::meshes;
3 /****************************************************************************
6 Copyright (c) 2001 Jerome Jacovella-St-Louis
9 cube.ec - Translucent Cube 3D Model
10 ****************************************************************************/
13 public class Cube : Object
16 bool Create(DisplaySystem displaySystem)
21 InitializeMesh(displaySystem);
25 if(mesh.Allocate({ vertices = true, texCoords1 = true }, 24, displaySystem))
27 Vector3Df vertices[24] =
29 { -(float)size.x/2,-(float)size.y/2,-(float)size.z/2 },
30 { (float)size.x/2,-(float)size.y/2,-(float)size.z/2 },
31 { (float)size.x/2, (float)size.y/2,-(float)size.z/2 },
32 { -(float)size.x/2, (float)size.y/2,-(float)size.z/2 },
33 { -(float)size.x/2,-(float)size.y/2, (float)size.z/2 },
34 { (float)size.x/2,-(float)size.y/2, (float)size.z/2 },
35 { (float)size.x/2, (float)size.y/2, (float)size.z/2 },
36 { -(float)size.x/2, (float)size.y/2, (float)size.z/2 },
38 { -(float)size.x/2,-(float)size.y/2,-(float)size.z/2 },
39 { (float)size.x/2,-(float)size.y/2,-(float)size.z/2 },
40 { (float)size.x/2, (float)size.y/2,-(float)size.z/2 },
41 { -(float)size.x/2, (float)size.y/2,-(float)size.z/2 },
42 { -(float)size.x/2,-(float)size.y/2, (float)size.z/2 },
43 { (float)size.x/2,-(float)size.y/2, (float)size.z/2 },
44 { (float)size.x/2, (float)size.y/2, (float)size.z/2 },
45 { -(float)size.x/2, (float)size.y/2, (float)size.z/2 },
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 Pointf texCoords[24] =
58 { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 },
59 { 1, 0 }, { 0, 0 }, { 0, 1 }, { 1, 1 },
60 { 1, 0 }, { 0, 0 }, { 0, 1 }, { 1, 1 },
61 { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 },
62 { 0, 1 }, { 1, 1 }, { 1, 1 }, { 0, 1 },
63 { 0, 0 }, { 1, 0 }, { 1, 0 }, { 0, 0 }
65 uint16 indices[6][4] =
67 // up, front, down, back, right, left
78 CopyBytes(mesh.vertices, vertices, sizeof(vertices));
79 CopyBytes(mesh.texCoords, texCoords, sizeof(texCoords));
87 sprintf(name, "tex%d.bmp", c+1);
88 if(c == 3) strcpy(name, "glass.bmp");
90 sprintf(name, "Cube Face %d", c+1);
91 material = displaySystem.AddNamedMaterial(name);
94 material.flags = { noFog = true, doubleSided = true, translucent = true };
95 material.opacity = 0.5f;
97 material.diffuse.r = material.diffuse.g = material.diffuse.b = 1;
98 material.ambient = material.diffuse;
101 material.baseMap = display.GetTexture(, name);
102 if(!material.baseMap)
104 material.baseMap = Bitmap { };
105 material.baseMap.LoadMipMaps(name, null, displaySystem);
106 displaySystem.AddTexture(name, material.baseMap);
109 group = mesh.AddPrimitiveGroup(quads, 4);
110 // group = mesh.AddPrimitiveGroup(triFan, 4);
113 CopyBytes(group.indices, indices[c], sizeof(indices[c]));
114 mesh.UnlockPrimitiveGroup(group);
115 group.material = material;
118 mesh.ComputeNormals();
122 SetMinMaxRadius(true);
128 property Vector3Df size { set { size = value; } };