File: cs_173.html

package info (click to toggle)
crystalspace 0.94-20020412-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 62,276 kB
  • ctags: 52,843
  • sloc: cpp: 274,783; ansic: 6,608; perl: 6,276; objc: 3,952; asm: 2,942; python: 2,354; php: 542; pascal: 530; sh: 430; makefile: 370; awk: 193
file content (184 lines) | stat: -rw-r--r-- 6,968 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Created by texi2html 1.64 -->
<!-- 
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
 
-->
<HTML>
<HEAD>
<TITLE>Crystal Space: Space Warping</TITLE>

<META NAME="description" CONTENT="Crystal Space: Space Warping">
<META NAME="keywords" CONTENT="Crystal Space: Space Warping">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="texi2html 1.64">

</HEAD>

<BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">

<A NAME="SEC376"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_172.html#SEC373"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_174.html#SEC377"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_167.html#SEC358"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_168.html#SEC359"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_196.html#SEC414"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC711">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<HR SIZE=1>
<H3> 7.6.5 Space Warping </H3>
<!--docid::SEC376::-->
<P>

<EM>Written by Jorrit Tyberghein,
<A HREF="mailto:jorrit.tyberghein@uz.kuleuven.ac.be">jorrit.tyberghein@uz.kuleuven.ac.be</A>.  Mathematical typesetting for
TeX performed by Eric Sunshine, <A HREF="mailto:sunshine@sunshineco.com">sunshine@sunshineco.com</A>.</EM>
</P><P>

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

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

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

<TABLE><tr><td>&nbsp;</td><td class=example><pre>       A
  +---------+       z
  |         |       ^
  |         |       |
D |    o    | B     o--&#62;x
  |         |
  |         |
  +---------+
       C
</pre></td></tr></table></P><P>

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

<TABLE><tr><td>&nbsp;</td><td class=example><pre>      /-1 0 0 \          / 2 \           / 2 \
Mw =  | 0 1 0 |    Vw1 = | 0 |     Vw2 = | 0 |
      \ 0 0 1 /          \ 0 /           \ 0 /
</pre></td></tr></table></P><P>

The mirror swaps along the X-axis.
</P><P>

How is this transformation then used?
</P><P>

To know how this works we should understand that
<EM>Mc</EM> and <EM>Vc</EM>
(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
<EM>Mw / Vw</EM> before <EM>Mc / Vc</EM>.
</P><P>

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
<EM>Mc'</EM> and <EM>Vc'</EM>.
</P><P>

The camera transformation is used like this in Crystal Space:
</P><P>

<BLOCKQUOTE>
<TABLE>
<TR><TD><EM>C = Mc * (W - Vc)</EM> </TD><TD> (Equation 1)</TD>
</TR></TABLE>
</BLOCKQUOTE>
<P>

Where <EM>C</EM> is the camera space coordinates and <EM>W</EM> is the world space
coordinates.
</P><P>

But first we want to transform world space using the warping transformation:
</P><P>

<BLOCKQUOTE>
<TABLE>
<TR><TD><EM>W' = Mw * (W - Vw1) + Vw2</EM> </TD><TD> (Equation 2)</TD>
</TR></TABLE>
</BLOCKQUOTE>
<P>

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

Combining equations (1) and (2), but replacing <EM>W</EM> by <EM>W'</EM> in (1),
gives:
</P><P>

<BLOCKQUOTE>
<EM>C = Mc * (Mw * (W - Vw1) + Vw2 - Vc)</EM><BR>
<EM>C = Mc * Mw * ((W - Vw1) - 1 / Mw * (Vc - Vw2))</EM><BR>
<EM>C = Mc * Mw * (W - (Vw1 + 1 / Mw * (Vc - Vw2)))</EM>
</BLOCKQUOTE>
<P>

And this is the new camera transformation:
</P><P>

<BLOCKQUOTE>
<EM>Mc' = Mc * Mw</EM><BR>
<EM>Vc' = Vw1 + 1 / Mw * (Vc - Vw2)</EM>
</BLOCKQUOTE>
<P>

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.
</P><P>

<A NAME="Texture Mapping"></A>
<HR SIZE=1>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_172.html#SEC373"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_174.html#SEC377"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_167.html#SEC358"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_168.html#SEC359"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_196.html#SEC414"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC711">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<BR>  
<FONT SIZE="-1">
This document was generated

using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
"><I>texi2html</I></A>

</BODY>
</HTML>