POV-Ray : Newsgroups : povray.general : Define camera angle from a given right : Re: Define camera angle from a given right Server Time
30 Jul 2024 10:18:23 EDT (-0400)
  Re: Define camera angle from a given right  
From: clipka
Date: 1 Mar 2009 06:10:01
Message: <web.49aa6cc178557ac474c3e19a0@news.povray.org>
"gregjohn" <pte### [at] yahoocom> wrote:
> I want complete control of the screen. For example, I want to be able to place a
> sphere at the corner of the generated image, no matter what the pixel size or
> ratio of the image, no matter the angle (however it's defined).

Been there, did that:

http://www.tc-rtc.co.uk/imagenewdisplay/stills/index164.html

The coffee spill in this shot is a blob object, with the individual elements
"sputtered" from the camera location, and covering no more than the actually
visible area (plus some "overscan" for the focal blur).

The core of that code is as follows:

#include "math.inc"
#include "transforms.inc"

#declare camera_location        = <6,5,6>;
#declare camera_angle           = 60;
#declare camera_look_at         = <0,1.5,0>;
#declare camera_focus_at        = <0.3,1.0,0.3>;
#declare camera_look_at_level   = (x+z)*camera_look_at + y*camera_location;
#declare camera_rotate          =-VAngleD(camera_look_at_level -
camera_location, z);
#declare camera_tilt            = VAngleD(camera_look_at_level -
camera_location, camera_look_at - camera_location);
#declare camera_transform       = transform { rotate x*camera_tilt rotate
y*camera_rotate }
#declare camera_true_right      = vtransform(x,
camera_transform);
#declare camera_true_up         = vtransform(y*image_height/image_width,
camera_transform);
#declare camera_true_direction  = vtransform(z*0.5/tand(camera_angle/2),
camera_transform);
#declare base_plane = plane { y, 0 }
#macro VCamera(xScreen,yScreen)     (camera_true_direction +
(xScreen/image_width-0.5)*camera_true_right +
(yScreen/image_height-0.5)*camera_true_up) #end
#macro VTrace(obj,xScreen,yScreen)
trace(obj,camera_location,VCamera(xScreen,yScreen)) #end

camera{
  perspective
  location  camera_location
  right     x
  up        y*image_height/image_width
  angle     camera_angle
  look_at   camera_look_at
}

The VTrace() macro traces a ray from the camera for a particular point on the
screen.


> I've got a way to do this using an obtuse use of the right vector.  It works
> perfectly for the camera in the default location. If I want to look somewhere
> else, I can simply apply a transform to both the camera and the object.  Using
> the formula in that is in the docs doesn't work immediately in my code.  I
> suspect the docs aren't completely telling us how the camera actually works--
> that image sure as heck doesn't.

The image in the docs sure as heck *DOES* - provided you use the "correct"
parameters that are expected to be used for camera control these days:

- use the up/right/direction vectors to define what axis is to be projected to
the vertical on the image (up), what the aspect ratio of your shot will be (up
& right), and whether you have a "left-" or "right-handed" co-ordinate system
(up & right & direction); that and *NO MORE*. AFAIK only the relative length of
these vectors matters except for the "up" vector which needs to point in a
suitable direction (the absolute length still doesn't matter) and that they
should be perpendicular to each other matching your desired "handedness".

- use location and look_at to define where the camera is placed (location) and
what direction it is facing (location & look_at).

- use angle to define the camera's opening angle (left to right).

I took *all* information for the above code from the online doc, *particularly*
the image you're ranting against. That plus some generic knowledge about vector
math.


> There are a bunch of parameters that can be
> played with, but I don't know how the camera actually WORKS.

If you want it to work (and match the diagram in the docs), use the above
schema.

If you want to fully understand what each parameter does when used in a
particular order (beyond what the docs disclose if you read them carefully),
dig through the code...


Post a reply to this message

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