File: cs_205.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 (264 lines) | stat: -rw-r--r-- 8,890 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<!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: MeshObject Spr2D</TITLE>

<META NAME="description" CONTENT="Crystal Space: MeshObject Spr2D">
<META NAME="keywords" CONTENT="Crystal Space: MeshObject Spr2D">
<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="SEC464"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_204.html#SEC463"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_206.html#SEC471"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_196.html#SEC414"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_201.html#SEC452"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_220.html#SEC543"> &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.8.4 Sprite2D Mesh Object </H3>
<!--docid::SEC464::-->
<P>

<EM>Written by Jorrit Tyberghein,
(<A HREF="mailto:jorrit.tyberghein@uz.kuleuven.ac.be">jorrit.tyberghein@uz.kuleuven.ac.be</A>).</EM>
</P><P>

A 2D Sprite is basically a polygon that always faces the camera.  There are
some special effects that you can do with this but it is really very simple
otherwise.
</P><P>

<A NAME="SEC465"></A>
<H4> Basic Structure </H4>
<!--docid::SEC465::-->
<P>

The following SCF class names are used (for <CODE>CS_LOAD_PLUGIN()</CODE>):
</P><P>

<UL>
<LI>
Type plugin: `<SAMP>crystalspace.mesh.object.sprite.2d</SAMP>'
<LI>
Loader plugin: `<SAMP>crystalspace.mesh.loader.sprite.2d</SAMP>'
<LI>
Factory loader plugin: `<SAMP>crystalspace.mesh.loader.factory.sprite.2d</SAMP>'
</UL>
<P>

Objects in this plugin implement the following SCF interfaces (get with
<CODE>SCF_QUERY_INTERFACE()</CODE>):
</P><P>

<UL>
<LI>
<EM>MeshObject</EM>
<UL>
<LI>
Implements `<SAMP>iMeshObject</SAMP>'
<LI>
Implements `<SAMP>iSprite2DState</SAMP>'
<LI>
Implements `<SAMP>iParticle</SAMP>'
</UL>
<LI>
<EM>MeshObjectFactory</EM>
<UL>
<LI>
Implements `<SAMP>iMeshObjectFactory</SAMP>'
<LI>
Implements `<SAMP>iSprite2DFactoryState</SAMP>'
</UL>
<LI>
<EM>MeshObjectFactory</EM>
<UL>
<LI>
Implements `<SAMP>iMeshObjectType</SAMP>'
</UL>
</UL>
<P>

<A NAME="SEC466"></A>
<H4> Factory State Interface </H4>
<!--docid::SEC466::-->
<P>

Use the SCF interface `<SAMP>iSprite2DFactoryState</SAMP>' to acccess settings for
a 2D sprite factory.  The definition of this interface can be found in
`<TT>CS/include/imesh/sprite2d.h</TT>' and that is also the include file you need
to include in your applications to use this plugin.  Using this interface you
can access the material, blending mode (mixmode), and lighting settings.
</P><P>

<A NAME="SEC467"></A>
<H4> Factory Loader </H4>
<!--docid::SEC467::-->
<P>

<DL COMPACT>
<DT><CODE>LIGHTING(boolean)</CODE>
<DD>Enable/disable lighting.
<DT><CODE>MATERIAL(materialName)</CODE>
<DD>Material to use for the polygon.
<DT><CODE>MIXMODE(mode)</CODE>
<DD>Blending mode; one of `<SAMP>ADD</SAMP>', `<SAMP>ALPHA</SAMP>', `<SAMP>COPY</SAMP>', `<SAMP>KEYCOLOR</SAMP>',
`<SAMP>MULTIPLY2</SAMP>', `<SAMP>MULTIPLY</SAMP>', or `<SAMP>TRANSPARENT</SAMP>'.
<DT><CODE>UVANIMATION(FRAME (<small>...</small>) <small>...</small>)</CODE>
<DD>Define an uv animation, that is a sequence of frames which textures are all in
one big texture.  Thus the animation is achieved by altering the (u,v)
coordinates of the polygon defined by this sprite.
<DT><CODE>FRAME(ms,vertices <small>...</small>)</CODE>
<DD>Defines a single frame within an uv animation by specifying its duration in
milliseconds and the u,v coordinates to use.
<UL>
FRAME 'framename' (millisec, u,v coo list)
</UL>
</DL>
<P>

<A NAME="SEC468"></A>
<H4> Object State Interface </H4>
<!--docid::SEC468::-->
<P>

`<SAMP>iSprite2DState</SAMP>' is the SCF interface that you can use to set/get
settings for a 2D sprite object.  The definition of this interface can be found
in `<TT>CS/include/imesh/sprite2d.h</TT>' and that is also the include file you
need to include in your applications to use this plugin.  Using this
interface you can access the material, blending mode (mixmode), lighting
settings, and also the vertices of the 2D polygon controlled by this plugin.
</P><P>

<A NAME="SEC469"></A>
<H4> Object Loader </H4>
<!--docid::SEC469::-->
<P>

<DL COMPACT>
<DT><CODE>FACTORY</CODE>
<DD>Name of the factory to use for creation of this instance.
<DT><CODE>MIXMODE</CODE>
<DD>Blending mode, one of `<SAMP>ADD</SAMP>', `<SAMP>ALPHA</SAMP>', `<SAMP>COPY</SAMP>', `<SAMP>KEYCOLOR</SAMP>',
`<SAMP>MULTIPLY2</SAMP>', `<SAMP>MULTIPLY</SAMP>', or `<SAMP>TRANSPARENT</SAMP>'.
<DT><CODE>MATERIAL</CODE>
<DD>Material to use for the polygon.
<DT><CODE>LIGHTING</CODE>
<DD>Enable/disable lighting.
<DT><CODE>VERTICES</CODE>
<DD>List of 2D vertices defining the polygon.
<DT><CODE>UV</CODE>
<DD>List of texture mapping UV coordinates for the polygon.
<DT><CODE>COLORS</CODE>
<DD>List of rgb colors for the polygon.
<DT><CODE>ANIMATE</CODE>
<DD>Select an uv animation from the list of animations declared in the template
<UL>
ANIMATE ('ani name', timing, loop)
<UL>
<LI>
timing &#62; 0 : every &#60;timing&#62; milliseconds the next frame will be shown
<LI>
timing &#60; 0 : every &#60;-timing&#62; gameloop the next frame will be shown
<LI>
timing = 0 : timing attached to the frame will be used
<LI>
loop : loop the animation or stop after last frame (and show the last frame)
</UL>
</UL>
</DL>
<P>

<A NAME="SEC470"></A>
<H4> Example 1 </H4>
<!--docid::SEC470::-->
<P>

This is how our world file looks:
</P><P>

<TABLE><tr><td>&nbsp;</td><td class=example><pre>WORLD (
  TEXTURES (
    TEXTURE 'blow' (FILE(blow.png))
  )

  MATERIALS (
    MATERIAL 'explosion' (TEXTURE ('blow'))
  )

  MESHOBJ 'Explosion' (
    PLUGIN ('crystalspace.mesh.loader.factory.sprite.2d')
    PARAMS (
      MATERIAL ('explosion')
      UVANIMATION 'boom' (
        FRAME 'f1' ( 100, 0, 0, 0.5, 0, 0.5, 0.5, 0, 0.5)
        FRAME 'f2' ( 100, 0.5, 0, 1, 0, 1, 0.5, 0.5, 0.5)
        FRAME 'f3' ( 100, 0, 0.5, 0.5, 0.5, 0.5, 1, 0, 1)
        FRAME 'f4' ( 100, 0.5, 0.5, 1, 0.5, 1, 1, 0.5, 1)
      )
    )
  )

  sector 'space' (
    ; define all the stuff in space
    ; ...
    ; and now one of the enemies right after we met him
    MESHOBJ 'kaboom' (
      PLUGIN ('crystalspace.mesh.loader.sprite.2d')
      PARAMS (
        FACTORY ('Explosion')
        VERTICES (-1,1,1,1,1,-1,-1,-1)
        UV (0,0,1,0,1,1,0,1)
        COLORS (1,1,1,1,1,1,1,1,1,1,1,1)
	LIGHTING (no)
        ; show the animation, use the timings attached to
	; the frames, loop
        ANIMATE ('boom', 0, yes)
      )
      MOVE (0,0,0)
    )
  )  
)

</pre></td></tr></table><A NAME="MeshObject Spr3D"></A>
<HR SIZE=1>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_204.html#SEC463"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_206.html#SEC471"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_196.html#SEC414"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_201.html#SEC452"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_220.html#SEC543"> &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>