Ult3D
Implementation of "Ultimate 3D Game Engine Design & Architecture" by Allan Sherrod
Loading...
Searching...
No Matches
BoxShape.h
Go to the documentation of this file.
1#ifndef ULT_BOX_SHAPE_H_INCLUDED
2#define ULT_BOX_SHAPE_H_INCLUDED
3
4#include "../Math/Plane.h"
5#include "../Math/Vector3D.h"
6#include "../ModelData.h"
7
8#define ULT_UNIT_BOX_VERTEX_TOTAL 24
9#define ULT_UNIT_BOX_INDEX_TOTAL 36
10#define ULT_UNIT_BOX_STRIDE sizeof(Ult::stUnitBoxVertex)
11
12namespace Ult
13{
14
20{
21 float x, y, z;
22 float tu1, tv1;
23 float nx, ny, nz;
24};
25
31static inline bool CreateCubeMesh(
32 const float size,
33 ModelData* model,
34 std::vector<Plane>* planes
35)
36{
37 if (!model) { return false; }
38
39 stUnitBoxVertex UnitBoxData[ULT_UNIT_BOX_VERTEX_TOTAL] = {
40 {-1*size, -1*size, -1*size, 1,0, 0,0,1 },
41 {+1*size, -1*size, -1*size, 0,0, 0,0,1 },
42 {+1*size, +1*size, -1*size, 0,1, 0,0,1 },
43 {-1*size, +1*size, -1*size, 1,1, 0,0,1 },
44
45 {+1*size, -1*size, +1*size, 1,0, 0,0,-1 },
46 {-1*size, -1*size, +1*size, 0,0, 0,0,-1 },
47 {-1*size, +1*size, +1*size, 0,1, 0,0,-1 },
48 {+1*size, +1*size, +1*size, 1,1, 0,0,-1 },
49
50 {-1*size, -1*size, -1*size, 0,0, 1,0,0 },
51 {-1*size, +1*size, -1*size, 0,1, 1,0,0 },
52 {-1*size, +1*size, +1*size, 1,1, 1,0,0 },
53 {-1*size, -1*size, +1*size, 1,0, 1,0,0 },
54
55 {+1*size, -1*size, +1*size, 0,0, -1,0,0 },
56 {+1*size, +1*size, +1*size, 0,1, -1,0,0 },
57 {+1*size, +1*size, -1*size, 1,1, -1,0,0 },
58 {+1*size, -1*size, -1*size, 1,0, -1,0,0 },
59
60 {-1*size, +1*size, +1*size, 0,0, 0,-1,0 },
61 {-1*size, +1*size, -1*size, 0,1, 0,-1,0 },
62 {+1*size, +1*size, -1*size, 1,1, 0,-1,0 },
63 {+1*size, +1*size, +1*size, 1,0, 0,-1,0 },
64
65 {+1*size, -1*size, +1*size, 0,0, 0,1,0 },
66 {+1*size, -1*size, -1*size, 0,1, 0,1,0 },
67 {-1*size, -1*size, -1*size, 1,1, 0,1,0 },
68 {-1*size, -1*size, +1*size, 1,0, 0,1,0 }
69 };
70
71 if (planes) {
72 Plane plane;
73 planes->push_back(Plane(0,0,1,size)); // back
74 planes->push_back(Plane(0,0,-1,size)); // front
75 planes->push_back(Plane(1,0,0,size)); // left
76 planes->push_back(Plane(-1,0,0,size)); // right
77 planes->push_back(Plane(0,-1,0,size)); // top
78 planes->push_back(Plane(0,1,0,size)); // bottom
79 }
80
81 unsigned int UnitBoxIndices[ULT_UNIT_BOX_INDEX_TOTAL] = {
82 0,1,2, 2,3,0,
83 4,5,6, 6,7,4,
84 8,9,10, 10,11,8,
85 12,13,14, 14,15,12,
86 16,17,18, 18,19,16,
87 20,21,22, 22,23,20
88 };
89
90 model->Clear();
94
95 if (!model->SetVertices(
99 (char*)UnitBoxData)) {
100 return false;
101 }
102 if (!model->SetIndices(ULT_UNIT_BOX_INDEX_TOTAL, UnitBoxIndices)) {
103 return false;
104 }
105 return true;
106}
107
112static inline bool CreateCubeMesh(const float size, ModelData* model)
113{
114 return CreateCubeMesh(size, model, nullptr);
115}
116
121static inline bool CreateUnitCubeMesh(ModelData* model)
122{
123 return CreateCubeMesh(1, model, nullptr);
124}
125
126} // namespace Ult
127
128#endif // ULT_BOX_SHAPE_H_INCLUDED
129
#define ULT_UNIT_BOX_STRIDE
Definition BoxShape.h:10
#define ULT_UNIT_BOX_VERTEX_TOTAL
Definition BoxShape.h:8
#define ULT_UNIT_BOX_INDEX_TOTAL
Definition BoxShape.h:9
Definition ModelData.h:26
void Clear()
Definition ModelData.cpp:21
bool SetIndices(int totalIndices, unsigned int *indices)
Definition ModelData.cpp:36
bool AddDescriptorElement(ElementType type)
Definition ModelData.h:49
bool SetVertices(PrimitiveType type, int totalVertices, int stride, char *vertices)
Definition ModelData.cpp:53
Definition Plane.h:27
@ ULT_TRI_LIST
Definition PrimitiveType.h:12
@ ULT_VERTEX_3F
Definition ElementType.h:13
@ ULT_TEX1_2F
Definition ElementType.h:16
@ ULT_NORMAL_3F
Definition ElementType.h:14
Definition Archive.h:13
Definition BoxShape.h:20
float nx
Definition BoxShape.h:23
float tu1
Definition BoxShape.h:22
float x
Definition BoxShape.h:21
float ny
Definition BoxShape.h:23
float tv1
Definition BoxShape.h:22
float y
Definition BoxShape.h:21
float z
Definition BoxShape.h:21
float nz
Definition BoxShape.h:23