-
Notifications
You must be signed in to change notification settings - Fork 1
/
Primitive.h
105 lines (91 loc) · 1.78 KB
/
Primitive.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef PRIMITIVE_H
#define PRIMITIVE_H
#include "glmath.h"
#include "Color.h"
enum PrimitiveTypes
{
Primitive_Point,
Primitive_Line,
Primitive_Plane,
Primitive_Cube,
Primitive_Sphere,
Primitive_Cylinder,
Primitive_Cone
};
class Primitive
{
public:
Primitive();
virtual void Render() const;
virtual void InnerRender() const;
void SetPos(float x, float y, float z);
void SetRotation(float angle, const vec3 &u);
void Scale(float x, float y, float z);
void DrawObj(PrimitiveTypes type);
PrimitiveTypes GetType() const;
public:
Color color;
mat4x4 transform;
bool axis, wire;
private:
float x_rotation[3] = { 1, 0, 0 };
float y_rotation[3] = { 0, 1, 0 };
float z_rotation[3] = { 0, 0, 1 };
float normal[3] = { 0, 0, 1 };
float center[3] = { 0, 0, 0 };
protected:
PrimitiveTypes type;
};
// ============================================
class Cube : public Primitive
{
public:
Cube();
Cube(float sizeX, float sizeY, float sizeZ);
void InnerRender() const;
public:
vec3 size;
};
// ============================================
class Sphere : public Primitive
{
public:
Sphere();
Sphere(float radius);
public:
float radius;
};
// ============================================
class Cylinder : public Primitive
{
public:
Cylinder();
Cylinder(float radius, float height);
void InnerRender() const;
public:
float radius;
float height;
};
// ============================================
class Line_ : public Primitive
{
public:
Line_();
Line_(float x, float y, float z);
void InnerRender() const;
public:
vec3 origin;
vec3 destination;
};
// ============================================
class Plane_ : public Primitive
{
public:
Plane_();
Plane_(float x, float y, float z, float d);
void InnerRender() const;
public:
vec3 normal;
float constant;
};
#endif PRIMITIVE_H