diff --git a/RecastDemo/Include/InputGeom.h b/RecastDemo/Include/InputGeom.h index 2d3158ee..ff5ec899 100644 --- a/RecastDemo/Include/InputGeom.h +++ b/RecastDemo/Include/InputGeom.h @@ -18,9 +18,15 @@ #pragma once -#include "ChunkyTriMesh.h" +//#include "ChunkyTriMesh.h" +//#include "MeshLoaderObj.h" #include +#include + +struct ChunkyTriMesh; +class rcContext; +struct duDebugDraw; static constexpr int MAX_CONVEXVOL_PTS = 12; struct ConvexVolume @@ -79,8 +85,8 @@ public: std::vector tris; std::vector normals; - int getVertCount() const { return static_cast(verts.size()) / 3; } - int getTriCount() const { return static_cast(tris.size()) / 3; } + [[nodiscard]] int getVertCount() const { return static_cast(verts.size()) / 3; } + [[nodiscard]] int getTriCount() const { return static_cast(tris.size()) / 3; } private: ChunkyTriMesh* chunkyMesh = nullptr; @@ -108,56 +114,56 @@ private: int volumeCount = 0; ///@} - bool loadMesh(class rcContext* ctx, const std::string& filepath); - bool loadGeomSet(class rcContext* ctx, const std::string& filepath); + bool loadMesh(rcContext* ctx, const std::string& filepath); + bool loadGeomSet(rcContext* ctx, const std::string& filepath); bool loadGeomSet(rcContext* ctx, char* buffer, size_t bufferLen); public: InputGeom() = default; - ~InputGeom() { delete chunkyMesh; } + ~InputGeom(); InputGeom(const InputGeom&) = delete; InputGeom& operator=(const InputGeom&) = delete; InputGeom(InputGeom&&) = delete; InputGeom& operator=(InputGeom&&) = delete; - bool load(class rcContext* ctx, const std::string& filepath); + bool load(rcContext* ctx, const std::string& filepath); bool saveGeomSet(const BuildSettings* settings); /// Method to return static mesh data. - const float* getMeshBoundsMin() const { return meshBMin; } - const float* getMeshBoundsMax() const { return meshBMax; } - const float* getNavMeshBoundsMin() const { return hasBuildSettings ? buildSettings.navMeshBMin : meshBMin; } - const float* getNavMeshBoundsMax() const { return hasBuildSettings ? buildSettings.navMeshBMax : meshBMax; } - const ChunkyTriMesh* getChunkyMesh() const { return chunkyMesh; } - const BuildSettings* getBuildSettings() const { return hasBuildSettings ? &buildSettings : 0; } + [[nodiscard]] const float* getMeshBoundsMin() const { return meshBMin; } + [[nodiscard]] const float* getMeshBoundsMax() const { return meshBMax; } + [[nodiscard]] const float* getNavMeshBoundsMin() const { return hasBuildSettings ? buildSettings.navMeshBMin : meshBMin; } + [[nodiscard]] const float* getNavMeshBoundsMax() const { return hasBuildSettings ? buildSettings.navMeshBMax : meshBMax; } + [[nodiscard]] const ChunkyTriMesh* getChunkyMesh() const { return chunkyMesh; } + [[nodiscard]] const BuildSettings* getBuildSettings() const { return hasBuildSettings ? &buildSettings : 0; } bool raycastMesh(float* src, float* dst, float& tmin); /// @name Off-Mesh connections. ///@{ - int getOffMeshConnectionCount() const { return offMeshConCount; } - const float* getOffMeshConnectionVerts() const { return offMeshConVerts; } - const float* getOffMeshConnectionRads() const { return offMeshConRads; } - const unsigned char* getOffMeshConnectionDirs() const { return offMeshConDirs; } - const unsigned char* getOffMeshConnectionAreas() const { return offMeshConAreas; } - const unsigned short* getOffMeshConnectionFlags() const { return offMeshConFlags; } - const unsigned int* getOffMeshConnectionId() const { return offMeshConId; } + [[nodiscard]] int getOffMeshConnectionCount() const { return offMeshConCount; } + [[nodiscard]] const float* getOffMeshConnectionVerts() const { return offMeshConVerts; } + [[nodiscard]] const float* getOffMeshConnectionRads() const { return offMeshConRads; } + [[nodiscard]] const unsigned char* getOffMeshConnectionDirs() const { return offMeshConDirs; } + [[nodiscard]] const unsigned char* getOffMeshConnectionAreas() const { return offMeshConAreas; } + [[nodiscard]] const unsigned short* getOffMeshConnectionFlags() const { return offMeshConFlags; } + [[nodiscard]] const unsigned int* getOffMeshConnectionId() const { return offMeshConId; } void addOffMeshConnection( const float* spos, const float* epos, - const float rad, + float rad, unsigned char bidir, unsigned char area, unsigned short flags); void deleteOffMeshConnection(int i); - void drawOffMeshConnections(struct duDebugDraw* dd, bool hilight = false); + void drawOffMeshConnections(duDebugDraw* dd, bool highlight = false); ///@} /// @name Box Volumes. ///@{ - int getConvexVolumeCount() const { return volumeCount; } - const ConvexVolume* getConvexVolumes() const { return volumes; } - void addConvexVolume(const float* verts, const int nverts, const float minh, const float maxh, unsigned char area); + [[nodiscard]] int getConvexVolumeCount() const { return volumeCount; } + [[nodiscard]] const ConvexVolume* getConvexVolumes() const { return volumes; } + void addConvexVolume(const float* verts, int nverts, float minh, float maxh, unsigned char area); void deleteConvexVolume(int i); - void drawConvexVolumes(struct duDebugDraw* dd, bool hilight = false); + void drawConvexVolumes(duDebugDraw* dd, bool highlight = false); ///@} }; diff --git a/RecastDemo/Include/PerfTimer.h b/RecastDemo/Include/PerfTimer.h index 36cf96f5..2e5be4df 100644 --- a/RecastDemo/Include/PerfTimer.h +++ b/RecastDemo/Include/PerfTimer.h @@ -22,4 +22,4 @@ typedef int64_t TimeVal; TimeVal getPerfTime(); -int getPerfTimeUsec(const TimeVal duration); +int getPerfTimeUsec(TimeVal duration); diff --git a/RecastDemo/Include/Sample.h b/RecastDemo/Include/Sample.h index 61f2c809..63a2c094 100644 --- a/RecastDemo/Include/Sample.h +++ b/RecastDemo/Include/Sample.h @@ -76,12 +76,12 @@ enum SamplePartitionType class SampleDebugDraw : public DebugDrawGL { public: - virtual unsigned int areaToCol(unsigned int area); + unsigned int areaToCol(unsigned int area) override; }; struct SampleTool { - virtual ~SampleTool(); + virtual ~SampleTool() = default; virtual SampleToolType type() = 0; virtual void init(Sample* sample) = 0; @@ -97,7 +97,7 @@ struct SampleTool struct SampleToolState { - virtual ~SampleToolState(); + virtual ~SampleToolState() = default; virtual void init(Sample* sample) = 0; virtual void reset() = 0; virtual void handleRender() = 0; @@ -135,7 +135,7 @@ protected: bool filterWalkableLowHeightSpans = true; SampleTool* tool = nullptr; - SampleToolState* toolStates[static_cast(SampleToolType::MAX_TOOLS)]; + SampleToolState* toolStates[static_cast(SampleToolType::MAX_TOOLS)] = {}; BuildContext* buildContext = nullptr; @@ -184,11 +184,11 @@ public: unsigned char getNavMeshDrawFlags() const { return navMeshDrawFlags; } void setNavMeshDrawFlags(unsigned char flags) { navMeshDrawFlags = flags; } - void updateToolStates(float dt); - void initToolStates(Sample* sample); - void resetToolStates(); - void renderToolStates(); - void renderOverlayToolStates(double* proj, double* model, int* view); + void updateToolStates(float dt) const; + void initToolStates(Sample* sample) const; + void resetToolStates() const; + void renderToolStates() const; + void renderOverlayToolStates(double* proj, double* model, int* view) const; void resetCommonSettings(); void handleCommonSettings(); diff --git a/RecastDemo/Include/SampleInterfaces.h b/RecastDemo/Include/SampleInterfaces.h index 91a4c460..62926d0a 100644 --- a/RecastDemo/Include/SampleInterfaces.h +++ b/RecastDemo/Include/SampleInterfaces.h @@ -24,14 +24,13 @@ #include "RecastDump.h" #include -#include #include #include // These are example implementations of various interfaces used in Recast and Detour. /// Recast build context. -class BuildContext : public rcContext +class BuildContext final : public rcContext { std::array startTime; std::array accTime; @@ -44,9 +43,9 @@ public: /// Dumps the log to stdout. void dumpLog(const char* format, ...); /// Returns number of log messages. - int getLogCount() const; + [[nodiscard]] int getLogCount() const; /// Returns log message text. - const char* getLogText(const int i) const; + [[nodiscard]] const char* getLogText(int i) const; protected: void doResetLog() override; @@ -54,25 +53,25 @@ protected: void doResetTimers() override; void doStartTimer(rcTimerLabel label) override; void doStopTimer(rcTimerLabel label) override; - int doGetAccumulatedTime(rcTimerLabel label) const override; + [[nodiscard]] int doGetAccumulatedTime(rcTimerLabel label) const override; }; /// OpenGL debug draw implementation. class DebugDrawGL : public duDebugDraw { public: - virtual void depthMask(bool state); - virtual void texture(bool state); - virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f); - virtual void vertex(const float* pos, unsigned int color); - virtual void vertex(const float* pos, unsigned int color, const float* uv); - virtual void vertex(float x, float y, float z, unsigned int color); - virtual void vertex(float x, float y, float z, unsigned int color, float u, float v); - virtual void end(); + void depthMask(bool state) override; + void texture(bool state) override; + void begin(duDebugDrawPrimitives prim, float size = 1.0f) override; + void vertex(const float* pos, unsigned int color) override; + void vertex(const float* pos, unsigned int color, const float* uv) override; + void vertex(float x, float y, float z, unsigned int color) override; + void vertex(float x, float y, float z, unsigned int color, float u, float v) override; + void end() override; }; /// stdio file implementation. -class FileIO : public duFileIO +class FileIO final : public duFileIO { public: FileIO() = default; @@ -80,15 +79,15 @@ public: FileIO& operator=(const FileIO&) = delete; FileIO(FileIO&&) = default; FileIO& operator=(FileIO&&) = default; - virtual ~FileIO(); + ~FileIO() override; bool openForWrite(const char* path); bool openForRead(const char* path); - virtual bool isWriting() const; - virtual bool isReading() const; - virtual bool write(const void* ptr, const size_t size); - virtual bool read(void* ptr, const size_t size); - size_t getFileSize(); + [[nodiscard]] bool isWriting() const override; + [[nodiscard]] bool isReading() const override; + bool write(const void* ptr, size_t size) override; + bool read(void* ptr, size_t size) override; + size_t getFileSize() const; static void scanDirectory(const std::string& path, const std::string& ext, std::vector& fileList); private: diff --git a/RecastDemo/Source/InputGeom.cpp b/RecastDemo/Source/InputGeom.cpp index 207b1c5c..5a23961c 100644 --- a/RecastDemo/Source/InputGeom.cpp +++ b/RecastDemo/Source/InputGeom.cpp @@ -20,7 +20,6 @@ #include "ChunkyTriMesh.h" #include "DebugDraw.h" -#include "Filelist.h" #include "MeshLoaderObj.h" #include "Recast.h" #include "Sample.h" @@ -32,7 +31,9 @@ #include -static bool intersectSegmentTriangle(const float* sp, const float* sq, const float* a, const float* b, const float* c, float& t) +namespace +{ +bool intersectSegmentTriangle(const float* sp, const float* sq, const float* a, const float* b, const float* c, float& t) { float v; float w; @@ -92,7 +93,7 @@ static bool intersectSegmentTriangle(const float* sp, const float* sq, const flo return true; } -static char* parseRow(char* buf, char* bufEnd, char* row, int len) +char* parseRow(char* buf, char* bufEnd, char* row, int len) { bool start = true; bool done = false; @@ -133,6 +134,12 @@ static char* parseRow(char* buf, char* bufEnd, char* row, int len) row[n] = '\0'; return buf; } +} + +InputGeom::~InputGeom() +{ + delete chunkyMesh; +} bool InputGeom::loadMesh(rcContext* ctx, const std::string& filepath) { @@ -563,7 +570,7 @@ void InputGeom::deleteOffMeshConnection(int i) offMeshConFlags[i] = offMeshConFlags[offMeshConCount]; } -void InputGeom::drawOffMeshConnections(duDebugDraw* dd, bool hilight) +void InputGeom::drawOffMeshConnections(duDebugDraw* dd, bool highlight) { unsigned int conColor = duRGBA(192, 0, 128, 192); unsigned int baseColor = duRGBA(0, 0, 0, 64); @@ -583,7 +590,7 @@ void InputGeom::drawOffMeshConnections(duDebugDraw* dd, bool hilight) duAppendCircle(dd, v[0], v[1] + 0.1f, v[2], offMeshConRads[i], baseColor); duAppendCircle(dd, v[3], v[4] + 0.1f, v[5], offMeshConRads[i], baseColor); - if (hilight) + if (highlight) { duAppendArc(dd, v[0], v[1], v[2], v[3], v[4], v[5], 0.25f, (offMeshConDirs[i] & 1) ? 0.6f : 0.0f, 0.6f, conColor); } diff --git a/RecastDemo/Source/PerfTimer.cpp b/RecastDemo/Source/PerfTimer.cpp index 1a932610..5c77294e 100644 --- a/RecastDemo/Source/PerfTimer.cpp +++ b/RecastDemo/Source/PerfTimer.cpp @@ -27,8 +27,8 @@ TimeVal getPerfTime() { #ifdef WIN32 - __int64 count; - QueryPerformanceCounter((LARGE_INTEGER*)&count); + int64_t count; + QueryPerformanceCounter(reinterpret_cast(&count)); return count; #else timeval now; @@ -40,13 +40,14 @@ TimeVal getPerfTime() int getPerfTimeUsec(const TimeVal duration) { #ifdef WIN32 - static __int64 freq = 0; + static int64_t freq = 0; if (freq == 0) { - QueryPerformanceFrequency((LARGE_INTEGER*)&freq); + QueryPerformanceFrequency(reinterpret_cast(&freq)); } - return (int)(duration * 1000000 / freq); + return static_cast(duration * 1000000 / freq); #else - return (int)duration; + return static_cast(duration); #endif } + diff --git a/RecastDemo/Source/Sample.cpp b/RecastDemo/Source/Sample.cpp index 03c20a0e..c6da554f 100644 --- a/RecastDemo/Source/Sample.cpp +++ b/RecastDemo/Source/Sample.cpp @@ -25,25 +25,35 @@ #include "InputGeom.h" #include "Recast.h" #include "RecastDebugDraw.h" -#include "SDL.h" -#include "SDL_opengl.h" #include -#include -#include + +#include #ifdef WIN32 # define snprintf _snprintf #endif -SampleTool::~SampleTool() +namespace { - // Defined out of line to fix the weak v-tables warning -} -SampleToolState::~SampleToolState() +constexpr int NAVMESHSET_MAGIC = 'M' << 24 | 'S' << 16 | 'E' << 8 | 'T'; //'MSET'; +constexpr int NAVMESHSET_VERSION = 1; + +struct NavMeshSetHeader { - // Defined out of line to fix the weak v-tables warning + int magic; + int version; + int numTiles; + dtNavMeshParams params; +}; + +struct NavMeshTileHeader +{ + dtTileRef tileRef; + int dataSize; +}; + } unsigned int SampleDebugDraw::areaToCol(unsigned int area) @@ -79,11 +89,6 @@ Sample::Sample() : navMeshDrawFlags(DU_DRAWNAVMESH_OFFMESHCONS | DU_DRAWNAVMESH_ resetCommonSettings(); navQuery = dtAllocNavMeshQuery(); crowd = dtAllocCrowd(); - - for (int i = 0; i < static_cast(SampleToolType::MAX_TOOLS); i++) - { - toolStates[i] = 0; - } } Sample::~Sample() @@ -132,9 +137,9 @@ void Sample::handleRender() 0, 1.0f); // Draw bounds - const float* bmin = inputGeometry->getMeshBoundsMin(); - const float* bmax = inputGeometry->getMeshBoundsMax(); - duDebugDrawBoxWire(&debugDraw, bmin[0], bmin[1], bmin[2], bmax[0], bmax[1], bmax[2], duRGBA(255, 255, 255, 128), 1.0f); + const float* min = inputGeometry->getMeshBoundsMin(); + const float* max = inputGeometry->getMeshBoundsMax(); + duDebugDrawBoxWire(&debugDraw, min[0], min[1], min[2], max[0], max[1], max[2], duRGBA(255, 255, 255, 128), 1.0f); } void Sample::handleRenderOverlay(double* /*proj*/, double* /*model*/, int* /*view*/) {} @@ -294,7 +299,7 @@ void Sample::handleUpdate(const float dt) updateToolStates(dt); } -void Sample::updateToolStates(const float dt) +void Sample::updateToolStates(const float dt) const { for (int i = 0; i < static_cast(SampleToolType::MAX_TOOLS); i++) { @@ -305,7 +310,7 @@ void Sample::updateToolStates(const float dt) } } -void Sample::initToolStates(Sample* sample) +void Sample::initToolStates(Sample* sample) const { for (int i = 0; i < static_cast(SampleToolType::MAX_TOOLS); i++) { @@ -316,7 +321,7 @@ void Sample::initToolStates(Sample* sample) } } -void Sample::resetToolStates() +void Sample::resetToolStates() const { for (int i = 0; i < static_cast(SampleToolType::MAX_TOOLS); i++) { @@ -327,7 +332,7 @@ void Sample::resetToolStates() } } -void Sample::renderToolStates() +void Sample::renderToolStates() const { for (int i = 0; i < static_cast(SampleToolType::MAX_TOOLS); i++) { @@ -338,7 +343,7 @@ void Sample::renderToolStates() } } -void Sample::renderOverlayToolStates(double* proj, double* model, int* view) +void Sample::renderOverlayToolStates(double* proj, double* model, int* view) const { for (int i = 0; i < static_cast(SampleToolType::MAX_TOOLS); i++) { @@ -349,23 +354,6 @@ void Sample::renderOverlayToolStates(double* proj, double* model, int* view) } } -static const int NAVMESHSET_MAGIC = 'M' << 24 | 'S' << 16 | 'E' << 8 | 'T'; //'MSET'; -static const int NAVMESHSET_VERSION = 1; - -struct NavMeshSetHeader -{ - int magic; - int version; - int numTiles; - dtNavMeshParams params; -}; - -struct NavMeshTileHeader -{ - dtTileRef tileRef; - int dataSize; -}; - dtNavMesh* Sample::loadAll(const char* path) { FILE* fp = fopen(path, "rb"); diff --git a/RecastDemo/Source/SampleInterfaces.cpp b/RecastDemo/Source/SampleInterfaces.cpp index 3738bd53..a3342d1f 100644 --- a/RecastDemo/Source/SampleInterfaces.cpp +++ b/RecastDemo/Source/SampleInterfaces.cpp @@ -326,26 +326,26 @@ bool FileIO::read(void* ptr, const size_t size) return readLen == 1; } -size_t FileIO::getFileSize() +size_t FileIO::getFileSize() const { if (!fp || mode != Mode::reading) { return false; } - size_t currentPos = ftell(fp); + const size_t currentPos = ftell(fp); if (fseek(fp, 0, SEEK_END) != 0) { return 0; } - size_t size = ftell(fp); - if (fseek(fp, 0, currentPos) != 0) + const size_t size = ftell(fp); + if (fseek(fp, 0, static_cast(currentPos)) != 0) { return 0; } return size; } -void FileIO::scanDirectory(const std::string& path, const std::string& ext, std::vector& filelist) +void FileIO::scanDirectory(const std::string& path, const std::string& ext, std::vector& fileList) { #ifdef WIN32 std::string pathWithExt = path + "/*" + ext; @@ -359,7 +359,7 @@ void FileIO::scanDirectory(const std::string& path, const std::string& ext, std: do { - filelist.emplace_back(dir.name); + fileList.emplace_back(dir.name); } while (_findnext(findHandle, &dir) == 0); _findclose(findHandle); #else @@ -383,5 +383,5 @@ void FileIO::scanDirectory(const std::string& path, const std::string& ext, std: #endif // Sort the list of files alphabetically. - std::sort(filelist.begin(), filelist.end()); + std::sort(fileList.begin(), fileList.end()); } diff --git a/RecastDemo/Source/Sample_TempObstacles.cpp b/RecastDemo/Source/Sample_TempObstacles.cpp index 9d03f0f3..13762589 100644 --- a/RecastDemo/Source/Sample_TempObstacles.cpp +++ b/RecastDemo/Source/Sample_TempObstacles.cpp @@ -27,6 +27,7 @@ #else # include #endif +#include "ChunkyTriMesh.h" #include "ConvexVolumeTool.h" #include "CrowdTool.h" #include "DetourAssert.h" diff --git a/RecastDemo/Source/Sample_TileMesh.cpp b/RecastDemo/Source/Sample_TileMesh.cpp index e3b15cbf..007540ef 100644 --- a/RecastDemo/Source/Sample_TileMesh.cpp +++ b/RecastDemo/Source/Sample_TileMesh.cpp @@ -30,6 +30,7 @@ # include #endif +#include "ChunkyTriMesh.h" #include "ConvexVolumeTool.h" #include "CrowdTool.h" #include "DetourDebugDraw.h" diff --git a/RecastDemo/Source/main.cpp b/RecastDemo/Source/main.cpp index f8254e96..f728e617 100644 --- a/RecastDemo/Source/main.cpp +++ b/RecastDemo/Source/main.cpp @@ -20,6 +20,7 @@ #include "SDL_keycode.h" #include "SDL_opengl.h" +#include #include #include #include @@ -30,7 +31,6 @@ # include #endif -#include "Filelist.h" #include "InputGeom.h" #include "Recast.h" #include "Sample_SoloMesh.h" @@ -55,14 +55,19 @@ struct SampleItem string name; std::function create; }; -static SampleItem g_samples[] = { + +namespace +{ +SampleItem g_samples[] = { {"Solo Mesh", []() { return new Sample_SoloMesh(); } }, {"Tile Mesh", []() { return new Sample_TileMesh(); } }, {"Temp Obstacles", []() { return new Sample_TempObstacles(); }}, }; -static constexpr int g_nsamples = sizeof(g_samples) / sizeof(SampleItem); +constexpr int g_nsamples = sizeof(g_samples) / sizeof(SampleItem); -static constexpr float fogColor[4] = {0.32f, 0.31f, 0.30f, 1.0f}; +constexpr float fogColor[4] = {0.32f, 0.31f, 0.30f, 1.0f}; + +} struct AppData { @@ -134,6 +139,14 @@ struct AppData float markerPosition[3] = {0, 0, 0}; bool markerPositionSet = false; + ~AppData() + { + delete sample; + sample = nullptr; + delete inputGeometry; + inputGeometry = nullptr; + } + void resetCamera() { const float* bmin = 0; @@ -162,6 +175,7 @@ struct AppData int main(int /*argc*/, char** /*argv*/) { AppData app; + // Init SDL if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { @@ -505,10 +519,7 @@ int main(int /*argc*/, char** /*argv*/) if (dt < MIN_FRAME_TIME) { int ms = static_cast((MIN_FRAME_TIME - dt) * 1000.0f); - if (ms > 10) - { - ms = 10; - } + ms = std::min(ms, 10); if (ms >= 0) { SDL_Delay(ms); @@ -588,17 +599,17 @@ int main(int /*argc*/, char** /*argv*/) keybSpeed *= 4.0f; } - float movex = (app.moveRight - app.moveLeft) * keybSpeed * dt; - float movey = (app.moveBack - app.moveFront) * keybSpeed * dt + app.scrollZoom * 2.0f; + float moveX = (app.moveRight - app.moveLeft) * keybSpeed * dt; + float moveY = (app.moveBack - app.moveFront) * keybSpeed * dt + app.scrollZoom * 2.0f; app.scrollZoom = 0; - app.cameraPos[0] += movex * static_cast(modelviewMatrix[0]); - app.cameraPos[1] += movex * static_cast(modelviewMatrix[4]); - app.cameraPos[2] += movex * static_cast(modelviewMatrix[8]); + app.cameraPos[0] += moveX * static_cast(modelviewMatrix[0]); + app.cameraPos[1] += moveX * static_cast(modelviewMatrix[4]); + app.cameraPos[2] += moveX * static_cast(modelviewMatrix[8]); - app.cameraPos[0] += movey * static_cast(modelviewMatrix[2]); - app.cameraPos[1] += movey * static_cast(modelviewMatrix[6]); - app.cameraPos[2] += movey * static_cast(modelviewMatrix[10]); + app.cameraPos[0] += moveY * static_cast(modelviewMatrix[2]); + app.cameraPos[1] += moveY * static_cast(modelviewMatrix[6]); + app.cameraPos[2] += moveY * static_cast(modelviewMatrix[10]); app.cameraPos[1] += (app.moveUp - app.moveDown) * keybSpeed * dt; @@ -959,13 +970,13 @@ int main(int /*argc*/, char** /*argv*/) glLineWidth(5.0f); glColor4ub(240, 220, 0, 196); glBegin(GL_LINE_LOOP); - const float r = 25.0f; for (int i = 0; i < 20; ++i) { - const float a = static_cast(i) / 20.0f * RC_PI * 2; - const float fx = static_cast(x) + cosf(a) * r; - const float fy = static_cast(y) + sinf(a) * r; - glVertex2f(fx, fy); + constexpr float radius = 25.0f; + const float arc = static_cast(i) / 20.0f * RC_PI * 2; + const float vertexX = static_cast(x) + cosf(arc) * radius; + const float vertexY = static_cast(y) + sinf(arc) * radius; + glVertex2f(vertexX, vertexY); } glEnd(); glLineWidth(1.0f); @@ -986,8 +997,5 @@ int main(int /*argc*/, char** /*argv*/) SDL_DestroyWindow(app.window); SDL_Quit(); - delete app.sample; - delete app.inputGeometry; - return 0; }