diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llsprite.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llsprite.cpp')
-rw-r--r-- | linden/indra/newview/llsprite.cpp | 315 |
1 files changed, 315 insertions, 0 deletions
diff --git a/linden/indra/newview/llsprite.cpp b/linden/indra/newview/llsprite.cpp new file mode 100644 index 0000000..601810c --- /dev/null +++ b/linden/indra/newview/llsprite.cpp | |||
@@ -0,0 +1,315 @@ | |||
1 | /** | ||
2 | * @file llsprite.cpp | ||
3 | * @brief LLSprite class implementation | ||
4 | * | ||
5 | * Copyright (c) 2000-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | /* -*- c++ -*- | ||
29 | * Notes: | ||
30 | * PR - Should add a creator that can take a pointer rather than handle for streaming | ||
31 | * object textures. | ||
32 | * PR - Need to add support for lit/non-lit conditions, set normals? | ||
33 | */ | ||
34 | |||
35 | #include "llviewerprecompiledheaders.h" | ||
36 | |||
37 | #include <llglheaders.h> | ||
38 | |||
39 | #include "llsprite.h" | ||
40 | |||
41 | #include "math.h" | ||
42 | |||
43 | #include "lldrawable.h" | ||
44 | #include "llface.h" | ||
45 | #include "llviewercamera.h" | ||
46 | #include "llviewerimagelist.h" | ||
47 | #include "viewer.h" | ||
48 | |||
49 | LLVector3 LLSprite::sCameraUp(0.0f,0.0f,1.0f); | ||
50 | LLVector3 LLSprite::sCameraRight(1.0f,0.0f,0.0f); | ||
51 | LLVector3 LLSprite::sCameraPosition(0.f, 0.f, 0.f); | ||
52 | LLVector3 LLSprite::sNormal(0.0f,0.0f,0.0f); | ||
53 | |||
54 | ////////////////////////////////////////////////////////////////////// | ||
55 | // Construction/Destruction | ||
56 | ////////////////////////////////////////////////////////////////////// | ||
57 | |||
58 | // A simple initialization | ||
59 | LLSprite::LLSprite(const LLUUID &image_uuid) | ||
60 | { | ||
61 | mImageID = image_uuid; | ||
62 | mImagep = NULL; | ||
63 | |||
64 | setSize(1.0f, 1.0f); | ||
65 | setPosition(LLVector3(0.0f, 0.0f, 0.0f)); | ||
66 | mTexMode = GL_REPLACE; | ||
67 | mColor.setVec(0.5f, 0.5f, 0.5f, 1.0f); | ||
68 | mFollow = TRUE; | ||
69 | mUseCameraUp = TRUE; | ||
70 | } | ||
71 | |||
72 | LLSprite::LLSprite(const LLUUID &image_uuid, const F32 width, const F32 height, const BOOL b_usemipmap) | ||
73 | { | ||
74 | mImageID = image_uuid; | ||
75 | mImagep = NULL; | ||
76 | |||
77 | setSize(width,height); | ||
78 | setPosition(LLVector3(0.0f, 0.0f, 0.0f)); | ||
79 | mTexMode = GL_REPLACE; | ||
80 | mColor.setVec(0.5f, 0.5f, 0.5f, 1.0f); | ||
81 | mFollow = TRUE; | ||
82 | mUseCameraUp = TRUE; | ||
83 | } | ||
84 | |||
85 | ////////////////////////////////////////////////////////////////////// | ||
86 | LLSprite::~LLSprite() | ||
87 | { | ||
88 | } | ||
89 | |||
90 | void LLSprite::updateFace(LLFace &face) | ||
91 | { | ||
92 | LLViewerCamera &camera = *gCamera; | ||
93 | |||
94 | // First, figure out how many vertices/indices we need. | ||
95 | U32 num_vertices, num_indices; | ||
96 | U32 vertex_count = 0; | ||
97 | |||
98 | |||
99 | LLStrider<LLVector3> verticesp; | ||
100 | LLStrider<LLVector3> normalsp; | ||
101 | LLStrider<LLVector2> tex_coordsp; | ||
102 | U32 *indicesp; | ||
103 | S32 index_offset; | ||
104 | |||
105 | // Get the total number of vertices and indices | ||
106 | if (mFollow) | ||
107 | { | ||
108 | num_vertices = 4; | ||
109 | num_indices = 6; | ||
110 | } | ||
111 | else | ||
112 | { | ||
113 | num_vertices = 4; | ||
114 | num_indices = 12; | ||
115 | } | ||
116 | |||
117 | // Setup face | ||
118 | face.setPrimType(LLTriangles); | ||
119 | face.setSize(num_vertices, num_indices); | ||
120 | index_offset = face.getGeometry(verticesp,normalsp,tex_coordsp, indicesp); | ||
121 | if (-1 == index_offset) | ||
122 | { | ||
123 | return; | ||
124 | } | ||
125 | |||
126 | if (mFollow) | ||
127 | { | ||
128 | sCameraUp = camera.getUpAxis(); | ||
129 | sCameraRight = -camera.getLeftAxis(); | ||
130 | sCameraPosition = camera.getOrigin(); | ||
131 | sNormal = -camera.getAtAxis(); | ||
132 | if (mUseCameraUp) | ||
133 | { | ||
134 | // these need to live here because the height/width may change between render calls | ||
135 | mScaledUp = sCameraUp; | ||
136 | mScaledRight = sCameraRight; | ||
137 | |||
138 | mScaledUp *= mHeightDiv2; | ||
139 | mScaledRight *= mWidthDiv2; | ||
140 | |||
141 | mA = mPosition + mScaledRight + mScaledUp; | ||
142 | mB = mPosition - mScaledRight + mScaledUp; | ||
143 | mC = mPosition - mScaledRight - mScaledUp; | ||
144 | mD = mPosition + mScaledRight - mScaledUp; | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | // The up vector is perpendicular to the camera vector... | ||
149 | LLVector3 camera_vec = mPosition - sCameraPosition; | ||
150 | mScaledRight = camera_vec % LLVector3(0.f, 0.f, 1.f); | ||
151 | mScaledUp = -(camera_vec % mScaledRight); | ||
152 | mScaledUp.normVec(); | ||
153 | mScaledRight.normVec(); | ||
154 | mScaledUp *= mHeightDiv2; | ||
155 | mScaledRight *= mWidthDiv2; | ||
156 | |||
157 | mA = mPosition + mScaledRight + mScaledUp; | ||
158 | mB = mPosition - mScaledRight + mScaledUp; | ||
159 | mC = mPosition - mScaledRight - mScaledUp; | ||
160 | mD = mPosition + mScaledRight - mScaledUp; | ||
161 | } | ||
162 | } | ||
163 | else | ||
164 | { | ||
165 | // this is equivalent to how it was done before. . . | ||
166 | // we need to establish a way to | ||
167 | // identify the orientation of a particular sprite rather than | ||
168 | // just banging it in on the x,z plane if it's not following the camera. | ||
169 | |||
170 | LLVector3 x_axis; | ||
171 | LLVector3 y_axis; | ||
172 | |||
173 | F32 dot = sNormal * LLVector3(0.f, 1.f, 0.f); | ||
174 | if (dot == 1.f || dot == -1.f) | ||
175 | { | ||
176 | x_axis.setVec(1.f, 0.f, 0.f); | ||
177 | y_axis.setVec(0.f, 1.f, 0.f); | ||
178 | } | ||
179 | else | ||
180 | { | ||
181 | x_axis = sNormal % LLVector3(0.f, -1.f, 0.f); | ||
182 | x_axis.normVec(); | ||
183 | |||
184 | y_axis = sNormal % x_axis; | ||
185 | } | ||
186 | |||
187 | LLQuaternion yaw_rot(mYaw, sNormal); | ||
188 | |||
189 | // rotate axes by specified yaw | ||
190 | x_axis = x_axis * yaw_rot; | ||
191 | y_axis = y_axis * yaw_rot; | ||
192 | |||
193 | // rescale axes by width and height of sprite | ||
194 | x_axis = x_axis * mWidthDiv2; | ||
195 | y_axis = y_axis * mHeightDiv2; | ||
196 | |||
197 | mA = -x_axis + y_axis; | ||
198 | mB = x_axis + y_axis; | ||
199 | mC = x_axis - y_axis; | ||
200 | mD = -x_axis - y_axis; | ||
201 | |||
202 | mA += mPosition; | ||
203 | mB += mPosition; | ||
204 | mC += mPosition; | ||
205 | mD += mPosition; | ||
206 | } | ||
207 | |||
208 | face.setFaceColor(mColor); | ||
209 | |||
210 | *tex_coordsp = LLVector2(0.f, 0.f); | ||
211 | *verticesp = mC; | ||
212 | tex_coordsp++; | ||
213 | verticesp++; | ||
214 | vertex_count++; | ||
215 | |||
216 | *tex_coordsp = LLVector2(0.f, 1.f); | ||
217 | *verticesp = mB; | ||
218 | tex_coordsp++; | ||
219 | verticesp++; | ||
220 | vertex_count++; | ||
221 | |||
222 | *tex_coordsp = LLVector2(1.f, 1.f); | ||
223 | *verticesp = mA; | ||
224 | tex_coordsp++; | ||
225 | verticesp++; | ||
226 | vertex_count++; | ||
227 | |||
228 | *tex_coordsp = LLVector2(1.f, 0.0f); | ||
229 | *verticesp = mD; | ||
230 | tex_coordsp++; | ||
231 | verticesp++; | ||
232 | vertex_count++; | ||
233 | |||
234 | // Generate indices, since they're easy. | ||
235 | // Just a series of quads. | ||
236 | *indicesp++ = index_offset; | ||
237 | *indicesp++ = 2 + index_offset; | ||
238 | *indicesp++ = 1 + index_offset; | ||
239 | |||
240 | *indicesp++ = index_offset; | ||
241 | *indicesp++ = 3 + index_offset; | ||
242 | *indicesp++ = 2 + index_offset; | ||
243 | |||
244 | if (!mFollow) | ||
245 | { | ||
246 | *indicesp++ = 0 + index_offset; | ||
247 | *indicesp++ = 1 + index_offset; | ||
248 | *indicesp++ = 2 + index_offset; | ||
249 | *indicesp++ = 0 + index_offset; | ||
250 | *indicesp++ = 2 + index_offset; | ||
251 | *indicesp++ = 3 + index_offset; | ||
252 | } | ||
253 | |||
254 | face.mCenterAgent = mPosition; | ||
255 | } | ||
256 | |||
257 | void LLSprite::setPosition(const LLVector3 &position) | ||
258 | { | ||
259 | mPosition = position; | ||
260 | } | ||
261 | |||
262 | |||
263 | void LLSprite::setPitch(const F32 pitch) | ||
264 | { | ||
265 | mPitch = pitch; | ||
266 | } | ||
267 | |||
268 | |||
269 | void LLSprite::setSize(const F32 width, const F32 height) | ||
270 | { | ||
271 | mWidth = width; | ||
272 | mHeight = height; | ||
273 | mWidthDiv2 = width/2.0f; | ||
274 | mHeightDiv2 = height/2.0f; | ||
275 | } | ||
276 | |||
277 | void LLSprite::setYaw(F32 yaw) | ||
278 | { | ||
279 | mYaw = yaw; | ||
280 | } | ||
281 | |||
282 | void LLSprite::setFollow(const BOOL follow) | ||
283 | { | ||
284 | mFollow = follow; | ||
285 | } | ||
286 | |||
287 | void LLSprite::setUseCameraUp(const BOOL use_up) | ||
288 | { | ||
289 | mUseCameraUp = use_up; | ||
290 | } | ||
291 | |||
292 | void LLSprite::setTexMode(const LLGLenum mode) | ||
293 | { | ||
294 | mTexMode = mode; | ||
295 | } | ||
296 | |||
297 | void LLSprite::setColor(const LLColor4 &color) | ||
298 | { | ||
299 | mColor = color; | ||
300 | } | ||
301 | |||
302 | void LLSprite::setColor(const F32 r, const F32 g, const F32 b, const F32 a) | ||
303 | { | ||
304 | mColor.setVec(r, g, b, a); | ||
305 | } | ||
306 | |||
307 | |||
308 | |||
309 | |||
310 | |||
311 | |||
312 | |||
313 | |||
314 | |||
315 | |||