xyz

Started by
2 comments, last by dhanyu 20 years, 1 month ago
I like to know how to move an object from source to destination in xyz plane. To be more specific....... If I want to shoot an object the bullet path has to be calculated. I''m looking for a solution. thanks - Dhanyu
dhanyu
Advertisement
Well, assuming nothing wacky, you''ll have a source vector and a destination vector, each with x, y, and z components. The displacement between the 2 (i.e. the difference) can be found by having a vector (vDestination - vSource).

You can derive a line equation from the start and end by determining slope in the x and z directions. This will probably be of the form y = f(x, z). If you have a velocity vector, you can also come up with a set of functions x = f(t), y = f(t), and z = f(t). These will give you a set of parametric equations that define your line. But generally the vector is enough, unless you need to do some sort of time based prediction or something.

That was kind of quick, if I lost you just say so.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
HI,

Thankx Promit. Let me express what I learned from your answer.

if source is X Y Z and destination is X1 Y1 Z1

displacement = X-X1, Y-Y1, Z-Z1

so if I move my object in loop till while
i != X-X1 i++ or i--
j != Y-Y1 j++ or j--
k != Z-Z1 k++ or k--

this would give me straight path to the destination.

this is what I understood. Thank you for your reply. Please let me know if I''m wrong.

- Dhanyu
dhanyu
More or less, yeah. The only things to note:

i, j, and k are almost certainly floating point variables, so you can add something other than 1 to them, any number in fact (this is where a velocity vector comes in). Instead of checking i != X - X1 you should probably check that i < X - X1 or whatever, because there''s a possibility of overshooting the final target (floating point inaccuracies and such). Then when you do reach or pass the end point, set the coordinates to the end point. This will make sure you don''t overshoot your target.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

This topic is closed to new replies.

Advertisement