|
|
|
|
@ -66,7 +66,7 @@ static render_group* g_hex_line_render_group;
|
|
|
|
|
static render_group* g_debug_render_group; |
|
|
|
|
static rg_shader_program g_default_shader; |
|
|
|
|
// NOTE: entity render_group pointers are kept in the entity struct
|
|
|
|
|
static camera g_camera; |
|
|
|
|
static render_state* g_render_state; |
|
|
|
|
// TODO: maybe keep all these globals in the render_state object?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -76,6 +76,8 @@ static camera g_camera;
|
|
|
|
|
bool |
|
|
|
|
initRenderer(render_state* rs) |
|
|
|
|
{ |
|
|
|
|
g_render_state = rs; |
|
|
|
|
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); |
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); |
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
|
|
|
|
@ -196,7 +198,7 @@ addTexture(SDL_Handles &handles, const char * path)
|
|
|
|
|
camera& |
|
|
|
|
renGetCamera() |
|
|
|
|
{ |
|
|
|
|
return g_camera; |
|
|
|
|
return g_render_state->cam; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
v2f |
|
|
|
|
@ -213,12 +215,6 @@ getUnprojectedCoords(int32 x, int32 y, int32 vp_width, int32 vp_height)
|
|
|
|
|
return v; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
v3f |
|
|
|
|
getCameraPosition() |
|
|
|
|
{ |
|
|
|
|
return v3f(g_camera.position.x, g_camera.position.y, g_camera.position.z); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
createScene(render_state* rs, std::vector<hex_info>* hexes, Entity* entities, uint32 entity_count) |
|
|
|
|
{ |
|
|
|
|
@ -270,10 +266,10 @@ moveCamera(bool up, bool left, bool down, bool right, bool forward, bool backwar
|
|
|
|
|
if (!up && !left && !down && !right && !forward && !backward) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
glm::vec3 f = g_camera.forward; |
|
|
|
|
glm::vec3 u = g_camera.up; |
|
|
|
|
glm::vec3 old = g_camera.position; |
|
|
|
|
glm::vec3 &p = g_camera.position; |
|
|
|
|
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
|
|
|
|
|
@ -302,7 +298,7 @@ moveCamera(bool up, bool left, bool down, bool right, bool forward, bool backwar
|
|
|
|
|
void |
|
|
|
|
rotateCamera(int32 xrel, int32 yrel) |
|
|
|
|
{ |
|
|
|
|
camera &c = g_camera; |
|
|
|
|
camera &c = g_render_state->cam; |
|
|
|
|
float &h = c.hAngle; |
|
|
|
|
float &v = c.vAngle; |
|
|
|
|
h += ROTATE_SPEED * xrel; |
|
|
|
|
@ -339,11 +335,11 @@ rollCamera(bool CW, bool CCW)
|
|
|
|
|
float a = 0.005f; |
|
|
|
|
if (CW) a *= 1; |
|
|
|
|
if (CCW) a *= -1; |
|
|
|
|
camera &c = g_camera; |
|
|
|
|
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_camera.up = glm::vec3(v.x, v.y, v.z); |
|
|
|
|
g_render_state->cam.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 |
|
|
|
|
@ -404,10 +400,10 @@ initMatrices(projection_type p)
|
|
|
|
|
if (p == PERSPECTIVE) |
|
|
|
|
{ |
|
|
|
|
// TODO: replace referernces to g_scene_matrices with camera.matrix_name
|
|
|
|
|
g_scene_matrices.projection = g_camera.projection; |
|
|
|
|
g_scene_matrices.view = g_camera.view; |
|
|
|
|
//g_scene_matrices.model = g_camera.model;
|
|
|
|
|
//g_scene_matrices.MVP = g_camera.MVP;
|
|
|
|
|
g_scene_matrices.projection = g_render_state->cam.projection; |
|
|
|
|
g_scene_matrices.view = g_render_state->cam.view; |
|
|
|
|
//g_scene_matrices.model = g_render_state->cam.model;
|
|
|
|
|
//g_scene_matrices.MVP = g_render_state->cam.MVP;
|
|
|
|
|
#if 0 |
|
|
|
|
g_scene_matrices.projection = glm::infinitePerspective( |
|
|
|
|
glm::radians(60.f), // FoV
|
|
|
|
|
@ -415,18 +411,18 @@ initMatrices(projection_type p)
|
|
|
|
|
0.1f // near clip plane
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
g_camera.position = glm::vec3(640,0,100); |
|
|
|
|
g_camera.target = glm::vec3(640,500,0); |
|
|
|
|
//g_camera.target = glm::vec3(0,0,0);
|
|
|
|
|
g_render_state->cam.position = glm::vec3(640,0,100); |
|
|
|
|
g_render_state->cam.target = glm::vec3(640,500,0); |
|
|
|
|
//g_render_state->cam.target = glm::vec3(0,0,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((t.z - p.z) / (t.y - p.y)); |
|
|
|
|
glm::vec3 &p = g_render_state->cam.position; |
|
|
|
|
glm::vec3 &t = g_render_state->cam.target; |
|
|
|
|
g_render_state->cam.hAngle = 0; |
|
|
|
|
g_render_state->cam.vAngle = glm::atan((t.z - p.z) / (t.y - p.y)); |
|
|
|
|
|
|
|
|
|
//////
|
|
|
|
|
// TODO: add call to rotate camera here to remove duplicate code
|
|
|
|
|
camera &c = g_camera; |
|
|
|
|
camera &c = g_render_state->cam; |
|
|
|
|
float &h = c.hAngle; |
|
|
|
|
float &v = c.vAngle; |
|
|
|
|
c.forward = glm::vec3( |
|
|
|
|
@ -438,14 +434,14 @@ initMatrices(projection_type p)
|
|
|
|
|
glm::normalize(c.forward); |
|
|
|
|
//////
|
|
|
|
|
|
|
|
|
|
g_camera.up = glm::vec3(0,1,0); |
|
|
|
|
g_camera.left = glm::normalize(glm::cross(g_camera.up, g_camera.forward)); |
|
|
|
|
g_camera.up = glm::normalize(glm::cross(g_camera.forward, g_camera.left)); |
|
|
|
|
g_render_state->cam.up = glm::vec3(0,1,0); |
|
|
|
|
g_render_state->cam.left = glm::normalize(glm::cross(g_render_state->cam.up, g_render_state->cam.forward)); |
|
|
|
|
g_render_state->cam.up = glm::normalize(glm::cross(g_render_state->cam.forward, g_render_state->cam.left)); |
|
|
|
|
|
|
|
|
|
g_scene_matrices.view = glm::lookAt( |
|
|
|
|
g_camera.position, // camera position
|
|
|
|
|
g_camera.position + g_camera.forward, |
|
|
|
|
g_camera.up // "up" vector
|
|
|
|
|
g_render_state->cam.position, // camera position
|
|
|
|
|
g_render_state->cam.position + g_render_state->cam.forward, |
|
|
|
|
g_render_state->cam.up // "up" vector
|
|
|
|
|
); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|