Jump to content
  • Advertisement
Sign in to follow this  
mikeman

Screen space movement

This topic is 3655 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

I'm sure this is a pretty simple problem, but I have stuck with it. Basically, let's say we have a 3D scene, and a character moving in it. I just want the movement of the character to be in screenspace. For example, when I press 'right', I want the character to move towards the right edge of the screen, no matter the camera angle. And so on. In other words, for a displacement vector in screenspace(say for 'right' is (1,0) ), I want the 3D vector that I want to displace my character in world space. I'm sure there's some method of formula about this, but I haven't managed to find it. Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
Usually it's just a matter of rotating the "controller" vector by the camera's yaw.

Or if your camera is purely matrix-based, just run the vector through the matrix and you'll probably be fine.

Share this post


Link to post
Share on other sites
In psuedocode...


Matrix cameraWorldMatrix = viewMatrix.Invert()
Vector4 rightVector = (1.0, 0, 0, 0)
Vector4 rightViewSpace = cameraWorldMatrix * rightVector


Note that this assumes column vectors (OpenGL). For row vectors, you should do rightVector * cameraWorldMatrix. And of course you can use whatever direction you want instead of positive X and this will work.

For your reference...this works because the view matrix for a camera is just the inverse of a matrix representing the camera's transform (its world matrix, so to speak). So this means that the 3x3 portion of the inverse of the view matrix represents the camera's orientation (rotation). If you transform any vector by this, you orient that vector in view space. Note that to only rotate the vector and not also translate it, I set the w component of the vector to 0.

Share this post


Link to post
Share on other sites
Hm. There's something I quite don't get. Here's a screenshot of a plane(a rectangle really) and two character moving in it:

Image Hosted by ImageShack.us<br/>

Let's say we want the characters to move when we press 'DOWN' key. We want to calculate the displacement vector. Is it the same for both objects, indepedent of their position? I mean, if the vector in this case is (0,0,1), that is the objects move along the z-axis. It works for the character in the center. But the character on the edge of the screen will not move entirely 'down' in screenspace, but diagonally.

What am I misunderstanding here?

Share this post


Link to post
Share on other sites
they're moving the same vector in world-space, but on-screen that translates into moving away from the 'vanishing point' . .

if the character should really be moving per the screen and isn't in the middle, you'd have to skew Z axis movement towards the camera .... ie - "right" is right and "left" is left.. .but down is vector pointing towards camera's projection into the movement plane, and up its opposite... i mean, if camera is at (0,10,0) and movement is considered on the ground plane then you're pointing at (0,0,0)

wait.. i just went cross-eyed... Whheeeeeeeeee!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!