# Screen space movement

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

## 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 on other sites
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 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 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:

<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 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!

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633726
• Total Posts
3013569
×