tags:

views:

88

answers:

2

I have a camera class and i want it to be able to track a physics object. However in my game engine (which is what the camera class will be part of), you can use different physics engines (even some i did not develop). How can i make my camera capable of tracking an object regardless of the physics engine i am using? if it helps, i will have a wrapper class to help abstract some of the specifics of dealing with specific engines physics implementation.

A: 

This completely depends on how your graphics engine is setup.

Most graphics engines have some form of scene graph, and a way to attach a camera to a node in the scene graph. This will make the camera inherit the transform's of it's parent, which means it can easily "follow" around another node.

If the physics system integrates cleanly, it'll move the objects around the scene, which effects their node. This will automatically propagate into the camera.

I could potentially give you more specifics, if you want to specify the game engine + physics integration packages you are using.

Reed Copsey
I dont even know what a scene graph is so that isnt going to work. I am writing my own engine and it will be using www.codeplex.com/farseerphysics as well as the jelly physics library from www.walaber.com , and a custom physics library developed by me as physics choices. Basically, i need a way to store a reference to a Vector2 so that i can track it. maybe i should have asked that?
RCIX
If you're writing your own engine, I'd study up on scene graphs. Most physics libraries assume that you have a way to modify transforms, which ties in nicely with a scene graph. Otherwise, just keep a reference to the object itself (with the position), and follow it around. You can't (easily) keep a reference to the Vector2 (since it's a value type), but you can keep a reference to the object which contains the Vector2.
Reed Copsey
+1  A: 

Wrap your object with something that contains a standard position object (Probably a Vector3). Then, simply add a Camera.LookAt(GameObject) method that will allow you to track the object. Also, this is nice to use with other objects in your engine, it simply gives you the ability to follow any object with any camera. This is the method I have used in my two previous game applications.

karbon
That will actually probably work seeing as i wanted to do a wrapper around the physics engines i want... thanks!
RCIX
Glad I could help! :)
karbon