Camera system structure

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
User avatar
abstractcoder
Gnome
Posts: 336
Joined: Wed Oct 12, 2005 1:50 pm
Location: UK
Contact:

Camera system structure

Post by abstractcoder »

I have now finished uni and I have the time to sort out the camera system that I have created and release the source to see if anyone will actually fine it useful.

Before I do this though I need to clean it up and change a few things around. One thing that I am a bit unsure as how to do is the class or classes that provide access to the system.

First I think I should describe how I did have it. I have a camera manager class and a viewport manager class. Each one is responsible for creating and running the cameras and viewports. Now originally I had created these two as separate singleton classes and to use the system would require creating and calling the update for each class.

To cut this down slightly I have since added a third singleton class and made the other two normal classes that are inherited by the third class that acts as a single access point to running the system. Now what I would like to know is if you view this to be of any use or if it would be easier to just have the separate camera and viewport managers?

I also find it very hard to pick a name for such things, at the moment I have prefixed all my classes with "ac". This currently has no real meaning; it could be something camera or it could be used as the initials of my website (abstractcoder). So current i have acCameraManager, acViewportManager and acSystem as the third class. But this is only a minor issue. If anyone has a better idea I am happy to hear it.

Thank for reading all my rambling on about this. I thought I might as well put this up on the forum and see if I could get some other opinions on the matter.

Thanks in advance.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

Generally, prefixing classes is not a good idea (IMO).
Just call them what they are, and put them in a namespace.
Then they become:
ac::CameraManager, ac::ViewportManager and ac::System.

System could probably be called CameraSystem?

If those managers are to be used only by the CameraSystem, you could make CameraSystem a friend of both, and hide the manager implementation.

Looking forward to seeing your camera code! :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
goldsword
Gnoblar
Posts: 22
Joined: Mon Apr 03, 2006 4:12 pm

Post by goldsword »

Hi, I believe your systems sounds a little bit to complex (ofcourse this is only my own believes) Having 3 classes to simply control the camera and the viewport.

Id prefer if you had a single class that managed everything about your camera and the actual camera is used to control the camera. Also the viewport could easily be embedded into the camera class or the manager of the camera class.

I wouldnt prefix anything either, simply put them in their own namespace.
User avatar
abstractcoder
Gnome
Posts: 336
Joined: Wed Oct 12, 2005 1:50 pm
Location: UK
Contact:

Post by abstractcoder »

jacmoe,

i had tried a namespace at the start of the project but i had problems when trying to subclass the ogre Camera. but i think you are right and i should get it working. as for using friend i know a little about the friend operator but not a lot. i will have to look into it.

goldsword,

this is possibly too much for what you want, there are in total quite a few classes, i have four camera classes along with a class for the viewport and a camera transition (for moving between two cameras). but i have done this so it is not all in one class as it would end up really large. there are a couple of things that i now realise is a really bad way of designing it and i can redo some of it to reduce the complexity a bit.

Thanks for the advise.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

goldsword wrote:Hi, I believe your systems sounds a little bit to complex (ofcourse this is only my own believes) Having 3 classes to simply control the camera and the viewport.
abstractcoder is not merely creating a simple camera handling system. It is a lot more than that. :wink:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Praetor
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3335
Joined: Tue Jun 21, 2005 8:26 pm
Location: Rochester, New York, US
x 3
Contact:

Post by Praetor »

When coding libraries I always use namespaces. Your trouble with Ogre could just be mixups. Try this: never use a "using namespace Ogre" when working with Ogre in a library. Instead prefix every ogre class with Ogre::. It tends to create easier-to-read library code since people know what is a class from one lib, and what is from another.

I'm against embedding Viewport into Camera because that would break some important conceptual boundaries. It might be "handy" but remember clean code pays off in the long run. A viewport is something having to do with rendering itself. It is part of a windowing and display system. A camera is a member of a scene, representing a physical object (eye, an actual camera, etc.) that exists in the virtual world. I wouldn't mix the two.
User avatar
Frenetic
Bugbear
Posts: 806
Joined: Fri Feb 03, 2006 7:08 am

Post by Frenetic »

I agree with Praetor.

The Camera class obviously represents a camera. Viewport is sort of like the "film" and the "frame". A lot of 3D terms are based off of cinematic-type semantics to help humans easily think about the concepts. It is important to maintain these concepts lest the software lose its functional definition, and degrade into "spaghetti".

Avoiding prefixes and using namespaces to their full advantage is also strongly recommended by me as well.

In addition, effective usage of friend declarations helps to strengthen encapsulation and allows classes to depend on one another within their object-oriented heirarchy, without increasing the complexity of the system.

Check out The Lite C++ FAQ for further info and insights. I have found that FAQ to be a tremendously helpful resource as I constantly hone my powers of OOP.

I look forward to seeing your finished camera system classes! :)
User avatar
abstractcoder
Gnome
Posts: 336
Joined: Wed Oct 12, 2005 1:50 pm
Location: UK
Contact:

Post by abstractcoder »

thanks, first tomorrow i am going to change all my code so that it uses namespaces. then i will try using friend as an alternative to subclassing them.

as for right now i am going to get some sleep so im not too tired trying it in the morning :)
Post Reply