POV-Ray : Newsgroups : povray.advanced-users : matrix help.... : Re: matrix help.... Server Time
29 Jul 2024 22:27:07 EDT (-0400)
  Re: matrix help....  
From: John VanSickle
Date: 14 Sep 2000 08:37:03
Message: <39C0C66E.9A38BA43@erols.com>
David Fontaine wrote:
> 
> John's macro should do what you want. The only problem I think would be the axial
> rotation changing, but if your gun stays pointing on the x-z plane with y up it
> shouldn't matter I think. I've written one aimilar to keep axial rotation the same
> (perpendicular vector intersecting y axis still intersects y axis). It's a lot
> messier than John's though.

The Reorient vector tilts as if the joint were a ball-and-socket joint.  If you
want to tilt in the way the POV camera tilts when the look_at parameter is
specified, here is some tighter, neater, and more flexible code.

Specifically, it allows you to begin from any direction; this is useful because
sometimes I model with x=forward, and sometimes with z=forward.  The "up"
direction of your scene can also be specified, so this can be used by people
who use up=y or up=z (or up=<3,4,12>/13, if you want to be strange).

I should probably add this to the Thoroughly Useful Macros file...

Hope this helps,
John

// macro code follows

#macro PointAlong(OldDirection,NewDirection,Up)
// OldDirection is the direction in which the object is currently pointed
// NewDirection is the direction in which you want it to point
// Up is the vector that is considered to be up

#if(vlength(OldDirection)=0)
#error "Zero-length vector supplied as old direction.\n"
#end
#if(vlength(NewDirection)=0)
#error "Zero-length vector supplied as new direction.\n"
#end
#if(vlength(Up)=0)
#error "Zero-length vector supplied as up vector.\n"
#end

#local vOD=vnormalize(OldDirection);
#local vOR=vcross(Up,OldDirection);
#if(vlength(vOR)=0)
  #debug "Old direction vector is parallel to up vector.\n"
  #local vOR=vcross(vOD,<vOD.z,vOD.x,-vOD.y>);
#end
#local vOR=vnormalize(vOR);
#local vOU=vnormalize(vcross(OldDirection,vOR));

#local vND=vnormalize(NewDirection);
#local vNR=vcross(Up,NewDirection);
#if(vlength(vNR)=0)
  #debug "New direction vector is parallel to up vector.\n"
  #local vNR=vcross(vND,<vND.z,vND.x,-vND.y>);
#end
#local vNR=vnormalize(vNR);
#local vNU=vnormalize(vcross(NewDirection,vOR));

matrix <vOR.x,vOU.x,vOD.x, vOR.y,vOU.y,vOD.y, vOR.z,vOU.z,vOD.z, 0,0,0>
matrix <vOR.x,vOR.y,vOR.z, vOU.x,vOU.y,vOU.z, vOD.x,vOD.y,vOD.z, 0,0,0>

#end
// end of macro code


Post a reply to this message

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