POV-Ray : Newsgroups : povray.general : Aiming a spaceship Server Time
31 Oct 2024 21:27:37 EDT (-0400)
  Aiming a spaceship (Message 1 to 2 of 2)  
From: Tom A 
Subject: Aiming a spaceship
Date: 20 Mar 2019 21:30:01
Message: <web.5c92e8379a594812cd3d062c0@news.povray.org>
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

From: Mike Horvath
Subject: Re: Aiming a spaceship
Date: 1 Apr 2019 07:45:23
Message: <5ca1f9d3$1@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.