Ult3D
Implementation of "Ultimate 3D Game Engine Design & Architecture" by Allan Sherrod
Loading...
Searching...
No Matches
SquareShape.h
Go to the documentation of this file.
1#ifndef ULT_SQUARE_SHAPE_H_INCLUDED
2#define ULT_SQUARE_SHAPE_H_INCLUDED
3
4#include <cstdio>
5
6#include "../ModelData.h"
7
8#define ULT_UNIT_SQUARE_VERTEX_TOTAL 4
9#define ULT_UNIT_SQUARE_INDEX_TOTAL 6
10#define ULT_UNIT_SQUARE_STRIDE sizeof(Ult::stUnitSquareVertex)
11
12namespace Ult
13{
14
16{
17 float x,y,z;
18 float tu1,tv1;
19 float nx,ny,nz;
20};
21
27bool CreateSquareMesh(float width, float height, ModelData* model)
28{
29 if (!model) { return false; }
30
32 { +1*width, -1*height, 0, 1, 0, 0, 0, 1 },
33 { -1*width, -1*height, 0, 0, 0, 0, 0, 1 },
34 { -1*width, +1*height, 0, 0, 1, 0, 0, 1 },
35 { +1*width, +1*height, 0, 1, 1, 0, 0, 1 }
36 };
37 unsigned int UnitSquareIndices[ULT_UNIT_SQUARE_INDEX_TOTAL] = {
38 0, 1, 2,
39 2, 3, 0
40 };
41
42 model->Clear();
46
47 if (!model->SetVertices(
51 (char*)UnitSquareData)) {
52 printf("Failed to set square vertices\n");
53 return false;
54 }
55 if (!model->SetIndices(
57 UnitSquareIndices)) {
58 printf("Failed to set square indices\n");
59 return false;
60 }
61
62 return true;
63}
64
71{
72 return CreateSquareMesh(1, 1, model);
73}
74
75} // namespace Ult
76
77#endif // ULT_SQUARE_SHAPE_H_INCLUDED
78
#define ULT_UNIT_SQUARE_INDEX_TOTAL
Definition SquareShape.h:9
#define ULT_UNIT_SQUARE_STRIDE
Definition SquareShape.h:10
#define ULT_UNIT_SQUARE_VERTEX_TOTAL
Definition SquareShape.h:8
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
@ 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
bool CreateSquareMesh(float width, float height, ModelData *model)
Definition SquareShape.h:27
bool CreateUnitSquareMesh(Ult::ModelData *model)
Definition SquareShape.h:70
Definition Archive.h:13
Definition SquareShape.h:16
float z
Definition SquareShape.h:17
float nz
Definition SquareShape.h:19
float ny
Definition SquareShape.h:19
float y
Definition SquareShape.h:17
float nx
Definition SquareShape.h:19
float x
Definition SquareShape.h:17
float tv1
Definition SquareShape.h:18
float tu1
Definition SquareShape.h:18