POV-Ray : Newsgroups : povray.advanced-users : matrix help.... : Re: matrix help.... Server Time
29 Jul 2024 22:30:56 EDT (-0400)
  Re: matrix help....  
From: Margus Ramst
Date: 8 Sep 2000 18:40:37
Message: <39B95CBE.1E526195@peak.edu.ee>
Paul Daniel Jones wrote:
> 
> is it possible to use a matrix to force an object at point <x1,y1,z1> to
> "track" a point <x2,y2,z2> without having to use complex trig functions.
> ie: imagine a gun following a moving target (whose position is given by
> a spline), how would i point the barrel? I tried the reorient macro, but
> I must admit, I don't understand the matrix command very well.
> 

The Reorient macro should do exactly what you need, and there should be no need
to understand the inner workings of the matrix command. Doesn't it work for you,
and if so, why?
Or perhaps this will help: these macros work as a vector equivalet of Reorient
(you need to call v_reorient, the second is used internally to catch ambiguous
cases)

//give 0 if not parallel, 1 if parallel, -1 if anti-parallel
#macro v_parallel(V1i,V2i)
    #local V1=vnormalize(V1i+<0,0,0>);
    #local V2=vnormalize(V2i+<0,0,0>);
    #local Vt=(vlength(V1+V2)-1);
    #if(Vt=1|Vt=-1) Vt
    #else 0
    #end
#end

//Vector equivalent of John VanSickle's Reorient macro
//V - vector to be reoriented
//RefA - original orientation
//RefB - target orientation
#macro v_reorient(V,RefA,RefB)
  (#if((v_parallel(RefA,RefB))=0)
    vaxis_rotate(
      V,
      vcross(vnormalize(RefA),vnormalize(RefB)),
      degrees(atan2(vlength(vcross(vnormalize(RefA),vnormalize(RefB))),
      vdot(vnormalize(RefA),vnormalize(RefB)))))
  #else
    ((v_parallel(RefA,RefB))*V)
  #end)
#end

-- 
Margus Ramst

Personal e-mail: mar### [at] peakeduee
TAG (Team Assistance Group) e-mail: mar### [at] tagpovrayorg


Post a reply to this message

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