Sign in to follow this  

update camera position

This topic is 2960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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 :/

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
..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....

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
...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...

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
..as i already write..
i am at beginner level..
i am to nvidia physx documentation, examples, samples...experience/learn/study.
i am to level were i experience put all kinds of objects on scene on some coord, move , apply forces..., change settings, change functions, arguments, update camera coordonates after diferent actors...etc ..hundreds of things like this...
at this moment
in nvidia physx
no dirextx integration

Share this post


Link to post
Share on other sites
Quote:
Original post by m_cio
i am at beginner level..
i am to nvidia physx documentation, examples, samples...experience/learn/study.


Ok this is just my opinion but I think you are starting at the wrong end. Physics is great but using a physics library won't teach you how to put everything together into a game. First you want to get a game loop going (which really is basically while(true) until you hit an exit condition). Doesn't matter at this point if it's DirectX or just printing some text to the console.

Here is a very basic article on how to put together a game loop. If/When you feel you want to get something more advanced going, read this one. But you can start with something simple. Just keep looping it.


loadGameStuff()
while (true):
if(wantToQuit):
quit()

updateInput()
updateGame()
drawGame()



Then in your updateGame() you can update both the player (move him if you want) and the camera (move it based on how the player moved). In drawGame() just print their positions out to the console to check them.

Share this post


Link to post
Share on other sites
thank you verry much...
finnaly , as you said, after read your docs, i find that is necessary only put this:
gCameraPos = box->getGlobalPosition();
inside RenderCallback() for a corect coord. update
thats all...
thanks again

Share this post


Link to post
Share on other sites

This topic is 2960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this