|
|
|
@ -124,6 +124,7 @@ bool initRenderer(SDL_Handles &handles, v2i vpDims); |
|
|
|
bool addTexture(SDL_Handles &handles, std::string path); |
|
|
|
bool addTexture(SDL_Handles &handles, std::string path); |
|
|
|
bool createScene(std::vector<hex_info>* hexes); |
|
|
|
bool createScene(std::vector<hex_info>* hexes); |
|
|
|
void moveCamera(bool up, bool left, bool down, bool right, bool forward, bool backward); |
|
|
|
void moveCamera(bool up, bool left, bool down, bool right, bool forward, bool backward); |
|
|
|
|
|
|
|
void rollCamera(bool CW, bool CCW); |
|
|
|
void rotateCamera(int32 xrel, int32 yrel); |
|
|
|
void rotateCamera(int32 xrel, int32 yrel); |
|
|
|
void renderFrame(const std::vector<hex_info> *hexes); |
|
|
|
void renderFrame(const std::vector<hex_info> *hexes); |
|
|
|
void renderDebug(std::vector<Point> &vertices); |
|
|
|
void renderDebug(std::vector<Point> &vertices); |
|
|
|
@ -273,11 +274,10 @@ initMatrices(projection_type p) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (p == PERSPECTIVE) |
|
|
|
if (p == PERSPECTIVE) |
|
|
|
{ |
|
|
|
{ |
|
|
|
g_scene_matrices.projection = glm::perspective( |
|
|
|
g_scene_matrices.projection = glm::infinitePerspective( |
|
|
|
glm::radians(60.f), // FoV
|
|
|
|
glm::radians(60.f), // FoV
|
|
|
|
16.f / 9.f, // ascpect ratio
|
|
|
|
16.f / 9.f, // ascpect ratio
|
|
|
|
0.1f, // near clip plane
|
|
|
|
0.1f // near clip plane
|
|
|
|
1000.0f // far clip plane
|
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
g_camera.position = glm::vec3(640,0,100);
|
|
|
|
g_camera.position = glm::vec3(640,0,100);
|
|
|
|
@ -400,6 +400,7 @@ moveCamera(bool up, bool left, bool down, bool right, bool forward, bool backwar |
|
|
|
glm::vec3 u = g_camera.up; |
|
|
|
glm::vec3 u = g_camera.up; |
|
|
|
glm::vec3 old = g_camera.position; |
|
|
|
glm::vec3 old = g_camera.position; |
|
|
|
glm::vec3 &p = g_camera.position; |
|
|
|
glm::vec3 &p = g_camera.position; |
|
|
|
|
|
|
|
|
|
|
|
if (forward) p += f * d; |
|
|
|
if (forward) p += f * d; |
|
|
|
if (backward) p -= f * d; |
|
|
|
if (backward) p -= f * d; |
|
|
|
if (up) p += u * d; |
|
|
|
if (up) p += u * d; |
|
|
|
@ -428,16 +429,46 @@ rotateCamera(int32 xrel, int32 yrel) |
|
|
|
float &v = c.vAngle; |
|
|
|
float &v = c.vAngle; |
|
|
|
h += 0.005f * xrel; |
|
|
|
h += 0.005f * xrel; |
|
|
|
v -= 0.005f * yrel; |
|
|
|
v -= 0.005f * yrel; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// clamp vAngle to + or - 85 degrees to prevent gimbal lock
|
|
|
|
|
|
|
|
float a = glm::radians(85.f); |
|
|
|
|
|
|
|
if (v < (-1 * a)) v = (-1 * a); |
|
|
|
|
|
|
|
if (v > a) v = a; |
|
|
|
|
|
|
|
|
|
|
|
c.forward = glm::vec3( |
|
|
|
c.forward = glm::vec3( |
|
|
|
glm::cos(v) * glm::sin(h), |
|
|
|
glm::cos(v) * glm::sin(h), |
|
|
|
glm::cos(v) * glm::cos(h), |
|
|
|
glm::cos(v) * glm::cos(h), |
|
|
|
glm::sin(v) |
|
|
|
glm::sin(v) |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c.up = glm::vec3(0,0,1); |
|
|
|
|
|
|
|
c.left = glm::cross(c.forward, c.up); |
|
|
|
|
|
|
|
|
|
|
|
g_scene_matrices.view = glm::lookAt(c.position, c.position + c.forward, c.up); |
|
|
|
g_scene_matrices.view = glm::lookAt(c.position, c.position + c.forward, c.up); |
|
|
|
g_scene_matrices.MVP = g_scene_matrices.projection * g_scene_matrices.view * g_scene_matrices.model;
|
|
|
|
g_scene_matrices.MVP = g_scene_matrices.projection * g_scene_matrices.view * g_scene_matrices.model;
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: don't need this yet
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
rollCamera(bool CW, bool CCW) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
|
|
|
if ((!CW && !CCW) || (CW && CCW)) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float a = 0.005f; |
|
|
|
|
|
|
|
if (CW) a *= 1; |
|
|
|
|
|
|
|
if (CCW) a *= -1; |
|
|
|
|
|
|
|
camera &c = g_camera; |
|
|
|
|
|
|
|
glm::mat4 m = glm::rotate(glm::mat4(1.f), a, c.forward); |
|
|
|
|
|
|
|
glm::vec4 v(c.up.x, c.up.y, c.up.z, 0); |
|
|
|
|
|
|
|
v = v * m; |
|
|
|
|
|
|
|
g_camera.up = glm::vec3(v.x, v.y, v.z); |
|
|
|
|
|
|
|
g_scene_matrices.view *= m; |
|
|
|
|
|
|
|
g_scene_matrices.MVP = g_scene_matrices.projection * g_scene_matrices.view * g_scene_matrices.model;
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
fillTriangleBufferFromHex(GLfloat buf[], int idx, const hex_info &hex) |
|
|
|
fillTriangleBufferFromHex(GLfloat buf[], int idx, const hex_info &hex) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|