[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.9.7 Space Warping

Written by Jorrit Tyberghein, [email protected]. Mathematical typesetting for TeX performed by Eric Sunshine, [email protected].

A little explanation about space warping in Crystal Space and how the space warping matrix/vector work should be given.

Crystal Space always works with 3x3 matrices and one 3-element vector to represent transformations. Let's say that the camera is given as Mc and Vc (camera matrix and camera vector, respectively).

When going through a warping portal (mirror for example) there is also a warping matrix and two vectors, Mw, Vw1 and Vw2. Vw1 is the vector that is applied before Mw and Vw2 is applied after Mw. The warping transformation is a transformation in world space. For example, if you have the following sector:

 
       A
  +---------+       z
  |         |       ^
  |         |       |
D |    o    | B     o-->x
  |         |
  |         |
  +---------+
       C

With point o at (0,0,0) and the B side a mirror. Let's say that B is 2 units to the right of o. The warping matrix/vector would then be:

 
      /-1 0 0 \          / 2 \           / 2 \
Mw =  | 0 1 0 |    Vw1 = | 0 |     Vw2 = | 0 |
      \ 0 0 1 /          \ 0 /           \ 0 /

The mirror swaps along the X-axis.

How is this transformation then used?

To know how this works we should understand that Mc and Vc (the camera transformation) is a transformation from world space to camera space. Since the warping transformation is in world space we first have to apply Mw / Vw before Mc / Vc.

So we want to make a new camera transformation matrix/vector that we are then going to use for the recursive rendering of the sector behind the mirror. Let's call this Mc' and Vc'.

The camera transformation is used like this in Crystal Space:

C = Mc * (W - Vc)

(Equation 1)

Where C is the camera space coordinates and W is the world space coordinates.

But first we want to transform world space using the warping transformation:

W' = Mw * (W - Vw1) + Vw2

(Equation 2)

It is important to realize that the Mw / Vwn transformation is used a little differently here. The Vw1 vector is used to translate to the warping polygon first and Vw2 is used to go back when the matrix Mw has done its work. This is just how Crystal Space does it. One could use other matrices/vectors to express the warping transformations.

Combining equations (1) and (2), but replacing W by W' in (1), gives:

C = Mc * (Mw * (W - Vw1) + Vw2 - Vc)
C = Mc * Mw * ((W - Vw1) - 1 / Mw * (Vc - Vw2))
C = Mc * Mw * (W - (Vw1 + 1 / Mw * (Vc - Vw2)))

And this is the new camera transformation:

Mc' = Mc * Mw
Vc' = Vw1 + 1 / Mw * (Vc - Vw2)

In summary, the warping transformation works by first transforming world space to a new warped world space. The new camera transformation is made by combining the warping transformation with the old camera transformation.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated using texi2html 1.76.