POV-Ray : Newsgroups : povray.advanced-users : Rotation Matrix around X or Y axis Actual vs. Theoretical : Re: Rotation Matrix around X or Y axis Actual vs. Theoretical Server Time
28 Jul 2024 18:27:07 EDT (-0400)
  Re: Rotation Matrix around X or Y axis Actual vs. Theoretical  
From: Tor Olav Kristensen
Date: 6 Sep 2004 22:08:10
Message: <413d180a$1@news.povray.org>
amjad wrote:

...
> What is the way in predicting the exact pixel location for an object
> -say a simple box place at <x1,y1,z1> - in the image for rotating just 
> the camera? Any hint or help in this matter is really appreciated.
...

Below is some code that will find screen coordinates of a
point when the camera vectors are known.

If you do not know how to find the new camera vectors after
a camera rotation, then I can help you with this too.


Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Calculation of screen coordinates of a point
// in front of a perspective camera.
// By Tor Olav Kristensen, 7. September 2004

#version 3.6;

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#default {
   texture {
     pigment { color rgbt <0.5, 0.5, 0.5, 0.8> }
     finish { ambient 2 }
   }
}

background { color blue 0.5 }

// Default camera parameters
#declare pLocation = 0*y;
#declare vDirection = z;
#declare vRight = 1.33*x;
#declare vUp = y;
#declare vSky = y;

// Where to look from and where to look
#declare pLocation = <0, 2, -3>*4;
#declare pLookAt = <0, 3, 0>;

// Calculate the new camera vectors "manually"
#declare vLookAt = pLookAt - pLocation;
#declare vDirection = vlength(vDirection)*vnormalize(vLookAt);
#declare vRight = vlength(vRight)*vnormalize(vcross(vSky, vDirection));
#declare vUp = vlength(vUp)*vnormalize(vcross(vDirection, vRight));

camera {
   location pLocation
   direction vDirection
   right vRight
   up vUp
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare vImageSize = <image_width, image_height>;

#declare p0 = <2, -1, 3>; // Position of sphere


#declare v0 = p0 - pLocation;

#declare vC =
   v0*vdot(vDirection, vDirection)/vdot(v0, vDirection);

#declare vImage =
   vImageSize*
   <
     vdot(vC, vRight)/vdot(vRight, vRight),
     vdot(vC, vUp)/vdot(vUp, vUp)
   >;

#debug "\n\n"
#debug "Position relative to center of image: "
#debug concat("<", vstr(2, vImage, ", ", 0, -1), ">")
#debug "\n"
#debug "Position relative to upper left corner of image: "
#declare vImage = vImageSize/2 + vImage*<1, -1>;
#debug concat("<", vstr(2, vImage, ", ", 0, -1), ">")
#debug "\n\n"

sphere {
   p0, 0.3
   pigment { color rgbt <0.8, 0.5, 0.5, 0.8> }
}

sphere {
   pLocation + vC*1, 0.01
   pigment { color rgbt <0.5, 0.8, 0.5, 0.8> }
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

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