Vivid
Loading...
Searching...
No Matches
Quad3d.cpp
1#include "Quad3d.h"
2#include "common/maths/Vec.h"
3
4namespace Vivid
5{
6 // TODO: Use multiple vertices to have correct normals for each vertex
7 Quad3d::Quad3d(float size, Maths::Vec3 col)
8 {
9 m_Size = (float)size;
10 const float const_Size = m_Size;
11
12 // TODO: Correct culling
13 Maths::Vec3 pos[8] = {
14 Maths::Vec3(-const_Size, const_Size, -const_Size),
15 Maths::Vec3(const_Size, const_Size, -const_Size),
16 Maths::Vec3(-const_Size, -const_Size, -const_Size),
17 Maths::Vec3(const_Size, -const_Size, -const_Size),
18 Maths::Vec3(-const_Size, const_Size, const_Size),
19 Maths::Vec3(const_Size, const_Size, const_Size),
20 Maths::Vec3(-const_Size, -const_Size, const_Size),
21 Maths::Vec3(const_Size, -const_Size, const_Size),
22 };
23
24 Maths::Vec2 tex[8] = {
25 Maths::Vec2(0.0, 0.0),
26 Maths::Vec2(1.0, 0.0),
27 Maths::Vec2(1.0, 1.0),
28 Maths::Vec2(0.0, 1.0),
29 Maths::Vec2(0.0, 0.0),
30 Maths::Vec2(1.0, 0.0),
31 Maths::Vec2(1.0, 1.0),
32 Maths::Vec2(0.0, 1.0),
33 };
34
35 Maths::Vec3 color[8] = {
36 col,
37 col,
38 col,
39 col,
40 col,
41 col,
42 col,
43 col,
44 };
45
46 Maths::Vec3 normal[8] = {
47 Maths::Vec3(1.0, 1.0, 1.0),
48 Maths::Vec3(1.0, 1.0, 1.0),
49 Maths::Vec3(1.0, 1.0, 1.0),
50 Maths::Vec3(1.0, 1.0, 1.0),
51 Maths::Vec3(1.0, 1.0, 1.0),
52 Maths::Vec3(1.0, 1.0, 1.0),
53 Maths::Vec3(1.0, 1.0, 1.0),
54 Maths::Vec3(1.0, 1.0, 1.0),
55 };
56
57 unsigned int ind[12 * 3] = {
58 0, 1, 2, // Side 0
59 2, 1, 3,
60 4, 0, 6, // Side 1
61 6, 0, 2,
62 7, 5, 6, // Side 2
63 6, 5, 4,
64 3, 1, 7, // Side 3
65 7, 1, 5,
66 4, 5, 0, // Side 4
67 0, 5, 1,
68 3, 7, 2, // Side 5
69 2, 7, 6
70 };
71
72 m_Pos.resize(8, Vertex());
73 m_Ind.resize(12 * 3, int());
74
75 for (int i = 0; i < 8; i++)
76 {
77 m_Pos[i].position = pos[i];
78 m_Pos[i].texcoord = tex[i];
79 m_Pos[i].tangent = color[i];
80 m_Pos[i].normal = normal[i];
81 }
82
83 int i = 0;
84 for (auto x : ind)
85 {
86 m_Ind[i] = x;
87 i++;
88 }
89 }
90}