Base class for camera and objects?

Started by
2 comments, last by Chadivision 20 years ago
Since the process of rotating a camera is basically the same as rotating any 3D object, is it usually best to make a base class that can handle rotations (using whetever method you choose) and derive the camera and your 3D objects from the same class?
Atari 2600 Homebrew Author - Someone who is smart enough to learn 6502 assembly language but dumb enough to actually want to use it.
Advertisement
I would do exactly that. If your base class has all the main properties that other objects do (such as x, y and z floats) its easier to derive them from one class.

Worship the holy trinity that is Blitz, Babes and Beers!
Worship the holy trinity that is Blitz, Babes and Beers!
Yes, it''s not a bad approach. Something you may want to consider, if you''re dealing with a fair old number of 3D objects, is using a ''scene graph'' - in this case, a tree of objects. Transformations applied to a node in the tree get ''carried down'' to nodes lower in the tree - and they put their own transformations on top.

Say you want to set the camera to ''see through the eyes'' of a character in your scene. You could set the camera as a child object of that character in the tree, and then whenever you rotate the character around, the camera goes with it. Further on, it applies to things like animation - having fingers as child objects of a hand means that the fingers will rotate with the hand as it moves, but they can also be rotated and moved on their own (skeletal animation).

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

I hadn''t really thought about the scene graph approach, but it makes sense.

If you want to apply the same rotation to several related objects it would simplify the process and it would also be more efficient. You could compute the matrix once and then pass it to all of the objects that are farther down the tree.

Atari 2600 Homebrew Author - Someone who is smart enough to learn 6502 assembly language but dumb enough to actually want to use it.

This topic is closed to new replies.

Advertisement