From e2f15d92443f3209f6650389d3908f8c65484bed Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 28 Jun 2009 16:26:44 +0100 Subject: [PATCH] Get rid of OpenGLGraphics helper class --- include/OpenGLHelper.hpp | 18 ------------- src/FLTKWindow.cpp | 56 +++++++++++++++++++++++++++++++++++++++- src/OpenGLHelper.cpp | 52 ------------------------------------- src/SDLWindow.cpp | 55 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 109 insertions(+), 72 deletions(-) diff --git a/include/OpenGLHelper.hpp b/include/OpenGLHelper.hpp index 89d957a..4187cf2 100644 --- a/include/OpenGLHelper.hpp +++ b/include/OpenGLHelper.hpp @@ -35,22 +35,4 @@ unsigned endPick(unsigned* aBuffer); const float NEAR_CLIP = 0.1f; const float FAR_CLIP = 70.0f; -// Standard implementation of IGraphics -class OpenGLGraphics : public IGraphics { -public: - OpenGLGraphics(); - ~OpenGLGraphics(); - - bool cuboidInViewFrustum(float x, float y, float z, - float sizeX, float sizeY, float sizeZ); - bool cubeInViewFrustum(float x, float y, float z, float size); - bool pointInViewFrustum(float x, float y, float z); - void setCamera(const Vector& aPos, - const Vector& aRotation); - void lookAt(const Vector anEyePoint, - const Vector aTargetPoint); -private: - Frustum myViewFrustum; -}; - #endif diff --git a/src/FLTKWindow.cpp b/src/FLTKWindow.cpp index 7f66b80..80a1cb9 100644 --- a/src/FLTKWindow.cpp +++ b/src/FLTKWindow.cpp @@ -24,9 +24,10 @@ #include #include #include +#include // An OpenGL window that supports FLTK widgets for the editor -class FLTKWindow : public IWindow, public OpenGLGraphics, +class FLTKWindow : public IWindow, public IGraphics, public Fl_Gl_Window, public IPickBuffer, public enable_shared_from_this { public: @@ -41,6 +42,16 @@ public: int width() const; int height() const; + // IGraphics interface + bool cuboidInViewFrustum(float x, float y, float z, + float sizeX, float sizeY, float sizeZ); + bool cubeInViewFrustum(float x, float y, float z, float size); + bool pointInViewFrustum(float x, float y, float z); + void setCamera(const Vector& aPos, + const Vector& aRotation); + void lookAt(const Vector anEyePoint, + const Vector aTargetPoint); + // Fl_Gl_Window interface void draw(); int handle(int anEvent); @@ -52,6 +63,7 @@ private: void checkValid(); IScreenPtr myScreen; + Frustum myViewFrustum; // Picking data static const int SELECT_BUFFER_SZ = 128; @@ -189,6 +201,48 @@ unsigned FLTKWindow::endPick() return ::endPick(mySelectBuffer); } +// Called to set the camera position +void FLTKWindow::setCamera(const Vector& aPos, + const Vector& aRotation) +{ + glRotatef(aRotation.x, 1.0f, 0.0f, 0.0f); + glRotatef(aRotation.y, 0.0f, 1.0f, 0.0f); + glRotatef(aRotation.z, 0.0f, 0.0f, 1.0f); + glTranslatef(aPos.x, aPos.y, aPos.z); + + myViewFrustum = getViewFrustum(); +} + +// A wrapper around gluLookAt +void FLTKWindow::lookAt(const Vector anEyePoint, + const Vector aTargetPoint) +{ + gluLookAt(anEyePoint.x, anEyePoint.y, anEyePoint.z, + aTargetPoint.x, aTargetPoint.y, aTargetPoint.z, + 0, 1, 0); + + myViewFrustum = getViewFrustum(); +} + +// Intersect a cuboid with the current view frustum +bool FLTKWindow::cuboidInViewFrustum(float x, float y, float z, + float sizeX, float sizeY, float sizeZ) +{ + return myViewFrustum.cuboidInFrustum(x, y, z, sizeX, sizeY, sizeZ); +} + +// Intersect a cube with the current view frustum +bool FLTKWindow::cubeInViewFrustum(float x, float y, float z, float size) +{ + return myViewFrustum.cubeInFrustum(x, y, z, size); +} + +// True if the point is contained within the view frustum +bool FLTKWindow::pointInViewFrustum(float x, float y, float z) +{ + return myViewFrustum.pointInFrustum(x, y, z); +} + IWindowPtr makeFLTKWindow() { return IWindowPtr(new FLTKWindow); diff --git a/src/OpenGLHelper.cpp b/src/OpenGLHelper.cpp index c3fdbfc..38d163a 100644 --- a/src/OpenGLHelper.cpp +++ b/src/OpenGLHelper.cpp @@ -172,55 +172,3 @@ unsigned endPick(unsigned* aBuffer) else return 0; } - -// Called to set the camera position -void OpenGLGraphics::setCamera(const Vector& aPos, - const Vector& aRotation) -{ - glRotatef(aRotation.x, 1.0f, 0.0f, 0.0f); - glRotatef(aRotation.y, 0.0f, 1.0f, 0.0f); - glRotatef(aRotation.z, 0.0f, 0.0f, 1.0f); - glTranslatef(aPos.x, aPos.y, aPos.z); - - myViewFrustum = getViewFrustum(); -} - -OpenGLGraphics::OpenGLGraphics() -{ - -} - -OpenGLGraphics::~OpenGLGraphics() -{ - -} - -// A wrapper around gluLookAt -void OpenGLGraphics::lookAt(const Vector anEyePoint, - const Vector aTargetPoint) -{ - gluLookAt(anEyePoint.x, anEyePoint.y, anEyePoint.z, - aTargetPoint.x, aTargetPoint.y, aTargetPoint.z, - 0, 1, 0); - - myViewFrustum = getViewFrustum(); -} - -// Intersect a cuboid with the current view frustum -bool OpenGLGraphics::cuboidInViewFrustum(float x, float y, float z, - float sizeX, float sizeY, float sizeZ) -{ - return myViewFrustum.cuboidInFrustum(x, y, z, sizeX, sizeY, sizeZ); -} - -// Intersect a cube with the current view frustum -bool OpenGLGraphics::cubeInViewFrustum(float x, float y, float z, float size) -{ - return myViewFrustum.cubeInFrustum(x, y, z, size); -} - -// True if the point is contained within the view frustum -bool OpenGLGraphics::pointInViewFrustum(float x, float y, float z) -{ - return myViewFrustum.pointInFrustum(x, y, z); -} diff --git a/src/SDLWindow.cpp b/src/SDLWindow.cpp index 7eefc21..b935e0e 100644 --- a/src/SDLWindow.cpp +++ b/src/SDLWindow.cpp @@ -34,7 +34,7 @@ using namespace boost; // Concrete implementation of SDL window -class SDLWindow : public IWindow, public OpenGLGraphics, public IPickBuffer, +class SDLWindow : public IWindow, public IGraphics, public IPickBuffer, public enable_shared_from_this { public: SDLWindow(); @@ -48,6 +48,16 @@ public: int width() const { return myWidth; } int height() const { return myHeight; } + // IGraphics interface + bool cuboidInViewFrustum(float x, float y, float z, + float sizeX, float sizeY, float sizeZ); + bool cubeInViewFrustum(float x, float y, float z, float size); + bool pointInViewFrustum(float x, float y, float z); + void setCamera(const Vector& aPos, + const Vector& aRotation); + void lookAt(const Vector anEyePoint, + const Vector aTargetPoint); + // IPickBuffer interface IGraphicsPtr beginPick(int x, int y); unsigned endPick(); @@ -61,6 +71,7 @@ private: IScreenPtr myScreen; bool willSkipNextFrame; bool willTakeScreenShot; + Frustum myViewFrustum; // Picking data static const int SELECT_BUFFER_SZ = 128; @@ -318,6 +329,48 @@ unsigned SDLWindow::endPick() return ::endPick(mySelectBuffer); } +// Called to set the camera position +void SDLWindow::setCamera(const Vector& aPos, + const Vector& aRotation) +{ + glRotatef(aRotation.x, 1.0f, 0.0f, 0.0f); + glRotatef(aRotation.y, 0.0f, 1.0f, 0.0f); + glRotatef(aRotation.z, 0.0f, 0.0f, 1.0f); + glTranslatef(aPos.x, aPos.y, aPos.z); + + myViewFrustum = getViewFrustum(); +} + +// A wrapper around gluLookAt +void SDLWindow::lookAt(const Vector anEyePoint, + const Vector aTargetPoint) +{ + gluLookAt(anEyePoint.x, anEyePoint.y, anEyePoint.z, + aTargetPoint.x, aTargetPoint.y, aTargetPoint.z, + 0, 1, 0); + + myViewFrustum = getViewFrustum(); +} + +// Intersect a cuboid with the current view frustum +bool SDLWindow::cuboidInViewFrustum(float x, float y, float z, + float sizeX, float sizeY, float sizeZ) +{ + return myViewFrustum.cuboidInFrustum(x, y, z, sizeX, sizeY, sizeZ); +} + +// Intersect a cube with the current view frustum +bool SDLWindow::cubeInViewFrustum(float x, float y, float z, float size) +{ + return myViewFrustum.cubeInFrustum(x, y, z, size); +} + +// True if the point is contained within the view frustum +bool SDLWindow::pointInViewFrustum(float x, float y, float z) +{ + return myViewFrustum.pointInFrustum(x, y, z); +} + // Capture the OpenGL pixels and save them to a file void SDLWindow::captureFrame() const { -- 2.39.2