Skip to main content
gamedev.net
🔒 Locked

Camera Class Design

Started by JoshG 3 replies 800+ views
Original Post
JoshG
JoshG
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
haegarr
haegarr
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 :)
Ingenu
Ingenu
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.)
-* So many things to do, so little time to spend. *-
Dirge
Dirge
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.
"Artificial Intelligence: the art of making computers that behave like the ones in movies."www.CodeFortress.com
noNchaoTic
noNchaoTic
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 :-)
Steven ToveySPUify | Twitter

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.