-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngine.h
More file actions
120 lines (91 loc) · 4.09 KB
/
Copy pathEngine.h
File metadata and controls
120 lines (91 loc) · 4.09 KB
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
114
115
116
117
118
119
#ifndef _ENGINE_H_
#define _ENGINE_H_
#include <vector>
#include "Timer.h"
class Engine
{
public:
Engine();
~Engine();
std::shared_ptr<GameObject> hero;
std::vector<std::shared_ptr<GameObject>> gameObjects;
std::vector<GLuint> textureIds;
std::weak_ptr<GameObject> highlightedGameObject;
std::weak_ptr<Renderable> highlightedRenderable;
std::string modelPath = "models";
std::string texturePath = "textures";
std::string dragonPath = modelPath + "/stanford/dragon/reconstruction";
std::string bunnyPath = modelPath + "/stanford/bunny/reconstruction";
bool drawWireframes = false;
Vector4 cameraPosition = Vector4(0.0, 2.0, 5.0);
float cameraXRotation = 0.0;
float cameraYRotation = 0.0;
float cameraKeyboardSpeed = 10.0;
float cameraScrollSpeed = 1.0;
float cameraKeyboardRotationSpeed = 2.0;
float cameraScrollRotationSpeed = 0.5;
float heroSpeed = 5.0;
unsigned char keyState[GLFW_KEY_LAST+1] = {0};
unsigned char keyMods[GLFW_KEY_LAST+1] = {0};
static Engine & instance();
Transform cameraTranslation();
Transform cameraRotation();
Transform cameraTransform();
Vector4 cameraForward();
Vector4 cameraRight();
void userTimerUpdate(double timeNow, double deltaTime);
// UI init and launch
void createWindow(int & argc, char ** argv);
void createWindow();
void start();
void repaintViewport();
// Returns index of texture into texture array
unsigned int loadTexture(const std::string & texturePath);
GLuint textureIdAtIndex(unsigned int index) { return textureIds[index]; }
// Lights
void addLight(float x, float y, float z,
float r, float g, float b);
// Game Objects
void addGameObject(const std::shared_ptr<GameObject> & obj);
// Callbacks
void registerCallbacks();
void keyCallback(GLFWwindow * window, int key, int scancode, int action, int mods);
void cursorPositionCallback(GLFWwindow * window, double xpos, double ypos);
void mouseButtonCallback(GLFWwindow * window, int button, int action, int mods);
void scrollCallback(GLFWwindow * window, double xoffset, double yoffset);
void framebufferSizeCallback(GLFWwindow * window, int width, int height);
// Static GLFW callbacks - delegate to instance callbacks
static void sKeyCallback(GLFWwindow * window, int key, int scancode, int action, int mods);
static void sCursorPositionCallback(GLFWwindow * window, double xpos, double ypos);
static void sMouseButtonCallback(GLFWwindow * window, int button, int action, int mods);
static void sScrollCallback(GLFWwindow * window, double xoffset, double yoffset);
static void sFramebufferSizeCallback(GLFWwindow * window, int width, int height);
protected:
void setViewport(int width, int height);
void drawGameObjects(const Matrix4x4 & projection, const Matrix4x4 & view);
void drawRenderable(const Matrix4x4 & projection, const Matrix4x4 & view,
std::shared_ptr<GameObject> & obj,
std::shared_ptr<Renderable> & renderable);
void drawScene();
void drawUserInterface();
void drawEngineWindow();
Timer gameTimer;
float gameTime = 0.0f;
GLFWwindow * window = nullptr;
int fbWidth, fbHeight;
float fbAspectRatio = 1.0f;
int mouse_last_x = -1;
int mouse_last_y = -1;
struct LightPosition { float x, y, z; };
struct LightColor { float r, g, b; };
std::vector<LightPosition> lightPositions;
std::vector<LightColor> lightColors;
// Framebuffers
GLuint mainCameraFBO = 0;
GLuint mainCameraColorTexture = 0;
GLuint mainCameraDepthTexture = 0;
GLuint shadowMapFBO = 0;
GLuint shadowMapDepthTexture = 0;
std::shared_ptr<GameObject> shadowMapCamera;
};
#endif