**0**

# Moving a scene/entity in a 3D world.

###
#1
Members - Reputation: **103**

Posted 30 July 2012 - 10:12 PM

What I'd like is a spaceship starting at the origin of the world with up in the positive Y, and forward into the screen, and the ability to move the ship forward, backward, left/right (strafe), turn to the right and left (rotation on the Y axis), and nose up and down (rotation on the X axis).

All this is working, at least to start. However, I'm having difficulty, suppose I start my game, and turn the ship to the left by 45 degrees so I'm still on the Z plane have neither angle up nor down, and simply am pointing off between negative Z (away from the screen), and negative X. Suppose the ship is given some forward acceleration, and then stopped say 50 units away from the origin.

Note: Up to this point, I have this working, the following is where it gets tricky.

Now suppose the ship is put nose down 45 degrees, and another 45 degrees to the left, so I'm facing directly in the negative X with my nose now pointing in the half-way between negative Y and negative X. Now, suppose I give the ship some velocity in the forward direction... Where should it end up?

So put another way, given a ship at an arbitrary 3D point, (x, y, z), a heading/direction, a velocity and a time(delta), how do I find the point where the ship should end up? Also, how should the heading/direction be stored?

Along the same lines, currently, when a user presses keys for rotating the ship on one of the axes, I increment a value, and rotate the ship on the corresponding axis. This works, and looks right, but I'm having trouble keeping track of where "heading/direction" is. How should this be recorded? Should I have three vectors for each axis or something?

I would greatly appreciate some detailed explanation or discussion of this. I've browsed and found some useful vector/matrix math stuff that's been helpful, but not quite enough to get me where I'm going. Any insight you could provide is welcome. Thanks in advance.

###
#2
Members - Reputation: **200**

Posted 31 July 2012 - 05:05 AM

If you want to turn, rotate the vector.

If you want to move, the velocity is speed*direction.

Another option is to use a quaternion, but I think starting with a vector is easier (more straightforward, anyway).

###
#3
Crossbones+ - Reputation: **20772**

Posted 31 July 2012 - 06:34 AM

Via a normalized 3D vector.Also, how should the heading/direction be stored?

Take the previous 3D vector, multiply it by the speed (not velocity) and by time, then add it to the ship’s current 3D vector that represents its position. The position of the ship has now moved in the correct direction by the correct amount.So put another way, given a ship at an arbitrary 3D point, (x, y, z), a heading/direction, a velocity and a time(delta), how do I find the point where the ship should end up?

L. Spiro

My Art: http://l-spiro.deviantart.com/gallery/4844241/Realism My Music: https://soundcloud.com/l-spiro

L. Spiro Engine: http://lspiroengine.com

L. Spiro Engine Forums: http://lspiroengine.com/forums

###
#4
Members - Reputation: **103**

Posted 04 August 2012 - 11:01 AM

This makes sense, I think. You're saying that I have one vector at my world origin which gives the ships x, y, z, and after adding the speed*direction*time to the position vector, it's the ship's new position.Take the previous 3D vector, multiply it by the speed (not velocity) and by time, then add it to the ship’s current 3D vector that represents its position. The position of the ship has now moved in the correct direction by the correct amount.

This I'm not so clear on. Is this unit vector centered about the world origin? I suppose it would be, right? If so, my difficulty now is in adjusting the direction of that unit vector. If the ship's "up" is in the positive Y direction, and the ship is facing the negative X, then when the user turns there ship to the left, I just rotate the facing direction about the Y axis, but I have trouble envisioning how it works when the "up" vector has X and Z components.You can use a unit vector to store your facing direction.

If you want to turn, rotate the vector.

I think if I had an explanation and solution for the following problem, that might help.

The ship has a direction described by the vector D=(0.36, 0.59, 0.72)

The ship's "up" direction is described by U=(.62, .75, -.21)

When a user "turns" for time 't', (rotating only about the "up" axis, like turning on a flat road in a car), the ship rotates 'pi/10' radians in the direction turned.

If this ship turns for one time unit, what is its new direction vector?

Even describing the above problem though, I foresee more issues. It seems like the direction vector MUST be centered at the ship's origin because if the direction is centered about the world origin, when the ship turns, and there's a rotation about U by pi/10 at the origin, it won't "feel" like pi/10 for the ship. From the ship's point of view it will turn very quickly at some 't's and very slowly at others based on its position from the world origin.

So there must be some sort of translation between the ship's "reference frame" and the world's.

I'm brand new to all this, so as much as you can dumb down any insight, the better.

To give the above problem a little more practicality with reference to my previous paragraph monologue, consider the following:

The ship's position in the world's reference frame is P=(50, 35, 35).

The ship moves 30 units in direction D before it turns, what is its new position P'?

Now the ship turns for one unit of time and rotates about U by pi/10.

The ship moves another 30 units in it's new direction D'.

Where is the ship's position P'' now?

A detailed solution to this would be GREATLY appreciated. Thank you.

###
#5
Crossbones+ - Reputation: **20772**

Posted 06 August 2012 - 07:47 AM

It is a direction; it has no center point. This is like asking , “What is the center point of left?”.This I'm not so clear on. Is this unit vector centered about the world origin?

D + Rotated amount. To combine rotations, look into quaternions or matrix rotation around axes.When a user "turns" for time 't', (rotating only about the "up" axis, like turning on a flat road in a car), the ship rotates 'pi/10' radians in the direction turned.

If this ship turns for one time unit, what is its new direction vector?

P + D * 30.The ship's position in the world's reference frame is P=(50, 35, 35).

The ship moves 30 units in direction D before it turns, what is its new position P'?

D += PI/10 (Matrix Rotation Around U).Now the ship turns for one unit of time and rotates about U by pi/10.

The ship moves another 30 units in it's new direction D'.

Where is the ship's position P'' now?

P" = P' + D * 30.

There is nothing tricky, fancy, or non-trivial happening here.

Just add and multiply things.

L. Spiro

My Art: http://l-spiro.deviantart.com/gallery/4844241/Realism My Music: https://soundcloud.com/l-spiro

L. Spiro Engine: http://lspiroengine.com

L. Spiro Engine Forums: http://lspiroengine.com/forums