|
|
|
@ -18,6 +18,11 @@ |
|
|
|
#include "hexlib.h" |
|
|
|
#include "hexlib.h" |
|
|
|
#include "hexgame.h" |
|
|
|
#include "hexgame.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
|
|
|
#define PROJ_TYPE ORTHOGRAPHIC |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
#define PROJ_TYPE PERSPECTIVE |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
const char * VERTEX_SHADER_CODE = |
|
|
|
const char * VERTEX_SHADER_CODE = |
|
|
|
"#version 330 core\n" |
|
|
|
"#version 330 core\n" |
|
|
|
@ -82,6 +87,8 @@ enum projection_type |
|
|
|
struct camera |
|
|
|
struct camera |
|
|
|
{ |
|
|
|
{ |
|
|
|
glm::vec3 position; |
|
|
|
glm::vec3 position; |
|
|
|
|
|
|
|
float hAngle; |
|
|
|
|
|
|
|
float vAngle; |
|
|
|
glm::vec3 target; |
|
|
|
glm::vec3 target; |
|
|
|
glm::vec3 forward; |
|
|
|
glm::vec3 forward; |
|
|
|
glm::vec3 up; |
|
|
|
glm::vec3 up; |
|
|
|
@ -275,44 +282,23 @@ initMatrices(projection_type p) |
|
|
|
|
|
|
|
|
|
|
|
g_camera.position = glm::vec3(640,0,100);
|
|
|
|
g_camera.position = glm::vec3(640,0,100);
|
|
|
|
g_camera.target = glm::vec3(640,500,0); |
|
|
|
g_camera.target = glm::vec3(640,500,0); |
|
|
|
|
|
|
|
// inital rotation should match target direction
|
|
|
|
|
|
|
|
glm::vec3 &p = g_camera.position; |
|
|
|
|
|
|
|
glm::vec3 &t = g_camera.target; |
|
|
|
|
|
|
|
g_camera.hAngle = 0; |
|
|
|
|
|
|
|
g_camera.vAngle = glm::atan((p.z - t.z) / (p.y - t.y)); |
|
|
|
|
|
|
|
|
|
|
|
g_camera.up = glm::vec3(0,1,0); |
|
|
|
g_camera.up = glm::vec3(0,1,0); |
|
|
|
g_camera.forward = glm::normalize(g_camera.position - g_camera.target); |
|
|
|
g_camera.forward = glm::normalize(g_camera.position - g_camera.target); |
|
|
|
g_camera.left = glm::normalize(glm::cross(g_camera.up, g_camera.forward)); |
|
|
|
g_camera.left = glm::normalize(glm::cross(g_camera.up, g_camera.forward)); |
|
|
|
g_camera.up = glm::cross(g_camera.forward, g_camera.left); |
|
|
|
g_camera.up = glm::cross(g_camera.forward, g_camera.left); |
|
|
|
|
|
|
|
|
|
|
|
glm::vec3 P, T, U; |
|
|
|
|
|
|
|
P = normalize(g_camera.position); |
|
|
|
|
|
|
|
T = normalize(g_camera.target); |
|
|
|
|
|
|
|
U = normalize(g_camera.up); |
|
|
|
|
|
|
|
//g_camera.forward = glm::cross(T - P, U);
|
|
|
|
|
|
|
|
#if 1 |
|
|
|
|
|
|
|
glm::mat4 mV = glm::lookAt( |
|
|
|
glm::mat4 mV = glm::lookAt( |
|
|
|
g_camera.position, // camera position
|
|
|
|
g_camera.position, // camera position
|
|
|
|
g_camera.target, // look at position
|
|
|
|
g_camera.target, // look at position
|
|
|
|
g_camera.up // "up" vector
|
|
|
|
g_camera.up // "up" vector
|
|
|
|
); |
|
|
|
); |
|
|
|
g_scene_matrices.view = mV; |
|
|
|
g_scene_matrices.view = mV; |
|
|
|
#else |
|
|
|
|
|
|
|
// get normalized vector from pos to target
|
|
|
|
|
|
|
|
glm::vec3 N = g_camera.target; |
|
|
|
|
|
|
|
glm::normalize(N); |
|
|
|
|
|
|
|
//glm::vec3 U = glm::vec3(0,1,0);
|
|
|
|
|
|
|
|
U = glm::cross(U, N); |
|
|
|
|
|
|
|
glm::vec3 V = glm::cross(N, U); |
|
|
|
|
|
|
|
glm::mat4 mR = glm::mat4(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mR[0][0] = U.x; mR[0][1] = U.y; mR[0][2] = U.z; mR[0][3] = 0.f; |
|
|
|
|
|
|
|
mR[1][0] = V.x; mR[1][1] = V.y; mR[1][2] = V.z; mR[1][3] = 0.f; |
|
|
|
|
|
|
|
mR[2][0] = N.x; mR[2][1] = N.y; mR[2][2] = N.z; mR[2][3] = 0.f; |
|
|
|
|
|
|
|
mR[3][0] = 0.f; mR[3][1] = 0.f; mR[3][2] = 0.f; mR[3][3] = 1.f; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get translation xfrom
|
|
|
|
|
|
|
|
glm::vec3 p = g_camera.position; |
|
|
|
|
|
|
|
glm::mat4 mT = glm::translate(glm::mat4(1.0f), glm::vec3(-1 * p.x, -1 * p.y, -1 * p.z)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glm::mat4 mVtemp = mR * mT; |
|
|
|
|
|
|
|
//g_scene_matrices.view = mR * mT;
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else // ORTHO
|
|
|
|
else // ORTHO
|
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -329,12 +315,6 @@ initMatrices(projection_type p) |
|
|
|
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;
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
|
|
|
#define PROJ_TYPE ORTHOGRAPHIC |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
#define PROJ_TYPE PERSPECTIVE |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool |
|
|
|
bool |
|
|
|
createScene(std::vector<hex_info>* hexes) |
|
|
|
createScene(std::vector<hex_info>* hexes) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -429,22 +409,19 @@ moveCamera(bool up, bool left, bool down, bool right) |
|
|
|
void |
|
|
|
void |
|
|
|
rotateCamera(int32 xrel, int32 yrel) |
|
|
|
rotateCamera(int32 xrel, int32 yrel) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#if 1 |
|
|
|
camera &c = g_camera; |
|
|
|
glm::mat4 &m = g_scene_matrices.view; |
|
|
|
float &h = c.hAngle; |
|
|
|
glm::vec3 &c = g_camera.position; |
|
|
|
float &v = c.vAngle; |
|
|
|
|
|
|
|
h += 0.005f * xrel; |
|
|
|
|
|
|
|
c.forward = glm::vec3( |
|
|
|
|
|
|
|
glm::cos(v) * glm::sin(h), |
|
|
|
|
|
|
|
glm::cos(v) * glm::cos(h), |
|
|
|
|
|
|
|
glm::sin(v) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
m = glm::translate(m, glm::vec3(c.x, c.y, c.z)); |
|
|
|
|
|
|
|
m = glm::rotate(m, glm::radians(0.5f * xrel), glm::vec3(0.f,0.f,1.f)); |
|
|
|
|
|
|
|
m = glm::translate(m, glm::vec3(-1.f * c.x, -1.f * c.y, -1.f * c.z)); |
|
|
|
|
|
|
|
g_scene_matrices.MVP = g_scene_matrices.projection * m * g_scene_matrices.model;
|
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
glm::mat4 &m = g_scene_matrices.view; |
|
|
|
glm::mat4 &m = g_scene_matrices.view; |
|
|
|
glm::vec3 &c = g_camera.position; |
|
|
|
m = glm::lookAt(c.position, c.position + c.forward, c.up); |
|
|
|
|
|
|
|
|
|
|
|
m = glm::translate(m, glm::vec3(-1.f * c.x, -1.f * c.y, -1.f * c.z)); |
|
|
|
|
|
|
|
m = glm::rotate(m, glm::radians(0.5f * xrel), glm::vec3(0.f,0.f,1.f)); |
|
|
|
|
|
|
|
g_scene_matrices.MVP = g_scene_matrices.projection * m * g_scene_matrices.model;
|
|
|
|
g_scene_matrices.MVP = g_scene_matrices.projection * m * g_scene_matrices.model;
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
|