Public Group

# DX Camera (Moving left regardless of angle)

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

## Recommended Posts

Hi, me again with more math questions I should probably remember heh. Ok so, I want to be able for certain functions move the camera/look position in a direction regardless of angle. For instahnce, a simple moving left if you're camera is straight would adding to the x position, but I want it to move it left (appearance wise) regardless of angle. Ok, so:
    ___
/  |  \
|   |   |
|   *   |
\ ___ /

The * represents the camera and the line extending above it is the direction it is looking. Note: I drew a circle because I used that to try and figure out new 'circle' to use cos/sin with. So What I tried to do was I figured regardless of any angle, there'd be a line tangent to the circle where the direction the camera is looking meets with the circle extending pi/4(I think 90 deg?) to the left. So I figured, I'd set that to whatever I want my moveRate to be. Then I knew that the direction line was equal to the radius I had been using for circular rotation so I got a reasonable thing going. so now I have:
 moveRate
_____
\    |
\   |
h \ |
\|

So I decided h would be the NEW radius for the new circle, and thus I did: (a^2 + b^2 = c^2) radius = sqrt(radius * radius + moveRate * moveRate) And got the new radius, and now the last bit would be to find the new angle. Ok, now I remember from a class that SinA/ a = SinB / b in a triangle, and I know a(new radius) and sinA(1, since A is 90 deg) and I knew b (move Rate) I just had to figure the rest out: newAngle = oldAngle + arcsin(moveRate/newRadius) and then bam, add posX = cos(angle) * radius and posZ = sinangle) * radius and then add the differences to lookX/lookZ and there ya go. If you have managed to weed through all of that, what is happening is it IS going 'left' or 'right' but it is making sort of like a W-shape.
*           *
*         *
*       *
*  o  *
*   *

Something like that where 'o' is the starting point.

##### Share on other sites
You want your camera to strafe? If so, you don't need all this complicated math. What you want to do is take the cross product of your view vector and your up vector, normalize the result, multiply it by how fast your camera can move, and update the position with time from the last frame.

##### Share on other sites
Woa Ok I'll look into those things - I figured there was an easier way.

I'll post back after I try it out and see how it works.

##### Share on other sites
So aside from me havin trouble figuring out cross product, what do I do with it? I mean.. I have the lookAt vector and up vector being cross producted and then I normalize it (I have to look that up to) and then multiply it by a simple number? like if I want to move it by 2 units, I multiply it by 2 or ?

After all that, I dont know what I do with it

##### Share on other sites
Still not sure what I'm doing, or how..

        D3DXVECTOR3 cross;	D3DXVec3Cross(&cross, &look, &up);	D3DXVECTOR3 norm;	D3DXVec3Normalize(&norm, &cross);		pos = norm;

Where pos is the camera objects position vector, look is the look vector and up is the up vector.

This code is warping my location to seemingly the same y Level as look.y and nothing else.

##### Share on other sites
The cross product of two vectors will give you a resultant vector that is orthogonal to each of the operand vectors. The cross products of two vectors (a, b, c) and (d, e, f) is equal to the determinant of

[[i,j,k] [a,b,c] [d,e,f]]

Thus:
Consider two vectors, a = (1,2,3) and b = (4,5,6). The cross product a × b is    a x b = (1,2,3) x (4,5,6) = ((2 * 6 - 3 * 5),(-1 * 6 + 3 * 4), (1 * 5 - 2 * 4)) = (-3,6,-3).

As you can see, the result is not a unit vector. If you want to be able to control the speed of your camera, you need to normalize it, which essentially means to make the length of the vector equal to one. Once it is equal to one, you can multiply the result by the speed of your camera (in units per second) and the time elapsed since the last frame in order to find the distance between the camera's previous location and its now present location. If you add this distance vector to your camera's previous location (in xyz coordinates), you will end up with the camera's final location (in xyz coordinates).

Thanks a lot :D

##### Share on other sites
Quote:
 Original post by CrimsonSunYou want your camera to strafe? If so, you don't need all this complicated math. What you want to do is take the cross product of your view vector and your up vector, normalize the result, multiply it by how fast your camera can move, and update the position with time from the last frame.

Heh, that's exactly how I implemented my first DX camera just a while ago :D

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 9
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999990
×