File: cs_176.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 (207 lines) | stat: -rw-r--r-- 7,428 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<!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: Texture Mapping Concepts</TITLE>

<META NAME="description" CONTENT="Crystal Space: Texture Mapping Concepts">
<META NAME="keywords" CONTENT="Crystal Space: Texture Mapping Concepts">
<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="SEC379"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_175.html#SEC378"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_177.html#SEC383"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_173.html#SEC376"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_174.html#SEC377"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_181.html#SEC390"> &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>
<H4> 7.6.6.2 General Concepts </H4>
<!--docid::SEC379::-->
<P>

This section describes general core concepts which are used by following
discussions.
</P><P>

<A NAME="SEC380"></A>
<H4> Polygon </H4>
<!--docid::SEC380::-->
<P>

A polygon is represented as a set of 3D vertices oriented in clockwise order
(if the orientation is different, the polygon is not visible on screen).
There are three versions of any polygon:
</P><P>

<OL>
<LI>
<EM>Po</EM> is the polygon in object space.  Here the vertices of the polygon are
given in object space coordinates.
<P>

<LI>
<EM>Pw</EM> is the polygon in world space.  For a sector world space is equal to
object space but for a thing there is a transformation from object space to
world space given as:
<P>

<BLOCKQUOTE>
<EM>Vw = Mow * Vo - Vow</EM>
</BLOCKQUOTE>
<P>

This means that the vertex in world space coordinates (<EM>Vw</EM>) is given as
the vertex in object space coordinates (<EM>Vo</EM>) transformed by the matrix
from object to world space (<EM>Mow</EM>) and the vector from object to world
space (<EM>Vow</EM>).
</P><P>

This transformation is recomputed whenever a thing moves.
</P><P>

<LI>
<EM>Pc</EM> is the polygon in camera space.  Before viewing, every relevant
vertex is transformed from world space to camera space using the following
equation:
<P>

<BLOCKQUOTE>
<EM>Vc = Mwc * (Vw - Vwc)</EM>
</BLOCKQUOTE>
</OL>
<P>

Note, all three versions of a polygon are represented by the same
`<SAMP>csPolygon3D</SAMP>' object.  The change from object to world and world to
camera space happens inside the Vertex class that is referenced by
`<SAMP>csPolygon3D</SAMP>'.
</P><P>

Associated with every polygon there is also a plane normal or plane equation:
</P><P>

<BLOCKQUOTE>
<EM>N: A * x + B * y + C * z + D = 0</EM>
</BLOCKQUOTE>
<P>

There are also three versions of this plane equation; one for object space,
one for world space, and one for camera space:
</P><P>

<BLOCKQUOTE>
<EM>No: Ao * x + Bo * y + Co * z + Do = 0</EM><BR>
<EM>Nw: Aw * x + Bw * y + Cw * z + Dw = 0</EM><BR>
<EM>Nc: Ac * x + Bc * y + Cc * z + Dc = 0</EM>
</BLOCKQUOTE>
<P>

<A NAME="SEC381"></A>
<H4> Camera </H4>
<!--docid::SEC381::-->
<P>

A camera is represented as a matrix (<EM>Mwc</EM>) and a vector (<EM>Vwc</EM>).  In
fact the camera describes the transformation between world and camera space.
The inverse transformation (<EM>Mcw</EM>) from camera space to world space is
also kept inside a `<SAMP>csCamera</SAMP>' object because it can be used for movement
(for example, to move forward one would want to move forward along the Z-axis
in camera space and not in world space).
</P><P>

<A NAME="SEC382"></A>
<H4> Texture </H4>
<!--docid::SEC382::-->
<P>

There is also a texture associated with every polygon (unless it is a portal
with no overlay).  The texture represents a 2-dimensional rectangular space
where (0,0) is one corner of the texture and (1,1) is the opposite corner.  If
a texture is overlayed onto a rectangular polygon such that one corner is
mapped onto (0,0) in texture space and the opposite corner is mapped onto
(2,2) then the texture will be tiled four times across the surface of the
polygon.
</P><P>

To transform object to texture space we have the following equation:
</P><P>

<BLOCKQUOTE>
<EM>Vt = Mot * (Vo - Vot)</EM>
</BLOCKQUOTE>
<P>

Similarly for world space:
</P><P>

<BLOCKQUOTE>
<EM>Vt = Mwt * (Vw - Vwt)</EM>
</BLOCKQUOTE>
<P>

And for camera space:
</P><P>

<BLOCKQUOTE>
<EM>Vt = Mct * (Vc - Vct)</EM>
</BLOCKQUOTE>
<P>

So, just as there are three versions of the polygon (<EM>Po</EM>, <EM>Pw</EM>, and
<EM>Pc</EM>) and three plane equations, we also have three equations transforming
the various spaces to the texture.  <EM>Mot</EM> and <EM>Vot</EM> (object to texture
space) are fixed (calculated at load time).  <EM>Mwt</EM> and <EM>Vwt</EM> (world to
texture space) are the same for sectors but for things they are calculated
whenever a thing moves.  <EM>Mct</EM> and <EM>Vct</EM> (camera to texture space) are
calculated every time the corresponding polygon is visible and needs to be
drawn on screen.
</P><P>

Note that the texture transformation matrix is actually a transformation from
3D to 3D.  We simply don't use the Z component in texture space (it is just
ignored).
</P><P>

<A NAME="Texture Mapping Perspective Correction"></A>
<HR SIZE=1>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_175.html#SEC378"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_177.html#SEC383"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_173.html#SEC376"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_174.html#SEC377"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_181.html#SEC390"> &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>