• Advertisement

Sir David

  • Content count

  • Joined

  • Last visited

Community Reputation

103 Neutral

About Sir David

  • Rank
  1. Moving a scene/entity in a 3D world.

    [quote name='L. Spiro' timestamp='1343738080' post='4964833'] 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. [/quote] 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. [quote name='wolfscaptain' timestamp='1343732720' post='4964803'] You can use a unit vector to store your facing direction. If you want to turn, rotate the vector. [/quote] 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. 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.
  2. I'm working on a space game where the player controls a spaceship, and I'm having some difficulty getting the math right. 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.
  • Advertisement