POV-Ray : Newsgroups : povray.general : Aiming a spaceship : Aiming a spaceship Server Time: 27 Jun 2019 04:14:15 GMT
  Aiming a spaceship  
From: Tom A 
Date: 21 Mar 2019 01:30:01
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-2008 Persistence of Vision Raytracer Pty. Ltd.