Browse Source

adding camera position to gooey

master
cinnaboot 8 years ago
parent
commit
01f22f23a0
  1. 10
      src/gooey.cpp
  2. 2
      src/gooey.h
  3. 22
      src/hexgame.cpp
  4. 3
      src/hexgame.h
  5. 6
      src/renderer.cpp
  6. 1
      src/renderer.h
  7. 9
      src/util.h

10
src/gooey.cpp

@ -42,7 +42,7 @@ gooeyProcessEvent(SDL_Event &event)
void void
renderGooey(SDL_Handles &handles, HexDrawMode &mode, bool &is_debug, renderGooey(SDL_Handles &handles, HexDrawMode &mode, bool &is_debug,
hex_info* start_hex, hex_info* current_hex, bool &is_selecting) hex_info* start_hex, hex_info* current_hex, bool &is_selecting, v3f camera_pos)
{ {
ImGui_ImplSdlGL3_NewFrame(handles.window); ImGui_ImplSdlGL3_NewFrame(handles.window);
@ -77,9 +77,17 @@ renderGooey(SDL_Handles &handles, HexDrawMode &mode, bool &is_debug,
ImGui::Text("is_selecting"); ImGui::Text("is_selecting");
ImGui::SameLine(); ImGui::TextUnformatted(is_selecting ? "true" : "false"); ImGui::SameLine(); ImGui::TextUnformatted(is_selecting ? "true" : "false");
if (ImGui::CollapsingHeader("Camera Position")) {
ImGui::Text("x: %f", camera_pos.x);
ImGui::Text("x: %f", camera_pos.y);
ImGui::Text("x: %f", camera_pos.z);
}
#if 0
// testing SDL_image // testing SDL_image
SDL_Surface* image = handles.texSurfaces[0]; SDL_Surface* image = handles.texSurfaces[0];
ImGui::Image((void*)(intptr_t) image->userdata, ImVec2(image->w, image->h)); ImGui::Image((void*)(intptr_t) image->userdata, ImVec2(image->w, image->h));
#endif
//ImGui::ShowMetricsWindow(); //ImGui::ShowMetricsWindow();
if (current_hex) if (current_hex)

2
src/gooey.h

@ -7,5 +7,5 @@ bool initGooey(SDL_Handles &handles, v2i vp_dims);
void shutdownGooey(); void shutdownGooey();
bool gooeyProcessEvent(SDL_Event &event); bool gooeyProcessEvent(SDL_Event &event);
void renderGooey(SDL_Handles &handles, HexDrawMode &mode, bool &is_debug, void renderGooey(SDL_Handles &handles, HexDrawMode &mode, bool &is_debug,
hex_info* start_hex, hex_info* current_hex, bool &is_selecting); hex_info* start_hex, hex_info* current_hex, bool &is_selecting, v3f camera_pos);

22
src/hexgame.cpp

@ -1,11 +1,11 @@
/* //-----------------------------------------------------------------------------
* TODO: // TODO:
* - add some sweet unit models // - lighting
* - need to add indexed drawing for assimp models // - map generation
* - map generation // - pathfinding
* - pathfinding // - assimp animation
* - update imgui to v1.62 -- requires changes to example api // - update imgui to v1.62 -- requires changes to example api
*/ //-----------------------------------------------------------------------------
// Some defaults for the game layout // Some defaults for the game layout
#define HEX_SIZE 10 #define HEX_SIZE 10
@ -14,8 +14,8 @@
#define FILL_COLOR 0x565656FF #define FILL_COLOR 0x565656FF
#define SELECTED_FILL_COLOR 0xF46000FF #define SELECTED_FILL_COLOR 0xF46000FF
#define DEBUG_DRAW true #define DEBUG_DRAW true
#define VIEWPORT_WIDTH 1280 #define VIEWPORT_WIDTH 1920
#define VIEWPORT_HEIGHT 720 #define VIEWPORT_HEIGHT 1080
#define CONE_ANGLE 30 #define CONE_ANGLE 30
@ -565,7 +565,7 @@ int main(int argc, char* argv[])
if (r->is_debug_draw && g->draw_mode == CONE_FILL) if (r->is_debug_draw && g->draw_mode == CONE_FILL)
renderDebug(g_polygon_select_vertices); renderDebug(g_polygon_select_vertices);
renderGooey(handles, g->draw_mode, r->is_debug_draw, g->start_hex, renderGooey(handles, g->draw_mode, r->is_debug_draw, g->start_hex,
g->current_hex, g->is_selecting); g->current_hex, g->is_selecting, getCameraPosition());
SDL_GL_SwapWindow(handles.window); SDL_GL_SwapWindow(handles.window);
} }

3
src/hexgame.h

@ -16,6 +16,7 @@
#include "mesh.h" #include "mesh.h"
// TODO: should move this to renderer.h
struct SDL_Handles struct SDL_Handles
{ {
SDL_Window *window; SDL_Window *window;
@ -48,6 +49,7 @@ enum HexDrawMode
struct Entity struct Entity
{ {
meMeshInfo* mesh; meMeshInfo* mesh;
//TODO: more entity properties: sound, gameplay info
}; };
struct render_state struct render_state
@ -57,6 +59,7 @@ struct render_state
uint32 fill_color; uint32 fill_color;
uint32 selected_fill_color; uint32 selected_fill_color;
// TODO: should move this to game_state
uint32 entity_count = 0; uint32 entity_count = 0;
Entity* entities = nullptr; Entity* entities = nullptr;
}; };

6
src/renderer.cpp

@ -156,6 +156,12 @@ getUnprojectedCoords(int32 x, int32 y, int32 vp_width, int32 vp_height)
return v; return v;
} }
v3f
getCameraPosition()
{
return v3f(g_camera.position.x, g_camera.position.y, g_camera.position.z);
}
void void
initMatrices(projection_type p) initMatrices(projection_type p)
{ {

1
src/renderer.h

@ -9,6 +9,7 @@
bool initRenderer(SDL_Handles &handles, v2i vpDims); bool initRenderer(SDL_Handles &handles, v2i vpDims);
bool addTexture(SDL_Handles &handles, const char * path); bool addTexture(SDL_Handles &handles, const char * path);
v2f getUnprojectedCoords(int32 x, int32 y, int32 vp_width, int32 vp_height); v2f getUnprojectedCoords(int32 x, int32 y, int32 vp_width, int32 vp_height);
v3f getCameraPosition();
bool createScene(std::vector<hex_info>* hexes, Entity* entities, uint32 entity_count); bool createScene(std::vector<hex_info>* hexes, Entity* entities, uint32 entity_count);
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 rollCamera(bool CW, bool CCW);

9
src/util.h

@ -28,6 +28,15 @@ struct v2i
int32 y; int32 y;
}; };
struct v3f
{
v3f(): x(0), y(0), z(0) {}
v3f(real64 a, real64 b, real64 c): x(a), y(b), z(c) {}
real64 x;
real64 y;
real64 z;
};
struct v4i struct v4i
{ {
int32 x0; int32 x0;

Loading…
Cancel
Save