How would you attach the camera?

How would you attach the camera to an object?
At first, I tried synchronizing model and camera rotations, but apparently camera needs to be translated too(spend god damn 2,5 hours till I realized that). I attempted to fiddle with translation in relation to model rotation values but I didnt go far away,
So, now I got this idea. Lets say, I have some 3d model, I put it in a box, I find the very middle point of top surfice, I lift it up(in another words, I find normal of top box surfice) and lastly, I move it a bit behind the model. In this case, if model does any kind movement, camera will move too in the right way.
So, it looks it should work, but maybe missing something?

Thats my plan http://www.uploadimage.co.uk/images/265396Untitled.gif

Edit: yes, I am missing something. All I can do is to get current matrix which will give me the position coordinates. If I will have box rotated, then I am gona get that middle point?
Last edited on
Anyone?
Is this OpenGL?
It is not, but does it matter? as the this problem is more or less faced in any 3d enviroment
One solution to the middle point problem would be to determine the model's direction of rotation every frame. Make a 2d vector (or 3d if necessary), normalize it, and then multiply it by its distance from the center. Then you can simply add the vector to the camera's position.
Topic archived. No new replies allowed.