|
|
|
@ -20,11 +20,6 @@ |
|
|
|
#include "renderer.h" |
|
|
|
#include "renderer.h" |
|
|
|
#include "render_group.h" |
|
|
|
#include "render_group.h" |
|
|
|
|
|
|
|
|
|
|
|
#define MOVE_SPEED 5.f |
|
|
|
|
|
|
|
#define ROTATE_SPEED 0.005f |
|
|
|
|
|
|
|
#define CAMERA_Z_CLAMP_ANGLE 85.f |
|
|
|
|
|
|
|
//#define PROJ_TYPE ORTHOGRAPHIC
|
|
|
|
|
|
|
|
#define PROJ_TYPE PERSPECTIVE |
|
|
|
|
|
|
|
#define DEFAULT_VERTEX_SHADER_FILE "../data/default.vs" |
|
|
|
#define DEFAULT_VERTEX_SHADER_FILE "../data/default.vs" |
|
|
|
#define DEFAULT_FRAGMENT_SHADER_FILE "../data/default.fs" |
|
|
|
#define DEFAULT_FRAGMENT_SHADER_FILE "../data/default.fs" |
|
|
|
#define MAX_LIGHTS 10 // NOTE: needs to match the fragment shader source
|
|
|
|
#define MAX_LIGHTS 10 // NOTE: needs to match the fragment shader source
|
|
|
|
@ -185,26 +180,6 @@ addTexture(SDL_Handles &handles, const char * path) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
camera& |
|
|
|
|
|
|
|
renGetCamera() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return g_render_state->cam; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v2f |
|
|
|
|
|
|
|
getUnprojectedCoords(int32 x, int32 y, int32 vp_width, int32 vp_height) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// NOTE: using depth buffer may not be as accurate as doing ray-cast
|
|
|
|
|
|
|
|
GLfloat depth; |
|
|
|
|
|
|
|
glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth); |
|
|
|
|
|
|
|
glm::vec4 viewport = glm::vec4(0, 0, vp_width, vp_height); |
|
|
|
|
|
|
|
glm::vec3 wincoord = glm::vec3(x, y, depth); |
|
|
|
|
|
|
|
glm::vec3 vU = glm::unProject(wincoord, g_render_state->cam.view, g_render_state->cam.projection, viewport); |
|
|
|
|
|
|
|
v2f v(vU.x, vU.y); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return v; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool |
|
|
|
bool |
|
|
|
createScene(render_state* rs, std::vector<hex_info>* hexes, Entity* entities, uint32 entity_count) |
|
|
|
createScene(render_state* rs, std::vector<hex_info>* hexes, Entity* entities, uint32 entity_count) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -215,9 +190,6 @@ createScene(render_state* rs, std::vector<hex_info>* hexes, Entity* entities, ui |
|
|
|
entities[i].ren_group->shader = g_default_shader; |
|
|
|
entities[i].ren_group->shader = g_default_shader; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: rename/alter this now that we init camera in sceneloader
|
|
|
|
|
|
|
|
initMatrices(PROJ_TYPE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!initHexGridBuffers(hexes)) |
|
|
|
if (!initHexGridBuffers(hexes)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
@ -250,91 +222,6 @@ createScene(render_state* rs, std::vector<hex_info>* hexes, Entity* entities, ui |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
moveCamera(bool up, bool left, bool down, bool right, bool forward, bool backward) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!up && !left && !down && !right && !forward && !backward) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glm::vec3 f = g_render_state->cam.forward; |
|
|
|
|
|
|
|
glm::vec3 u = g_render_state->cam.up; |
|
|
|
|
|
|
|
glm::vec3 old = g_render_state->cam.position; |
|
|
|
|
|
|
|
glm::vec3 &p = g_render_state->cam.position; |
|
|
|
|
|
|
|
glm::vec3 v(0.f); // normalized direction
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: still seems like we're adding magnitude when moving in 2 directions
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
|
|
|
if (forward) v = glm::normalize(v + f); |
|
|
|
|
|
|
|
if (backward) v = glm::normalize(v - f); |
|
|
|
|
|
|
|
if (up) v = glm::normalize(v + u); |
|
|
|
|
|
|
|
if (down) v = glm::normalize(v - u); |
|
|
|
|
|
|
|
if (left) v -= glm::normalize(glm::cross(f, u)); |
|
|
|
|
|
|
|
if (right) v -= glm::normalize(glm::cross(u, f)); |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
if (forward) v += f; |
|
|
|
|
|
|
|
if (backward) v -= f; |
|
|
|
|
|
|
|
if (up) v += u; |
|
|
|
|
|
|
|
if (down) v -= u; |
|
|
|
|
|
|
|
if (left) v -= glm::cross(f, u); |
|
|
|
|
|
|
|
if (right) v -= glm::cross(u, f); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p += (v * MOVE_SPEED); |
|
|
|
|
|
|
|
glm::vec3 diff = old - p; |
|
|
|
|
|
|
|
g_render_state->cam.view = glm::translate(g_render_state->cam.view, diff); |
|
|
|
|
|
|
|
g_render_state->cam.MVP = g_render_state->cam.projection * g_render_state->cam.view * g_render_state->cam.model; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
rotateCamera(int32 xrel, int32 yrel) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
camera &c = g_render_state->cam; |
|
|
|
|
|
|
|
float &h = c.hAngle; |
|
|
|
|
|
|
|
float &v = c.vAngle; |
|
|
|
|
|
|
|
h += ROTATE_SPEED * xrel; |
|
|
|
|
|
|
|
v -= ROTATE_SPEED * yrel; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// clamp vAngle to prevent gimbal lock
|
|
|
|
|
|
|
|
float a = glm::radians(CAMERA_Z_CLAMP_ANGLE); |
|
|
|
|
|
|
|
if (v < (-1 * a)) v = (-1 * a); |
|
|
|
|
|
|
|
if (v > a) v = a; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c.forward = glm::vec3( |
|
|
|
|
|
|
|
glm::cos(v) * glm::sin(h), |
|
|
|
|
|
|
|
glm::cos(v) * glm::cos(h), |
|
|
|
|
|
|
|
glm::sin(v) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glm::normalize(c.forward); |
|
|
|
|
|
|
|
c.up = glm::vec3(0,0,1); |
|
|
|
|
|
|
|
c.left = glm::normalize(glm::cross(c.forward, c.up)); |
|
|
|
|
|
|
|
c.up = glm::normalize(glm::cross(c.left, c.forward)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g_render_state->cam.view = glm::lookAt(c.position, c.position + c.forward, c.up); |
|
|
|
|
|
|
|
g_render_state->cam.MVP = g_render_state->cam.projection * g_render_state->cam.view * g_render_state->cam.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_render_state->cam; |
|
|
|
|
|
|
|
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_render_state->cam.up = glm::vec3(v.x, v.y, v.z); |
|
|
|
|
|
|
|
g_render_state->cam.view *= m; |
|
|
|
|
|
|
|
g_render_state->cam.MVP = g_render_state->cam.projection * g_render_state->cam.view * g_render_state->cam.model; |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
renderFrame(render_state* rs, std::vector<hex_info> *hexes, Entity* entities, uint32 entity_count) |
|
|
|
renderFrame(render_state* rs, std::vector<hex_info> *hexes, Entity* entities, uint32 entity_count) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -382,33 +269,6 @@ renderDebug(render_state* rs, std::vector<Point> &vertices) |
|
|
|
|
|
|
|
|
|
|
|
// internal
|
|
|
|
// internal
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
initMatrices(projection_type p) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// TODO: many constants used here should be passed as args
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (p == PERSPECTIVE) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
g_render_state->cam.projection = g_render_state->cam.projection; |
|
|
|
|
|
|
|
g_render_state->cam.view = g_render_state->cam.view; |
|
|
|
|
|
|
|
//g_render_state->cam.model = g_render_state->cam.model;
|
|
|
|
|
|
|
|
//g_render_state->cam.MVP = g_render_state->cam.MVP;
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else // ORTHO
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// left, right, bottom, top, zNear, zFar
|
|
|
|
|
|
|
|
g_render_state->cam.projection = glm::ortho(0.f, 1280.0f, 0.f, 720.0f, 0.1f, 100.0f); |
|
|
|
|
|
|
|
g_render_state->cam.view = glm::lookAt( |
|
|
|
|
|
|
|
glm::vec3(0.0f, 0.0f, 1.0f), // camera position
|
|
|
|
|
|
|
|
glm::vec3(0.0f, 0.0f, 0.0f), // look at position
|
|
|
|
|
|
|
|
glm::vec3(0,1,0) // "up" vector
|
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g_render_state->cam.model = glm::mat4(1.0f); |
|
|
|
|
|
|
|
g_render_state->cam.MVP = g_render_state->cam.projection * g_render_state->cam.view * g_render_state->cam.model; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
openglDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, |
|
|
|
openglDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, |
|
|
|
GLsizei length, const GLchar* message, const void* userParam) |
|
|
|
GLsizei length, const GLchar* message, const void* userParam) |
|
|
|
|