From 01f22f23a001c5c2487e145c391740640482cfcc Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Fri, 10 Aug 2018 21:25:59 -0400 Subject: [PATCH] adding camera position to gooey --- src/gooey.cpp | 10 +++++++++- src/gooey.h | 2 +- src/hexgame.cpp | 22 +++++++++++----------- src/hexgame.h | 3 +++ src/renderer.cpp | 6 ++++++ src/renderer.h | 1 + src/util.h | 9 +++++++++ 7 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/gooey.cpp b/src/gooey.cpp index eb9712b..cd2fa51 100644 --- a/src/gooey.cpp +++ b/src/gooey.cpp @@ -42,7 +42,7 @@ gooeyProcessEvent(SDL_Event &event) 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) { ImGui_ImplSdlGL3_NewFrame(handles.window); @@ -77,9 +77,17 @@ renderGooey(SDL_Handles &handles, HexDrawMode &mode, bool &is_debug, ImGui::Text("is_selecting"); 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 SDL_Surface* image = handles.texSurfaces[0]; ImGui::Image((void*)(intptr_t) image->userdata, ImVec2(image->w, image->h)); +#endif //ImGui::ShowMetricsWindow(); if (current_hex) diff --git a/src/gooey.h b/src/gooey.h index 4f02c7f..282eb6b 100644 --- a/src/gooey.h +++ b/src/gooey.h @@ -7,5 +7,5 @@ bool initGooey(SDL_Handles &handles, v2i vp_dims); void shutdownGooey(); bool gooeyProcessEvent(SDL_Event &event); 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); diff --git a/src/hexgame.cpp b/src/hexgame.cpp index f5f5c6a..64571ef 100644 --- a/src/hexgame.cpp +++ b/src/hexgame.cpp @@ -1,11 +1,11 @@ -/* - * TODO: - * - add some sweet unit models - * - need to add indexed drawing for assimp models - * - map generation - * - pathfinding - * - update imgui to v1.62 -- requires changes to example api - */ +//----------------------------------------------------------------------------- +// TODO: +// - lighting +// - map generation +// - pathfinding +// - assimp animation +// - update imgui to v1.62 -- requires changes to example api +//----------------------------------------------------------------------------- // Some defaults for the game layout #define HEX_SIZE 10 @@ -14,8 +14,8 @@ #define FILL_COLOR 0x565656FF #define SELECTED_FILL_COLOR 0xF46000FF #define DEBUG_DRAW true -#define VIEWPORT_WIDTH 1280 -#define VIEWPORT_HEIGHT 720 +#define VIEWPORT_WIDTH 1920 +#define VIEWPORT_HEIGHT 1080 #define CONE_ANGLE 30 @@ -565,7 +565,7 @@ int main(int argc, char* argv[]) if (r->is_debug_draw && g->draw_mode == CONE_FILL) renderDebug(g_polygon_select_vertices); 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); } diff --git a/src/hexgame.h b/src/hexgame.h index 736c429..bba06f4 100644 --- a/src/hexgame.h +++ b/src/hexgame.h @@ -16,6 +16,7 @@ #include "mesh.h" +// TODO: should move this to renderer.h struct SDL_Handles { SDL_Window *window; @@ -48,6 +49,7 @@ enum HexDrawMode struct Entity { meMeshInfo* mesh; + //TODO: more entity properties: sound, gameplay info }; struct render_state @@ -57,6 +59,7 @@ struct render_state uint32 fill_color; uint32 selected_fill_color; + // TODO: should move this to game_state uint32 entity_count = 0; Entity* entities = nullptr; }; diff --git a/src/renderer.cpp b/src/renderer.cpp index 1d0ef7b..9b02a5a 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -156,6 +156,12 @@ 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); +} + void initMatrices(projection_type p) { diff --git a/src/renderer.h b/src/renderer.h index b2d2fe1..3cea771 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -9,6 +9,7 @@ bool initRenderer(SDL_Handles &handles, v2i vpDims); bool addTexture(SDL_Handles &handles, const char * path); v2f getUnprojectedCoords(int32 x, int32 y, int32 vp_width, int32 vp_height); +v3f getCameraPosition(); bool createScene(std::vector* hexes, Entity* entities, uint32 entity_count); void moveCamera(bool up, bool left, bool down, bool right, bool forward, bool backward); void rollCamera(bool CW, bool CCW); diff --git a/src/util.h b/src/util.h index 5b5ccf3..69c5fb4 100644 --- a/src/util.h +++ b/src/util.h @@ -28,6 +28,15 @@ struct v2i 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 { int32 x0;