Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / Finding points on a line in 3D Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Sublime

July 05, 1999, 11:43 PM

I have a 3D object located at a specific point (x, y, z). The object is a space ship and when I want it to shoot, I animate a laser going into the screen along the z-axis.

But if I rotate the ship by some angle and it should shoot towards the left instead of straight in, what equations do I need to find the new x, y and z coordinates?


Thanks!

 
SLI9000

July 06, 1999, 12:18 AM



Sublime wrote:
>>I have a 3D object located at a specific point (x, y, z). The object is a space ship and when I want it to shoot, I animate a laser going into the screen along the z-axis.
>>
>>But if I rotate the ship by some angle and it should shoot towards the left instead of straight in, what equations do I need to find the new x, y and z coordinates?
>>
>>
>>Thanks!
>>
I'm not sure what you mean by the 'new x, y, and z coords' but would this work?
With the space ship store 3 vectors that represent the ship's x, y, and z axis.
At the start these would be x[1,0, 0] y[0,1,0] z[0,0,1].
Each time you rotate your ship, rotate each of these 3 vectors in exactly the same way.
And when you have to shoot a laser, the z axis you stored would be the direction it would have to go.

So if you were going to move the laser forward by 1, you'd translate it by the x, y, z components of the z axis you stored.

if you were going to move the laser forward by 0.1 or (1/10) you'd translate the laser by the
x/10, y/10, z/10 components of the z axis. (But make sure you preserve the original values before dividing by 10)













 
SLI9000

July 06, 1999, 12:27 AM

>>if you were going to move the laser forward by 0.1 or (1/10) you'd translate the laser by the
>>x/10, y/10, z/10 components of the z axis. (But make sure you preserve the original values before dividing by 10)
>>

Sorry, I think this would be better,
If you were going to move the laser forward by m units forward (m could be 0.1 or anything)
you'd translate the laser by x*m, y*m, z*m components of the z axis (but make sure you preserve the orig values)






 
Dimitris

July 06, 1999, 09:45 AM



Sublime wrote:
>>I have a 3D object located at a specific point (x, y, z). The object is a space ship and when I want it to shoot, I animate a laser going into the screen along the z-axis.
>>
>>But if I rotate the ship by some angle and it should shoot towards the left instead of straight in, what equations do I need to find the new x, y and z coordinates?
>>
>>
>>Thanks!
>>

When you shoot forward before you rotate the object you just add 0, 0, 1 to the x, y, z positon
of the laser. If you rotate the object then rotate 0, 0, 1 by the rotate vector of the
object and add it to the position of the leser. Laser sould be rotated by this vector, too.
If you want to change the speed of the laser by half just change 0, 0, 1 to 0, 0, 0.5 and then
rotate it.

see ya
Dimitris

 
Sublime

July 06, 1999, 06:39 PM

SLI9000 and Dimitris,
Thank you so much, you two. I think you nailed what I need to do right on the head. Unfortunately, my math skills aren't that hot. I still am a little unclear on something.

Suppose my "ship" is at the point 0, 0, 0 and the laser location is along the line 5 units into the z-axis. The direction of ship and laser are rotated off to the side about the y-axis by 45 degrees.

This means I should rotate [0, 0, 5] by 45 degrees, right? How do I make this calculation in C/C++ using OpenGL. Am I supposed to do matrix multiplication manually with a rotation matrix,
like [ cos(45) 0 sin(45) ]
[ 0 1 0 ]
[-sin(45) 0 cos(45) ]

And when I mean manually, I mean doing the multiplication and additions individually, or is there a better way, or is this totally off.

I appreciate any help!

 
This thread contains 5 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.