POV-Ray : Newsgroups : povray.general : Aiming a spaceship : Aiming a spaceship Server Time
25 Apr 2024 10:52:31 EDT (-0400)
  Aiming a spaceship  
From: Tom A 
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

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