Rib
Camera Transformations


return to main index



The tutorial explains how the world coordinate system is created in a Rib file. A sequence of transformation commands (Scale, Rotate and Translate) applied before WorldBegin create a copy of the camera coordinate system that is inverted, rotated and "placed" in front of the camera. This sequence of transformations are, somewhat misleadingly, known as the "camera transforms".

When the WorldBegin statement is executed by PRMan the new coordinate defines the world coordinate system. Subsequent transformations are relative to the origin and axes of the world coordinate system.

The "camera transforms" determine how the 3D scene will be viewed by the camera and as such what is transformed is NOT the camera but the world coordinate system.



Figure 1



Option "searchpath" "rixplugin" "${RMSTREE}/lib/shaders:@"
Integrator "PxrVisualizer" "shaded_wireframe"
Hider "raytrace"
  
Display "camera_transforms" "it" "rgb"
Projection "perspective" "fov" 20
Format 640 360 1
#-----------------------------------
Translate 0 0 3     # dolly distance
Rotate -30  1 0 0   # elevation angle
Rotate  45  0 1 0   # orbital angle
Scale 1 1 -1        # convert to right-hand coordinate system
#-----------------------------------
WorldBegin
    Polygon "P" [-0.5 0 -0.5   0.5 0 -0.5   0.5 0 0.5  -0.5 0 0.5]
    Disk 0 0.25 360
WorldEnd


The key points to understand about transformations are that they are,

  • applied in reverse order,
  • applied to a copy of the current coordinate system,
  • applied relative to the the current coordinate system.



# disk3.rib
# applying multiple transformations
  
Display "disk2" "framebuffer" "rgb"
Projection "perspective" "fov" 40
Format 320 240 1

Translate 0 0 3
Rotate -40  1 0 0 
Rotate -20  0 1 0

Two comments about the scene.


Set the camera to give a perspective view with a field of vision of 40 degrees and a frame size of 320 by 240 pixels.


The camera coordinate system is the current (active) system.


The transformations are applied in reverse order.

First, the negative rotation of 20 degrees around the y-axis is applied to a copy of the current coordinate system.

Translate 0 0 3
Rotate -40  1 0 0 
Rotate -20  0 1 0

Next, the negative rotation of 40 degrees around the x-axis is applied to the copy.

Translate 0 0 3
Rotate -40 1 0 0
Rotate -20  0 1 0

Move the transformed coordinate system 3 units along the z-axis of the camera.

WorldBegin

The copy of the coordinate system now becomes the primary, "world", or current coordinate system.

    Color 1 1 0.7
    Polygon "P" [-0.5 0 -0.5  -0.5 0 0.5  
                  0.5 0 0.5  0.5 0 -0.5]
            "st" [0 0  0 1  1 1  1 0]
    Color 1 0 0
    Disk 0 0.25 360

Make yellow the current color.
Insert a 1 x 1 polygon.

Assign the texture coordinates.
Make red the current color.
Insert the disk.

WorldEnd

Conclude the description of the 3D scene.




© 2002- Malcolm Kesson. All rights reserved.