1 namespace gfx3D::meshes;
3 /****************************************************************************
6 Copyright (c) 2001 Jerome Jacovella-St-Louis
9 skybox.ec - SkyBox 3D Model
10 ****************************************************************************/
13 static char * faceNames[] = { "up", "fr", "dn", "bk", "rt", "lf" };
15 public class SkyBox : Object
18 bool Create(DisplaySystem displaySystem)
23 InitializeMesh(displaySystem);
25 if(mesh.Allocate({vertices = true, texCoords1 = true }, 24, displaySystem))
28 Vector3Df vertices[24] =
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 },
37 { -(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 },
46 { -(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 },
55 { -(float)size.x/2, (float)size.y/2, (float)size.z/2 }
57 Pointf texCoords[24] =
59 { 1, 0 }, { 0, 0 }, { 0, 1 }, { 1, 1 },
60 { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 },
61 { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 },
62 { 1, 0 }, { 0, 0 }, { 0, 1 }, { 1, 1 },
63 { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 },
64 { 0, 1 }, { 1, 1 }, { 1, 0 }, { 0, 0 }
67 uint16 indices[6][4] =
69 // up, front, down, back, right, left
88 CopyBytes(mesh.vertices, vertices, sizeof(vertices));
89 CopyBytes(mesh.texCoords, texCoords, sizeof(texCoords));
95 sprintf(name, "SKYBOX %s", faceNames[c]);
96 material = displaySystem.AddNamedMaterial(name);
100 sprintf(name, "%s/%s.%s", folder ? folder : ":skycube", faceNames[c], extension ? extension : "pcx");
101 material.flags = { noFog = true };
102 material.opacity = 1;
103 material.emissive.r = material.emissive.g = material.emissive.b = 1;
104 material.baseMap = Bitmap { };
105 material.baseMap.LoadMipMaps(name, null, displaySystem);
106 displaySystem.AddTexture(name, material.baseMap);
108 group = mesh.AddPrimitiveGroup(triFan, 4);
109 //group = mesh.AddPrimitiveGroup(quads, sizeof(indices[c]) / sizeof(uint16));
112 group.material = material;
113 CopyBytes(group.indices, indices[c], sizeof(indices[c]));
114 mesh.UnlockPrimitiveGroup(group);
120 SetMinMaxRadius(true);
125 void Render(Camera camera, Display display)
129 display.depthTest = false;
130 display.depthWrite = false;
132 flags.viewSpace = true;
133 flags.transform = true;
136 // TODO: Not working...
137 // transform.orientation.Inverse(camera.cOrientation);
140 iquat.Inverse(camera.cOrientation);
141 transform.orientation = iquat;
145 display.DrawObject(this);
147 display.depthWrite = true;
148 display.depthTest = true;
152 property Vector3Df size { set { size = value; } };
153 property char * folder { set { folder = value; } };
154 property char * extension { set { extension = value; } };
159 size = { 10000,10000,10000 };
165 char * folder, * extension;