aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llprimitive/llprimitive.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llprimitive/llprimitive.h')
-rw-r--r--linden/indra/llprimitive/llprimitive.h529
1 files changed, 529 insertions, 0 deletions
diff --git a/linden/indra/llprimitive/llprimitive.h b/linden/indra/llprimitive/llprimitive.h
new file mode 100644
index 0000000..e51fdcf
--- /dev/null
+++ b/linden/indra/llprimitive/llprimitive.h
@@ -0,0 +1,529 @@
1/**
2 * @file llprimitive.h
3 * @brief LLPrimitive base class
4 *
5 * Copyright (c) 2001-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#ifndef LL_LLPRIMITIVE_H
29#define LL_LLPRIMITIVE_H
30
31#include "lluuid.h"
32#include "v3math.h"
33#include "xform.h"
34#include "message.h"
35#include "llmemory.h"
36#include "llvolume.h"
37#include "lltextureentry.h"
38
39// Moved to stdtypes.h --JC
40// typedef U8 LLPCode;
41class LLMessageSystem;
42class LLVolumeParams;
43class LLColor4;
44class LLColor3;
45class LLTextureEntry;
46class LLDataPacker;
47
48enum LLGeomType // NOTE: same vals as GL Ids
49{
50 LLInvalid = 0,
51 LLLineLoop = 2,
52 LLLineStrip = 3,
53 LLTriangles = 4,
54 LLTriStrip = 5,
55 LLTriFan = 6,
56 LLQuads = 7,
57 LLQuadStrip = 8
58};
59
60class LLVolume;
61
62/**
63 * exported constants
64 */
65extern const F32 OBJECT_CUT_MIN;
66extern const F32 OBJECT_CUT_MAX;
67extern const F32 OBJECT_CUT_INC;
68extern const F32 OBJECT_MIN_CUT_INC;
69extern const F32 OBJECT_ROTATION_PRECISION;
70
71extern const F32 OBJECT_TWIST_MIN;
72extern const F32 OBJECT_TWIST_MAX;
73extern const F32 OBJECT_TWIST_INC;
74
75// This is used for linear paths,
76// since twist is used in a slightly different manner.
77extern const F32 OBJECT_TWIST_LINEAR_MIN;
78extern const F32 OBJECT_TWIST_LINEAR_MAX;
79extern const F32 OBJECT_TWIST_LINEAR_INC;
80
81extern const F32 OBJECT_MIN_HOLE_SIZE;
82extern const F32 OBJECT_MAX_HOLE_SIZE_X;
83extern const F32 OBJECT_MAX_HOLE_SIZE_Y;
84
85// Revolutions parameters.
86extern const F32 OBJECT_REV_MIN;
87extern const F32 OBJECT_REV_MAX;
88extern const F32 OBJECT_REV_INC;
89
90
91//============================================================================
92
93// TomY: Base class for things that pack & unpack themselves
94class LLNetworkData
95{
96public:
97 // Extra parameter IDs
98 enum
99 {
100 PARAMS_FLEXIBLE = 0x10,
101 PARAMS_LIGHT = 0x20
102 };
103
104public:
105 U16 mType;
106 virtual ~LLNetworkData() {};
107 virtual BOOL pack(LLDataPacker &dp) const = 0;
108 virtual BOOL unpack(LLDataPacker &dp) = 0;
109 virtual bool operator==(const LLNetworkData& data) const = 0;
110 virtual void copy(const LLNetworkData& data) = 0;
111};
112
113extern const F32 LIGHT_MIN_RADIUS;
114extern const F32 LIGHT_DEFAULT_RADIUS;
115extern const F32 LIGHT_MAX_RADIUS;
116extern const F32 LIGHT_MIN_FALLOFF;
117extern const F32 LIGHT_DEFAULT_FALLOFF;
118extern const F32 LIGHT_MAX_FALLOFF;
119extern const F32 LIGHT_MIN_CUTOFF;
120extern const F32 LIGHT_DEFAULT_CUTOFF;
121extern const F32 LIGHT_MAX_CUTOFF;
122
123class LLLightParams : public LLNetworkData
124{
125protected:
126 LLColor4 mColor; // alpha = intensity
127 F32 mRadius;
128 F32 mFalloff;
129 F32 mCutoff;
130
131public:
132 LLLightParams();
133 /*virtual*/ BOOL pack(LLDataPacker &dp) const;
134 /*virtual*/ BOOL unpack(LLDataPacker &dp);
135 /*virtual*/ bool operator==(const LLNetworkData& data) const;
136 /*virtual*/ void copy(const LLNetworkData& data);
137
138 void setColor(const LLColor4& color) { mColor = color; mColor.clamp(); }
139 void setRadius(F32 radius) { mRadius = llclamp(radius, LIGHT_MIN_RADIUS, LIGHT_MAX_RADIUS); }
140 void setFalloff(F32 falloff) { mFalloff = llclamp(falloff, LIGHT_MIN_FALLOFF, LIGHT_MAX_FALLOFF); }
141 void setCutoff(F32 cutoff) { mCutoff = llclamp(cutoff, LIGHT_MIN_CUTOFF, LIGHT_MAX_CUTOFF); }
142
143 LLColor4 getColor() const { return mColor; }
144 F32 getRadius() const { return mRadius; }
145 F32 getFalloff() const { return mFalloff; }
146 F32 getCutoff() const { return mCutoff; }
147};
148
149//-------------------------------------------------
150// This structure is also used in the part of the
151// code that creates new flexible objects.
152//-------------------------------------------------
153
154// These were made into enums so that they could be used as fixed size
155// array bounds.
156enum EFlexibleObjectConst
157{
158 // "Softness" => [0,3], increments of 1
159 // Represents powers of 2: 0 -> 1, 3 -> 8
160 FLEXIBLE_OBJECT_MIN_SECTIONS = 0,
161 FLEXIBLE_OBJECT_DEFAULT_NUM_SECTIONS = 2,
162 FLEXIBLE_OBJECT_MAX_SECTIONS = 3
163};
164
165// "Tension" => [0,10], increments of 0.1
166extern const F32 FLEXIBLE_OBJECT_MIN_TENSION;
167extern const F32 FLEXIBLE_OBJECT_DEFAULT_TENSION;
168extern const F32 FLEXIBLE_OBJECT_MAX_TENSION;
169
170// "Drag" => [0,10], increments of 0.1
171extern const F32 FLEXIBLE_OBJECT_MIN_AIR_FRICTION;
172extern const F32 FLEXIBLE_OBJECT_DEFAULT_AIR_FRICTION;
173extern const F32 FLEXIBLE_OBJECT_MAX_AIR_FRICTION;
174
175// "Gravity" = [-10,10], increments of 0.1
176extern const F32 FLEXIBLE_OBJECT_MIN_GRAVITY;
177extern const F32 FLEXIBLE_OBJECT_DEFAULT_GRAVITY;
178extern const F32 FLEXIBLE_OBJECT_MAX_GRAVITY;
179
180// "Wind" = [0,10], increments of 0.1
181extern const F32 FLEXIBLE_OBJECT_MIN_WIND_SENSITIVITY;
182extern const F32 FLEXIBLE_OBJECT_DEFAULT_WIND_SENSITIVITY;
183extern const F32 FLEXIBLE_OBJECT_MAX_WIND_SENSITIVITY;
184
185extern const F32 FLEXIBLE_OBJECT_MAX_INTERNAL_TENSION_FORCE;
186
187extern const F32 FLEXIBLE_OBJECT_DEFAULT_LENGTH;
188extern const BOOL FLEXIBLE_OBJECT_DEFAULT_USING_COLLISION_SPHERE;
189extern const BOOL FLEXIBLE_OBJECT_DEFAULT_RENDERING_COLLISION_SPHERE;
190
191
192class LLFlexibleObjectData : public LLNetworkData
193{
194protected:
195 S32 mSimulateLOD; // 2^n = number of simulated sections
196 F32 mGravity;
197 F32 mAirFriction; // higher is more stable, but too much looks like it's underwater
198 F32 mWindSensitivity; // interacts with tension, air friction, and gravity
199 F32 mTension; //interacts in complex ways with other parameters
200 LLVector3 mUserForce; // custom user-defined force vector
201 //BOOL mUsingCollisionSphere;
202 //BOOL mRenderingCollisionSphere;
203
204public:
205 void setSimulateLOD(S32 lod) { mSimulateLOD = llclamp(lod, (S32)FLEXIBLE_OBJECT_MIN_SECTIONS, (S32)FLEXIBLE_OBJECT_MAX_SECTIONS); }
206 void setGravity(F32 gravity) { mGravity = llclamp(gravity, FLEXIBLE_OBJECT_MIN_GRAVITY, FLEXIBLE_OBJECT_MAX_GRAVITY); }
207 void setAirFriction(F32 friction) { mAirFriction = llclamp(friction, FLEXIBLE_OBJECT_MIN_AIR_FRICTION, FLEXIBLE_OBJECT_MAX_AIR_FRICTION); }
208 void setWindSensitivity(F32 wind) { mWindSensitivity = llclamp(wind, FLEXIBLE_OBJECT_MIN_WIND_SENSITIVITY, FLEXIBLE_OBJECT_MAX_WIND_SENSITIVITY); }
209 void setTension(F32 tension) { mTension = llclamp(tension, FLEXIBLE_OBJECT_MIN_TENSION, FLEXIBLE_OBJECT_MAX_TENSION); }
210 void setUserForce(LLVector3 &force) { mUserForce = force; }
211
212 S32 getSimulateLOD() const { return mSimulateLOD; }
213 F32 getGravity() const { return mGravity; }
214 F32 getAirFriction() const { return mAirFriction; }
215 F32 getWindSensitivity() const { return mWindSensitivity; }
216 F32 getTension() const { return mTension; }
217 LLVector3 getUserForce() const { return mUserForce; }
218
219 //------ the constructor for the structure ------------
220 LLFlexibleObjectData();
221 BOOL pack(LLDataPacker &dp) const;
222 BOOL unpack(LLDataPacker &dp);
223 bool operator==(const LLNetworkData& data) const;
224 void copy(const LLNetworkData& data);
225};// end of attributes structure
226
227class LLPrimitive : public LLXform
228{
229public:
230 LLPrimitive();
231 virtual ~LLPrimitive();
232
233 static LLPrimitive *createPrimitive(LLPCode p_code);
234 void init(LLPCode p_code);
235
236 void setPCode(const LLPCode pcode);
237 const LLVolume *getVolumeConst() const { return mVolumep; } // HACK for Windoze confusion about ostream operator in LLVolume
238 LLVolume *getVolume() const { return mVolumep; }
239 virtual BOOL setVolume(const LLVolumeParams &volume_params, const S32 detail, bool unique_volume = false);
240
241 // Modify texture entry properties
242 inline BOOL validTE(const U8 te_num) const;
243 const LLTextureEntry *getTE(const U8 te_num) const;
244
245 virtual void setNumTEs(const U8 num_tes);
246 virtual void setAllTETextures(const LLUUID &tex_id);
247 virtual void setTE(const U8 index, const LLTextureEntry &te);
248 virtual S32 setTEColor(const U8 te, const LLColor4 &color);
249 virtual S32 setTEColor(const U8 te, const LLColor3 &color);
250 virtual S32 setTEAlpha(const U8 te, const F32 alpha);
251 virtual S32 setTETexture(const U8 te, const LLUUID &tex_id);
252 virtual S32 setTEScale (const U8 te, const F32 s, const F32 t);
253 virtual S32 setTEScaleS(const U8 te, const F32 s);
254 virtual S32 setTEScaleT(const U8 te, const F32 t);
255 virtual S32 setTEOffset (const U8 te, const F32 s, const F32 t);
256 virtual S32 setTEOffsetS(const U8 te, const F32 s);
257 virtual S32 setTEOffsetT(const U8 te, const F32 t);
258 virtual S32 setTERotation(const U8 te, const F32 r);
259 virtual S32 setTEBumpShinyFullbright(const U8 te, const U8 bump);
260 virtual S32 setTEBumpShiny(const U8 te, const U8 bump);
261 virtual S32 setTEMediaTexGen(const U8 te, const U8 media);
262 virtual S32 setTEBumpmap(const U8 te, const U8 bump);
263 virtual S32 setTETexGen(const U8 te, const U8 texgen);
264 virtual S32 setTEShiny(const U8 te, const U8 shiny);
265 virtual S32 setTEFullbright(const U8 te, const U8 fullbright);
266 virtual S32 setTEMediaFlags(const U8 te, const U8 flags);
267 virtual BOOL setMaterial(const U8 material); // returns TRUE if material changed
268
269 void setTEArrays(const U8 size,
270 const LLUUID* image_ids,
271 const F32* scale_s,
272 const F32* scale_t);
273 void copyTEs(const LLPrimitive *primitive);
274 S32 packTEField(U8 *cur_ptr, U8 *data_ptr, U8 data_size, U8 last_face_index, EMsgVariableType type) const;
275 S32 unpackTEField(U8 *cur_ptr, U8 *buffer_end, U8 *data_ptr, U8 data_size, U8 face_count, EMsgVariableType type);
276 BOOL packTEMessage(LLMessageSystem *mesgsys) const;
277 BOOL packTEMessage(LLDataPacker &dp) const;
278 S32 unpackTEMessage(LLMessageSystem *mesgsys, char *block_name);
279 S32 unpackTEMessage(LLMessageSystem *mesgsys, char *block_name, const S32 block_num); // Variable num of blocks
280 BOOL unpackTEMessage(LLDataPacker &dp);
281
282#ifdef CHECK_FOR_FINITE
283 inline void setPosition(const LLVector3& pos);
284 inline void setPosition(const F32 x, const F32 y, const F32 z);
285 inline void addPosition(const LLVector3& pos);
286
287 inline void setAngularVelocity(const LLVector3& avel);
288 inline void setAngularVelocity(const F32 x, const F32 y, const F32 z);
289 inline void setVelocity(const LLVector3& vel);
290 inline void setVelocity(const F32 x, const F32 y, const F32 z);
291 inline void setVelocityX(const F32 x);
292 inline void setVelocityY(const F32 y);
293 inline void setVelocityZ(const F32 z);
294 inline void addVelocity(const LLVector3& vel);
295 inline void setAcceleration(const LLVector3& accel);
296 inline void setAcceleration(const F32 x, const F32 y, const F32 z);
297#else
298 // Don't override the base LLXForm operators.
299 // Special case for setPosition. If not check-for-finite, fall through to LLXform method.
300 // void setPosition(F32 x, F32 y, F32 z)
301 // void setPosition(LLVector3)
302
303 void setAngularVelocity(const LLVector3& avel) { mAngularVelocity = avel; }
304 void setAngularVelocity(const F32 x, const F32 y, const F32 z) { mAngularVelocity.setVec(x,y,z); }
305 void setVelocity(const LLVector3& vel) { mVelocity = vel; }
306 void setVelocity(const F32 x, const F32 y, const F32 z) { mVelocity.setVec(x,y,z); }
307 void setVelocityX(const F32 x) { mVelocity.mV[VX] = x; }
308 void setVelocityY(const F32 y) { mVelocity.mV[VY] = y; }
309 void setVelocityZ(const F32 z) { mVelocity.mV[VZ] = z; }
310 void addVelocity(const LLVector3& vel) { mVelocity += vel; }
311 void setAcceleration(const LLVector3& accel) { mAcceleration = accel; }
312 void setAcceleration(const F32 x, const F32 y, const F32 z) { mAcceleration.setVec(x,y,z); }
313#endif
314
315 const LLPCode getPCode() const { return mPrimitiveCode; }
316 const char * getPCodeString() const { return pCodeToString(mPrimitiveCode); }
317 const LLVector3& getAngularVelocity() const { return mAngularVelocity; }
318 const LLVector3& getVelocity() const { return mVelocity; }
319 const LLVector3& getAcceleration() const { return mAcceleration; }
320 const U8 getNumTEs() const { return mNumTEs; }
321
322 const U8 getMaterial() const { return mMaterial; }
323
324 void setVolumeType(const U8 code);
325 U8 getVolumeType();
326
327 void setTextureList(LLTextureEntry *listp);
328
329 inline BOOL isAvatar() const;
330
331 static const char *pCodeToString(const LLPCode pcode);
332 static LLPCode legacyToPCode(const U8 legacy);
333 static U8 pCodeToLegacy(const LLPCode pcode);
334
335 inline static BOOL isPrimitive(const LLPCode pcode);
336 inline static BOOL isApp(const LLPCode pcode);
337
338protected:
339 LLPCode mPrimitiveCode; // Primitive code
340 LLVector3 mVelocity; // how fast are we moving?
341 LLVector3 mAcceleration; // are we under constant acceleration?
342 LLVector3 mAngularVelocity; // angular velocity
343 LLPointer<LLVolume> mVolumep;
344 LLTextureEntry *mTextureList; // list of texture GUIDs, scales, offsets
345 U8 mMaterial; // Material code
346 U8 mNumTEs; // # of faces on the primitve
347};
348
349inline BOOL LLPrimitive::isAvatar() const
350{
351 return mPrimitiveCode == LL_PCODE_LEGACY_AVATAR;
352}
353
354// static
355inline BOOL LLPrimitive::isPrimitive(const LLPCode pcode)
356{
357 LLPCode base_type = pcode & LL_PCODE_BASE_MASK;
358
359 if (base_type && (base_type < LL_PCODE_APP))
360 {
361 return TRUE;
362 }
363 return FALSE;
364}
365
366// static
367inline BOOL LLPrimitive::isApp(const LLPCode pcode)
368{
369 LLPCode base_type = pcode & LL_PCODE_BASE_MASK;
370
371 return (base_type == LL_PCODE_APP);
372}
373
374
375#ifdef CHECK_FOR_FINITE
376// Special case for setPosition. If not check-for-finite, fall through to LLXform method.
377void LLPrimitive::setPosition(const F32 x, const F32 y, const F32 z)
378{
379 if (llfinite(x) && llfinite(y) && llfinite(z))
380 {
381 LLXform::setPosition(x, y, z);
382 }
383 else
384 {
385 llerrs << "Non Finite in LLPrimitive::setPosition(x,y,z) for " << pCodeToString(mPrimitiveCode) << llendl;
386 }
387}
388
389// Special case for setPosition. If not check-for-finite, fall through to LLXform method.
390void LLPrimitive::setPosition(const LLVector3& pos)
391{
392 if (pos.isFinite())
393 {
394 LLXform::setPosition(pos);
395 }
396 else
397 {
398 llerrs << "Non Finite in LLPrimitive::setPosition(LLVector3) for " << pCodeToString(mPrimitiveCode) << llendl;
399 }
400}
401
402void LLPrimitive::setAngularVelocity(const LLVector3& avel)
403{
404 if (avel.isFinite())
405 {
406 mAngularVelocity = avel;
407 }
408 else
409 {
410 llerror("Non Finite in LLPrimitive::setAngularVelocity", 0);
411 }
412}
413
414void LLPrimitive::setAngularVelocity(const F32 x, const F32 y, const F32 z)
415{
416 if (llfinite(x) && llfinite(y) && llfinite(z))
417 {
418 mAngularVelocity.setVec(x,y,z);
419 }
420 else
421 {
422 llerror("Non Finite in LLPrimitive::setAngularVelocity", 0);
423 }
424}
425
426void LLPrimitive::setVelocity(const LLVector3& vel)
427{
428 if (vel.isFinite())
429 {
430 mVelocity = vel;
431 }
432 else
433 {
434 llerrs << "Non Finite in LLPrimitive::setVelocity(LLVector3) for " << pCodeToString(mPrimitiveCode) << llendl;
435 }
436}
437
438void LLPrimitive::setVelocity(const F32 x, const F32 y, const F32 z)
439{
440 if (llfinite(x) && llfinite(y) && llfinite(z))
441 {
442 mVelocity.setVec(x,y,z);
443 }
444 else
445 {
446 llerrs << "Non Finite in LLPrimitive::setVelocity(F32,F32,F32) for " << pCodeToString(mPrimitiveCode) << llendl;
447 }
448}
449
450void LLPrimitive::setVelocityX(const F32 x)
451{
452 if (llfinite(x))
453 {
454 mVelocity.mV[VX] = x;
455 }
456 else
457 {
458 llerror("Non Finite in LLPrimitive::setVelocityX", 0);
459 }
460}
461
462void LLPrimitive::setVelocityY(const F32 y)
463{
464 if (llfinite(y))
465 {
466 mVelocity.mV[VY] = y;
467 }
468 else
469 {
470 llerror("Non Finite in LLPrimitive::setVelocityY", 0);
471 }
472}
473
474void LLPrimitive::setVelocityZ(const F32 z)
475{
476 if (llfinite(z))
477 {
478 mVelocity.mV[VZ] = z;
479 }
480 else
481 {
482 llerror("Non Finite in LLPrimitive::setVelocityZ", 0);
483 }
484}
485
486void LLPrimitive::addVelocity(const LLVector3& vel)
487{
488 if (vel.isFinite())
489 {
490 mVelocity += vel;
491 }
492 else
493 {
494 llerror("Non Finite in LLPrimitive::addVelocity", 0);
495 }
496}
497
498void LLPrimitive::setAcceleration(const LLVector3& accel)
499{
500 if (accel.isFinite())
501 {
502 mAcceleration = accel;
503 }
504 else
505 {
506 llerrs << "Non Finite in LLPrimitive::setAcceleration(LLVector3) for " << pCodeToString(mPrimitiveCode) << llendl;
507 }
508}
509
510void LLPrimitive::setAcceleration(const F32 x, const F32 y, const F32 z)
511{
512 if (llfinite(x) && llfinite(y) && llfinite(z))
513 {
514 mAcceleration.setVec(x,y,z);
515 }
516 else
517 {
518 llerrs << "Non Finite in LLPrimitive::setAcceleration(F32,F32,F32) for " << pCodeToString(mPrimitiveCode) << llendl;
519 }
520}
521#endif // CHECK_FOR_FINITE
522
523inline BOOL LLPrimitive::validTE(const U8 te_num) const
524{
525 return (mNumTEs && te_num < mNumTEs);
526}
527
528#endif
529