implement singleton pattern

This commit is contained in:
Anakin 2016-09-07 12:46:34 +02:00
parent e7d7bec608
commit f824f4eb4c
3 changed files with 29 additions and 26 deletions

View File

@ -8,10 +8,13 @@
class OpenGLController
{
public:
OpenGLController();
OpenGLController(int oglMajor, int oglMinor);
static OpenGLController& getInstance(int oglMajor = 4, int oglMinor = 5);
~OpenGLController();
private:
OpenGLController() {};
OpenGLController(int oglMajor, int oglMinor);
private:
int iOglMajorVersion;
int iOglMinorVersion;
@ -30,7 +33,7 @@ private:
glm::mat4 m4x4Model;
glm::mat4 m4x4MVP;
Camera camera;
Camera* camera;
Object* object;
struct {

View File

@ -8,24 +8,10 @@
/////////////////////////////////////////////////////////////////////////
// public constructor/destructor
OpenGLController::OpenGLController() :
iWidth(640),
iHeight(480),
camera(iWidth, iHeight)
OpenGLController& OpenGLController::getInstance(int oglMajor, int oglMinor)
{
initDefault();
processInit();
}
OpenGLController::OpenGLController(int oglMajor, int oglMinor) :
iWidth(640),
iHeight(480),
camera(iWidth, iHeight)
{
initDefault();
iOglMajorVersion = oglMajor;
iOglMinorVersion = oglMinor;
processInit();
static OpenGLController instace(oglMajor, oglMinor);
return instace;
}
OpenGLController::~OpenGLController()
@ -35,6 +21,20 @@ OpenGLController::~OpenGLController()
}
/////////////////////////////////////////////////////////////////////////
// private constructor
OpenGLController::OpenGLController(int oglMajor, int oglMinor) :
iWidth(640),
iHeight(480)
{
camera = new Camera(iWidth, iHeight);
initDefault();
iOglMajorVersion = oglMajor;
iOglMinorVersion = oglMinor;
processInit();
}
/////////////////////////////////////////////////////////////////////////
// private functions
@ -141,7 +141,7 @@ void OpenGLController::setCallbackFunctions()
glm::mat4 OpenGLController::getMVPMatrix()
{
return camera.getMatrix() * object->getMatrix();
return camera->getMatrix() * object->getMatrix();
}
GLFWwindow * OpenGLController::getWindow() const
@ -155,7 +155,7 @@ GLFWwindow * OpenGLController::getWindow() const
void OpenGLController::resize(int width, int height)
{
camera.setSize(width, height);
camera->setSize(width, height);
}
void OpenGLController::addRotX(float value)
@ -170,17 +170,17 @@ void OpenGLController::addRotY(float value)
void OpenGLController::addTransX(double value)
{
camera.add2x(value);
camera->add2x(value);
}
void OpenGLController::addTransY(double value)
{
camera.add2y(value);
camera->add2y(value);
}
void OpenGLController::addTransZ(double value)
{
camera.add2z(value);
camera->add2z(value);
}
void OpenGLController::updateScene()

View File

@ -6,7 +6,7 @@
int main(int argc, char** argv)
{
OpenGLController scene;
OpenGLController scene = OpenGLController::getInstance();
do {