|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Finally got a routine to point my spaceships. Each is built along the X axis,
in the positive X direction. I've used a spline to define the spaceships
motion, but getting the ship to point into the direction it is going.
But here it is:
#macro aimAt(p_cur, p_new )
// given an object around origin pointing in the x direction,
// generate a rotation so it can go from p_cur to p_new
#local p_diff = p_new - p_cur; // where it's headed (vector normalized to
origin)
#local y_angle = - atan2d(p_diff.z,p_diff.x) ;
#local xy_diff = sqrt(p_diff.x*p_diff.x + p_diff.z*p_diff.z);
#local z_angle = atan2d(p_diff.y,xy_diff) ;
// #if (p_diff.y < 1) #local z_angle = -z_angle; #end
rotate <0,0,z_angle>
rotate <0,y_angle,0>
#end // aim at
And an example of it's use (cccc is a variable based off of the clock):
object{ Freebooter(1) aimAt( moveSpline(cccc), moveSpline(cccc+.001) )
translate moveSpline(cccc) - <-90,-100,-100> no_shadow }
Enjoy!
Tom A.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Does your spaceship adhere to Newtonian physics? In which case your ship
will slide around a lot and not necessarily point in the direction you
are moving.
Mike
On 3/20/2019 9:26 PM, Tom A. wrote:
> Finally got a routine to point my spaceships. Each is built along the X axis,
> in the positive X direction. I've used a spline to define the spaceships
> motion, but getting the ship to point into the direction it is going.
> But here it is:
>
> #macro aimAt(p_cur, p_new )
> // given an object around origin pointing in the x direction,
> // generate a rotation so it can go from p_cur to p_new
>
> #local p_diff = p_new - p_cur; // where it's headed (vector normalized to
> origin)
> #local y_angle = - atan2d(p_diff.z,p_diff.x) ;
> #local xy_diff = sqrt(p_diff.x*p_diff.x + p_diff.z*p_diff.z);
> #local z_angle = atan2d(p_diff.y,xy_diff) ;
> // #if (p_diff.y < 1) #local z_angle = -z_angle; #end
>
> rotate <0,0,z_angle>
> rotate <0,y_angle,0>
>
> #end // aim at
>
> And an example of it's use (cccc is a variable based off of the clock):
>
> object{ Freebooter(1) aimAt( moveSpline(cccc), moveSpline(cccc+.001) )
> translate moveSpline(cccc) - <-90,-100,-100> no_shadow }
>
> Enjoy!
>
> Tom A.
>
>
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
|
|