-
Notifications
You must be signed in to change notification settings - Fork 0
/
ggameobject.h
113 lines (98 loc) · 3.01 KB
/
ggameobject.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
106
107
108
109
110
111
112
113
#ifndef GGAMEOBJECT_H
#define GGAMEOBJECT_H
#include "gmath.h"
#include "gmodel.h"
#include "gbuffer.h"
#include "gshader.h"
enum GLightType
{
kLTDirection,
kLTPoint,
};
struct GLightInfo
{
GColor lightColor;
float lightIntensity;
GLightType lightType;
GMath::vec3 lightPosOrDir;
};
class GGraphicLibAPI;
class GGameObject
{
public:
enum GGameObjectType
{
kCamera,
kLight,
kModel,
};
enum GCameraType
{
kOrthographic,
kProjection,
};
GGameObject()=default;
GGameObject(GGameObjectType t,int subType);
// common
void SetT(GMath::vec3f pos);
void SetR(GMath::vec3f rotation);
void SetS(GMath::vec3f scale);
void SetTRS(GMath::vec3f pos,GMath::vec3f rotation,GMath::vec3f scale);
void TRSInvertTRS(const GMath::mat4f*& trs, const GMath::mat4f*& invertTRS);
const GMath::vec3f& position() { return _position; }
const GMath::vec3f& rotation() { return _rotation; }
const GMath::vec3f& scale() { return _scale; }
GGameObjectType mtype;
GMath::vec3f right();
GMath::vec3f up();
GMath::vec3f forward();
// camera
static GGameObject CreateProjCamera(float near, float far, float fov);
static GGameObject* activeCamera;
void SetViewport(int x, int y, int w, int h);
void SetFov(float fov);
GMath::vec2 NDCPosToScreenPos(GMath::vec3 ndc);
float ToWBufferValue(float wValue);
int viewportX;
int viewportY;
int viewportW;
int viewportH;
GCameraType cameraType;
float fov{60};
float near{0.1};
float far{200.0f};
float aspectRatio{1.0f};
GMath::mat4f& LookAt(GMath::vec3f eyePos, GMath::vec3f lookAtPoint, GMath::vec3f up);
void ProjInvertProj(const GMath::mat4f*& tproj,const GMath::mat4f*& tinvertProj);
// light
static GGameObject& CreateLightGObj(GLightType lightType, GColor lColor=GColor::white, float lIntensity=1);
static std::vector<GGameObject> lights;
GLightInfo lightInfo;
// model
static GGameObject CreateModelGObj(GModelType modelType, std::string modelPath="", bool init_texture=true);
typedef std::vector<std::tuple<GRenderBufferType, bool>> BlendConfigT;
void InitShader(GGraphicLibAPI* GLAPI, GShaderType shaderType=GShaderType::kSTDefault, BlendConfigT blendConfig={std::make_tuple(GRenderBufferType::kRBFront,false)});
void SetupDraw(GGraphicLibAPI* GLAPI);
void DrawModel(GGraphicLibAPI* GLAPI);
GShaderType shaderType;
std::vector<std::tuple<GRenderBufferType, bool>> blendConfig;
GGLModel model;
GVertexAttribInfoObject* modelVAO;
GShader* modelShader{nullptr};
bool depthMask{true};
private:
// common
GMath::vec3f _position;
GMath::vec3f _rotation;
GMath::vec3f _scale = {1,1,1};
bool _trs_dirty = true;
GMath::mat4f transform;
GMath::mat4f invertTransform;
// camera
GMath::mat4f projMat;
GMath::mat4f invertProjMat;
bool _proj_dirty = true;
// light
void FillLightData(GGraphicLibAPI* GLAPI);
};
#endif // GGAMEOBJECT_H