1 | #include "SceneEntityConverter.h"
|
---|
2 | #include "SceneEntity.h"
|
---|
3 | #include "Geometry.h"
|
---|
4 | #include "Shape.h"
|
---|
5 | #include "Plane3.h"
|
---|
6 |
|
---|
7 | using namespace std;
|
---|
8 |
|
---|
9 |
|
---|
10 | namespace CHCDemoEngine
|
---|
11 | {
|
---|
12 |
|
---|
13 | SceneEntity *SceneEntityConverter::ConvertBox(const AxisAlignedBox3 &box,
|
---|
14 | Material *mat,
|
---|
15 | Transform3 *trafo)
|
---|
16 | {
|
---|
17 | SceneEntity *ent = new SceneEntity(trafo);
|
---|
18 |
|
---|
19 | vector<Triangle3> triangles;
|
---|
20 |
|
---|
21 | box.Triangulate(triangles);
|
---|
22 |
|
---|
23 | Vector3 *vertices = new Vector3[36];
|
---|
24 | Vector3 *normals = new Vector3[36];
|
---|
25 |
|
---|
26 | for (size_t i = 0; i < triangles.size(); ++ i)
|
---|
27 | {
|
---|
28 | Triangle3 tri = triangles[i];
|
---|
29 |
|
---|
30 | vertices[i * 3 + 0] = tri.mVertices[0];
|
---|
31 | vertices[i * 3 + 1] = tri.mVertices[1];
|
---|
32 | vertices[i * 3 + 2] = tri.mVertices[2];
|
---|
33 |
|
---|
34 | Vector3 normal = tri.GetNormal();
|
---|
35 |
|
---|
36 | normals[i * 3 + 0] = normal;
|
---|
37 | normals[i * 3 + 1] = normal;
|
---|
38 | normals[i * 3 + 2] = normal;
|
---|
39 | }
|
---|
40 |
|
---|
41 | Geometry *geom = new Geometry(vertices, normals, NULL, 36, true, NULL);
|
---|
42 |
|
---|
43 | Shape *shape = new Shape(geom, mat);
|
---|
44 | ent->AddShape(shape);
|
---|
45 |
|
---|
46 | LODLevel lodLevel(0);
|
---|
47 |
|
---|
48 | lodLevel.AddShape(shape);
|
---|
49 | ent->AddLODLevel(lodLevel);
|
---|
50 |
|
---|
51 | return ent;
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | SceneEntity *SceneEntityConverter::ConvertSphere(float radius,
|
---|
56 | float xspans,
|
---|
57 | float yspans,
|
---|
58 | Material *mat,
|
---|
59 | Transform3 *trafo)
|
---|
60 | {
|
---|
61 | // todo
|
---|
62 | return NULL;
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | SceneEntity *SceneEntityConverter::ConvertPlane(const Plane3 &plane,
|
---|
67 | float xsize,
|
---|
68 | float ysize,
|
---|
69 | float xspans,
|
---|
70 | float yspans,
|
---|
71 | Material *mat,
|
---|
72 | Transform3 *trafo)
|
---|
73 | {
|
---|
74 | SceneEntity *ent = new SceneEntity(trafo);
|
---|
75 |
|
---|
76 | vector<Triangle3> triangles;
|
---|
77 |
|
---|
78 | Vector3 x1, x2, x3, x4;
|
---|
79 | float xsize_h = xsize * 0.5f;
|
---|
80 | float ysize_h = xsize * 0.5f;
|
---|
81 |
|
---|
82 | x1 = Vector3(xsize_h, ysize_h, 0);
|
---|
83 | x2 = Vector3(xsize_h, -ysize_h, 0);
|
---|
84 | x3 = Vector3(-xsize_h, -ysize_h, 0);
|
---|
85 | x4 = Vector3(-xsize_h, ysize_h, 0);
|
---|
86 |
|
---|
87 | triangles.push_back(Triangle3(x3, x2, x1));
|
---|
88 | triangles.push_back(Triangle3(x3, x1, x4));
|
---|
89 |
|
---|
90 | Vector3 *vertices = new Vector3[6];
|
---|
91 | Vector3 *normals = new Vector3[6];
|
---|
92 | Texcoord2 *tex = new Texcoord2[6];
|
---|
93 |
|
---|
94 | tex[0].first = 0; tex[0].second = 0;
|
---|
95 | tex[1].first = 50; tex[1].second = 0;
|
---|
96 | tex[2].first = 50; tex[2].second = 50;
|
---|
97 |
|
---|
98 | tex[3].first = 0; tex[3].second = 0;
|
---|
99 | tex[4].first = 50; tex[4].second = 50;
|
---|
100 | tex[5].first = 0; tex[5].second = 50;
|
---|
101 |
|
---|
102 | for (size_t i = 0; i < triangles.size(); ++ i)
|
---|
103 | {
|
---|
104 | Triangle3 tri = triangles[i];
|
---|
105 |
|
---|
106 | vertices[i * 3 + 0] = tri.mVertices[0];
|
---|
107 | vertices[i * 3 + 1] = tri.mVertices[1];
|
---|
108 | vertices[i * 3 + 2] = tri.mVertices[2];
|
---|
109 |
|
---|
110 | Vector3 normal = tri.GetNormal();
|
---|
111 |
|
---|
112 | normals[i * 3 + 0] = normal;
|
---|
113 | normals[i * 3 + 1] = normal;
|
---|
114 | normals[i * 3 + 2] = normal;
|
---|
115 | }
|
---|
116 |
|
---|
117 |
|
---|
118 | Geometry *geom = new Geometry(vertices, normals, tex, 6, true, NULL);
|
---|
119 |
|
---|
120 | Shape *shape = new Shape(geom, mat);
|
---|
121 | ent->AddShape(shape);
|
---|
122 |
|
---|
123 | LODLevel lodLevel(0);
|
---|
124 |
|
---|
125 | lodLevel.AddShape(shape);
|
---|
126 | ent->AddLODLevel(lodLevel);
|
---|
127 |
|
---|
128 | return ent;
|
---|
129 | }
|
---|
130 |
|
---|
131 | } |
---|