update camera position

Started by
13 comments, last by Stani R 14 years, 5 months ago
i want to "link" the camera by an actor ... How i update the camera coordonates by the actor position on every frame ?
Advertisement
You want to watch when the player moves and then move the camera as well. The specifics of this really depend on your setup. For instance, if you are using a scene graph, you can simply attach the camera to the player.
Up to you really. Simple case:

cameraPosition = playerPosition + someOffset

More complicated way would be have a hierachy type approach, where the player is the root and the camera is a child of it. The player has a transformation (position) and the camera has a a relative transformation (offset).

You then need to transform the camera origin (0, 0, 0) into world space which you can do by first multiplying it by the camera transform and then by the player transform (or the other way round, not 100% sure at the moment).

The second approach is nice as it allows you more freedom, scaling your player will also elevate the camera position etc. You can also easily store orientation of the camera so it can look up and down without moving your actual players body up and down.

Not sure how it s actually done, would like to see some other replies as I'm interested in this too :).

Right now I do the second option and it works fine, I precompute the "to world" matrix of the camera and only update it when needed to avoid it being multiplied alot.

Ok I checked how I was doing it.
Camera has position, view, up
My player object has a "transformation" which is a matrix with position/orientation.
I call "GetLookAtVectors" on the player when I need camera info. This gets position/view/up from the camera and multiplies their value by the player transform (thus putting camera into world space) and returns the world space values.

I suppose view/up vectors might be wrong if the player is scaled :/

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

Finally !! Yes !!
I want to make an actor ( a capsule, a box , a sphere), give him a (let say) angular damping (anything to keep it streight), and move it on scene with forces applied.
And , of course , as you said, i want the camera "linked" by it ....giving to the camera the permanent (current) actor coordonates.(for now is the only and simplest way how i could imagine myself a "character controller")

Is verry simple probably. I am to the beginning of physx and i experience with all this kind of settings.

I use to work with physics in shockwave and there was verry simple and sugestive ....something like this:
i was just write:
on enterframe me
camera.worldposition = actor.worldposition
end
but here in c++ physx...i just cannot imagine how to do this.
Quote:Original post by Nanoha
Not sure how it s actually done, would like to see some other replies as I'm interested in this too :).

I compute the camera position anew every frame. I place the camera at the player ship (it's meant to be a space sim), then I rotate it (based on pitch and yaw which are independent of the ship orientation), then move it out to a "zoom distance" along the local z-axis.

..this is exact the way i 've done....but the problem is i just cannot ( so i come back to my first question) update the camera coordonats to every new frame...
i 'don't know...i dont't use the right code, the right commands....it just dont't work...
the camera remain to the first set coordonates (the initial actor coordonates), so the actor ( the "character") is moved "alone"....and the camera does not change his coordonates to move along with it....
For that method you need to get the actor's coordinates every frame. If you are already doing that, and it still doesn't work, you probably are doing something wrong (like passing the player's transform by value initially). Post your camera update code and we'll have a look.
...oh god, i am looking(asking) after such a method by over one week....
please give me the simplest example of get the actor coordonates EVERY FRAME, and set it to camera also EVERY FRAME.
let say :
the actor position:
NxVec3 actorPos;
actorPos = actor->getGlobalPosition()
and camera:
gCameraPos = actorPos + NxVec3(0,0,-2);
were actor is box, capsule, etc
Were? Were, and how , and in what function, to put this getters and setters to pass a NxVec3 coord from each other EVERY FRAME...
Quote:...oh god, i am looking(asking) after such a method by over one week....
please give me the simplest example of get the actor coordonates EVERY FRAME, and set it to camera also EVERY FRAME.
let say :
the actor position:
NxVec3 actorPos;
actorPos = actor->getGlobalPosition()
and camera:
gCameraPos = actorPos + NxVec3(0,0,-2);
were actor is box, capsule, etc
Were? Were, and how , and in what function, to put this getters and setters to pass a NxVec3 coord from each other EVERY FRAME...
1. What graphics API are you using? (E.g. OpenGL, Direct3D, etc.)

2. Do you want a first-person camera, or a third-person camera?
Quote:Original post by m_cio
...oh god, i am looking(asking) after such a method by over one week....
please give me the simplest example of get the actor coordonates EVERY FRAME, and set it to camera also EVERY FRAME.


In that time you could've looked up your graphics API, looked up your language documentation, read five books and seventeen tutorials on the subject, and implemented it five different ways... you're not using your time effectively.

It's really not that complicated. If you want to run something every frame, then just run something every frame. It won't happen automatically, you need to call those functions.

Conceptually:

while (true):    player.move()    camera.setPosition(player.getPosition())    renderer.draw(player, camera)


This is just one of twelve different ways you could get it to work. You could have the camera store a reference to the player's position and update itself based on that. Or you could store both in a scene graph with the camera as child of the player and have the scene graph keep the transforms in sync. Get it to run like this without physX first, then worry about using springs or dampening or joints or whatever technique feels best.

This topic is closed to new replies.

Advertisement