# Camera Class Design

This topic is 4527 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everyone, It occurs to me that this is probably something that people don't really worry about and will just write it one way and "who cares" :) But, here is the question: I currently have a Scene class, that has a group of cameras stored in it... when rendering this scene, should I do something like this: Scene::draw(){ camera->applyOffset(); drawObjects(); } OR, should I do this: Scene::draw(){ camera->render(this); } camera::render(Scene *scene){ applyOffset(); scene->drawObjects(); } It occurs to me that in the second version I get the ability to subclass the camera and potentially do wierd things with the subclassed camera.. ie. Different transitions between camera positions etc. Any comments from the community on this? Recon the extra de-referencing is going to cause much of a performance difference? Am I free to choose without many caveats to worry about? Thanks all --Josh

##### Share on other sites
My framework is supposed to drive an engine as well as an editor, so I have to deal with multiple views. Since a view's visual scene cut is defined by a camera's geometry, several views may (but need not) mean several cameras. Hence I've chosen the 2nd approach with the exception that not the camera but the view is starting rendering.

IMHO this approach is also senseful in games when e.g. rear view mirrors are to be implemented (also a kind of multiple view paradigm :)

##### Share on other sites
I'd go that way:
void scene::render( CCamera* pCamera ){   pCamera->set();  //Matrices...   drawObjects();}

(Well you would want to also generate Camera Frustum and compute visible set in that function, prior to setting and drawing.)

##### Share on other sites
Well, a comparision of the 2:

Scene::draw(){camera->applyOffset();drawObjects();}

This would imply that the camera applys a transformation (the "offset").

Scene::draw(){camera->render(this);}camera::render(Scene *scene){applyOffset();scene->drawObjects();}

This would imply that the camera has intimate knowledge about how to draw an object.

Personally I like to keep objects as discrete as possible, so the question you should be asking is, should a camera look like it knows how to draw something or should the scene. To me it would make logical sense that the scene should so I would go with the first method. If you did this than the camera would just serve as a seperate container for the scenes view information and I think that makes more sense.

As an alternative though Ingenu's way seems a lot more robust so I would consider that over the other two methods if I had to choose for myself.

##### Share on other sites
Personally my renderer class has a pointer to the current camera, which can be set at will, I just call for instance:

pRootNodeOfSceneGraph->Draw(pRenderer);

Job done :-)

1. 1
2. 2
JoeJ
20
3. 3
frob
20
4. 4
5. 5

• 10
• 11
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632210
• Total Posts
3004817

×