POV-Ray : Newsgroups : povray.animations : Storing object rotation : Re: Storing object rotation Server Time
8 Jul 2024 12:45:23 EDT (-0400)
  Re: Storing object rotation  
From: Rune
Date: 18 Mar 2003 08:39:24
Message: <3e77218c$1@news.povray.org>
Phil Brewer wrote:
> The way I see it, I can either save a new rotate statement for every
> frame including all previous frames (I think parse times would get
> excessive towards the end), or break my arbitrary axis rotation into
> something that could be stored as a simple sequence of rotations.

Any sequence of rotations can be stored as a single matrix
transformation, and any matrix transformation made of only rotations can
be stored as a single rotation statement. So the accumulated rotations
can be stored as a single rotation vector.

Untested code below.

// I assume you have:
// CurRotate and CurTranslate
// - the rotation and translation from the previous frames.
// ThisRotate and ThisTranslate
// - the rotation and translation to be done in the current frame.
// And then you get NewRotate and NewTranslate
// - the rotation and translation from the previous frames
//   plus the current frame.

// Given 2 vectors, a vector for the X direction
// (similar to the 1st - 3rd number in a matrix),
// and one for the Y direction (similar to the
// 4th - 6th number in a matrix), Vectors2Rotate will
// return a rotation vector which will transform an
// object in the same way as a matrix using the
// vectors would do. VectorX and VectorY must be
// perpendicular to each other.
#macro Vectors2Rotate (VectorX,VectorY) // by Rune S. Johansen
   #local RotZ = VRotationD(x,<VectorX.x,VectorX.y,0>,z);
   #local RotY = VRotationD(x,vrotate(VectorX,-RotZ*z),y);
   #local RotX = VRotationD(vrotate(y,<0,RotY,RotZ>),VectorY,VectorX);
   <RotX,RotY,RotZ>
#end

// Get the current local x, y and z axis
CurX = vrotate(x,CurRotate);
CurY = vrotate(y,CurRotate);

// Get new rotation from old using using
// the rotation for the current frame...
// (You can also use vaxis_rotate to get
// NewX,Y,Z from OldX,Y,Z if that is
// more natural to your algorithm.)
NewX = vrotate(CurX,ThisRotate);
NewY = vrotate(CurY,ThisRotate);
NewRotate = Vectors2Rotate(NewX,NewY);
NewTranslate = CurTranslate + ThisTranslate;

object {Ball rotate NewRotate translate NewTranslate}


Hope that helps...

Rune
--
3D images and anims, include files, tutorials and more:
rune|vision:  http://runevision.com (updated Oct 19)
POV-Ray Ring: http://webring.povray.co.uk


Post a reply to this message

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