0

My current working code:

void GraphicFunctions::drawECM(const OpenGLCamera& camera)
{
   gl->drawECMEdges(camera, ecm, layerID);
}

OpenGL class:

void OpenGL::draw(const OpenGLCamera& camera)
{
   const vector<double>& cameraBBox = camera.getBoundingBox();
}

Is it possible to make "OpenGLCamera" more general, make it into a pointer or something? For example something like this:

void GraphicFunctions::drawECM(const OpenGLCamera& camera)
{
   const int* camerapointer = camera;
   gl->drawECMEdges(camerapointer, ecm, layerID);
}

OpenGL class:

void OpenGL::draw(const int& camera)
{
   const vector<double>& cameraBBox = camera->getBoundingBox();
}

This way i will be able to use other camera types as well...!

  • 1
    erm, *inheritance* - have you not heard about this concept? – Nim Mar 26 '13 at 11:46
  • Read about inheritance and virtual member functions. – Some programmer dude Mar 26 '13 at 11:47
  • please read topics on inheritance and polymorphism with a focus on c++ (ie http://www.cplusplus.com/doc/tutorial/inheritance/ and http://www.cplusplus.com/doc/tutorial/polymorphism/ ) – scones Mar 26 '13 at 11:50
  • Don't pay too much attention to cplusplus.com - it's not very good. [The "canonical" SO C++ Book & Guide List](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) has plenty of good things. – molbdnilo Mar 26 '13 at 12:58
  • but how can i put inheritance into a function, i mean, into variables i know how to do it... but how to chance it so that a function is "typeless" or "changeable"?? – Sebastiaan van Dorst Mar 26 '13 at 13:23

1 Answers1

0

Just use inheritance to add different camera types. This will also work if you pass them by reference

struct Camera1 : public OpenGLCamera
{
  // reimplement something
}
struct Camera2 : public OpenGLCamera
{
}

now you can pass them to OpenGL::draw(const OpenGLCamera& camera)

spiritwolfform
  • 2,263
  • 15
  • 16
  • but how can i put inheritance into a function, i mean, into variables i know how to do it... but how to chance it so that a function is "typeless" or "changeable"?? – Sebastiaan van Dorst Mar 26 '13 at 13:04
  • No you don't do that. You should really read something from the stuff suggested in the comments – spiritwolfform Mar 26 '13 at 13:28
  • But this way i still need another function/method for another type of camera... right? Since i want to use multiple types of cameras...! OpenGLCamera, UnityCamera, Direct3DCamera (all different types..) so then OpenGL::draw(const SomeTypeOfCamera& camera) wont work... This way i can only use OpenGLCameras or do i see that wrong? – Sebastiaan van Dorst Mar 27 '13 at 10:08
  • you define which methods are common for every camera you use. Then have a base class for those. Then reimplement them for each derived class you have – spiritwolfform Mar 27 '13 at 10:30