File: cs_179.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 (153 lines) | stat: -rw-r--r-- 5,561 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
<!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 Instructions</TITLE>

<META NAME="description" CONTENT="Crystal Space: Texture Mapping Instructions">
<META NAME="keywords" CONTENT="Crystal Space: Texture Mapping Instructions">
<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="SEC385"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_178.html#SEC384"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_180.html#SEC386"> &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.5 Instructions for Texture Mapper </H4>
<!--docid::SEC385::-->
<P>

In the Crystal Space map file,
the `<SAMP>ORIG</SAMP>', `<SAMP>FIRST</SAMP>', and `<SAMP>SECOND</SAMP>' vertex keywords describe the
texture plane.  What Crystal Space does internally is to create a
transformation matrix/vector which translates object space (3D coordinates) to
texture space (<EM>u,v</EM> coordinates).  Here is how this works.
</P><P>

First a few definitions:
</P><P>

<UL>
<LI>
<CODE>ORIG</CODE> vector is <EM>Vo</EM>
<LI>
<CODE>FIRST</CODE> vector is <EM>V1</EM>
<LI>
<CODE>SECOND</CODE> vector is <EM>V2</EM>
<LI>
<CODE>FIRST_LEN</CODE> is <EM>L1</EM>
<LI>
<CODE>SECOND_LEN</CODE> is <EM>L2</EM>
<LI>
Length of
<EM>V1 - Vo</EM>
is <EM>l1</EM>
<LI>
Length of
<EM>V2 - Vo</EM>
is <EM>l2</EM>
</UL>
<P>

<EM>Vo</EM>, <EM>V1</EM> and <EM>V2</EM> are vertices in object space.  These define
the local coordinate system for texture space.  So we have the following
mapping:
</P><P>

<BLOCKQUOTE>
<EM>Vo</EM> ==> (<EM>0</EM>,<EM>0</EM>)<BR>
<EM>V1</EM> ==> (<EM>L1</EM>,<EM>0</EM>)<BR>
<EM>V2</EM> ==> (<EM>0</EM>,<EM>L2</EM>)
</BLOCKQUOTE>
<P>

It is important to realize that the coordinate (0,0) in texture space is the
top-left coordinate of the texture and (1,1) is the bottom-right corner.  The
coordinate (2,2) is thus the bottom-right corner of a tiled texture (2x2
times).
</P><P>

The conversion to the matrix happens as follows:
</P><P>

<BLOCKQUOTE>
<EM>Vu = (len1 / l1) * (V1-Vo)</EM><BR>
<EM>Vv = (len2 / l2) * (V2-Vo)</EM>
</BLOCKQUOTE>
<TABLE><tr><td>&nbsp;</td><td class=example><pre>      / Vu.x Vv.x 1 \
Mot = | Vu.y Vv.y 1 |
      \ Vu.z Vv.z 1 /
</pre></td></tr></table><P>

The last column represents the <EM>W</EM> texture component which is not used.
</P><P>

<BLOCKQUOTE>
<EM>Vot = &#60;Vo.x Vo.y Vo.z&#62;</EM>
</BLOCKQUOTE>
<P>

So <EM>Mot</EM> and <EM>Vot</EM> are the transformation matrix/vector to go from
object to texture space.  Use these as follows:
</P><P>

<BLOCKQUOTE>
<EM>T = Mot * (O - Vot)</EM>
</BLOCKQUOTE>
<P>

With <EM>O</EM> being the object space vector that you want to convert and
<EM>T</EM> the texture space vector.  Only the <EM>x</EM> and <EM>y</EM> components
are used of <EM>T</EM>.  <EM>x</EM> represents <EM>u</EM> and <EM>y</EM> represents
<EM>v</EM>.
</P><P>

Using the last equation you can convert every point of your polygon to texture
space.
</P><P>

<A NAME="Texture Mapping Animations"></A>
<HR SIZE=1>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_178.html#SEC384"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_180.html#SEC386"> &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>