From 89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:44:50 -0500 Subject: Second Life viewer sources 1.14.0.0 --- linden/indra/llmath/llcamera.cpp | 16 +- linden/indra/llmath/llcoordframe.cpp | 16 +- linden/indra/llmath/llcrc.cpp | 25 +- linden/indra/llmath/llmath.vcproj | 9 +- linden/indra/llmath/llmath_vc8.vcproj | 453 ++++++++++++++++++++++++++++++++++ linden/indra/llmath/llmd5.cpp | 71 ++---- linden/indra/llmath/llmd5.h | 2 - linden/indra/llmath/lloctree.h | 94 ++++--- linden/indra/llmath/llrand.cpp | 18 +- linden/indra/llmath/llrand.h | 6 +- linden/indra/llmath/lltreenode.h | 5 +- linden/indra/llmath/lluuid.cpp | 32 +-- linden/indra/llmath/lluuid.h | 7 +- linden/indra/llmath/llvolume.cpp | 220 +++++++++-------- linden/indra/llmath/llvolume.h | 3 +- linden/indra/llmath/llvolumemgr.cpp | 4 +- linden/indra/llmath/m3math.cpp | 95 ++++--- linden/indra/llmath/m3math.h | 9 +- linden/indra/llmath/m4math.h | 9 +- linden/indra/llmath/v2math.h | 15 ++ linden/indra/llmath/v3color.h | 6 +- linden/indra/llmath/v3math.cpp | 31 ++- linden/indra/llmath/v3math.h | 43 ++-- linden/indra/llmath/v4math.h | 11 +- 24 files changed, 852 insertions(+), 348 deletions(-) create mode 100644 linden/indra/llmath/llmath_vc8.vcproj (limited to 'linden/indra/llmath') diff --git a/linden/indra/llmath/llcamera.cpp b/linden/indra/llmath/llcamera.cpp index 13666ba..bc13c90 100644 --- a/linden/indra/llmath/llcamera.cpp +++ b/linden/indra/llmath/llcamera.cpp @@ -121,25 +121,25 @@ void LLCamera::setFar(F32 far_plane) size_t LLCamera::writeFrustumToBuffer(char *buffer) const { - memcpy(buffer, &mView, sizeof(F32)); + memcpy(buffer, &mView, sizeof(F32)); /* Flawfinder: ignore */ buffer += sizeof(F32); - memcpy(buffer, &mAspect, sizeof(F32)); + memcpy(buffer, &mAspect, sizeof(F32)); /* Flawfinder: ignore */ buffer += sizeof(F32); - memcpy(buffer, &mNearPlane, sizeof(F32)); + memcpy(buffer, &mNearPlane, sizeof(F32)); /* Flawfinder: ignore */ buffer += sizeof(F32); - memcpy(buffer, &mFarPlane, sizeof(F32)); + memcpy(buffer, &mFarPlane, sizeof(F32)); /* Flawfinder: ignore */ return 4*sizeof(F32); } size_t LLCamera::readFrustumFromBuffer(const char *buffer) { - memcpy(&mView, buffer, sizeof(F32)); + memcpy(&mView, buffer, sizeof(F32)); /* Flawfinder: ignore */ buffer += sizeof(F32); - memcpy(&mAspect, buffer, sizeof(F32)); + memcpy(&mAspect, buffer, sizeof(F32)); /* Flawfinder: ignore */ buffer += sizeof(F32); - memcpy(&mNearPlane, buffer, sizeof(F32)); + memcpy(&mNearPlane, buffer, sizeof(F32)); /* Flawfinder: ignore */ buffer += sizeof(F32); - memcpy(&mFarPlane, buffer, sizeof(F32)); + memcpy(&mFarPlane, buffer, sizeof(F32)); /* Flawfinder: ignore */ return 4*sizeof(F32); } diff --git a/linden/indra/llmath/llcoordframe.cpp b/linden/indra/llmath/llcoordframe.cpp index 552854d..c7d18bb 100644 --- a/linden/indra/llmath/llcoordframe.cpp +++ b/linden/indra/llmath/llcoordframe.cpp @@ -460,26 +460,26 @@ void LLCoordFrame::getRotMatrixToParent(LLMatrix4& mat) const size_t LLCoordFrame::writeOrientation(char *buffer) const { - memcpy(buffer, mOrigin.mV, 3*sizeof(F32)); + memcpy(buffer, mOrigin.mV, 3*sizeof(F32)); /*Flawfinder: ignore */ buffer += 3*sizeof(F32); - memcpy(buffer, mXAxis.mV, 3*sizeof(F32)); + memcpy(buffer, mXAxis.mV, 3*sizeof(F32)); /*Flawfinder: ignore */ buffer += 3*sizeof(F32); - memcpy(buffer, mYAxis.mV, 3*sizeof(F32)); + memcpy(buffer, mYAxis.mV, 3*sizeof(F32));/*Flawfinder: ignore */ buffer += 3*sizeof(F32); - memcpy(buffer, mZAxis.mV, 3*sizeof(F32)); + memcpy(buffer, mZAxis.mV, 3*sizeof(F32)); /*Flawfinder: ignore */ return 12*sizeof(F32); } size_t LLCoordFrame::readOrientation(const char *buffer) { - memcpy(mOrigin.mV, buffer, 3*sizeof(F32)); + memcpy(mOrigin.mV, buffer, 3*sizeof(F32)); /*Flawfinder: ignore */ buffer += 3*sizeof(F32); - memcpy(mXAxis.mV, buffer, 3*sizeof(F32)); + memcpy(mXAxis.mV, buffer, 3*sizeof(F32)); /*Flawfinder: ignore */ buffer += 3*sizeof(F32); - memcpy(mYAxis.mV, buffer, 3*sizeof(F32)); + memcpy(mYAxis.mV, buffer, 3*sizeof(F32)); /*Flawfinder: ignore */ buffer += 3*sizeof(F32); - memcpy(mZAxis.mV, buffer, 3*sizeof(F32)); + memcpy(mZAxis.mV, buffer, 3*sizeof(F32)); /*Flawfinder: ignore */ if( !isFinite() ) { diff --git a/linden/indra/llmath/llcrc.cpp b/linden/indra/llmath/llcrc.cpp index 4194432..1c0aa5d 100644 --- a/linden/indra/llmath/llcrc.cpp +++ b/linden/indra/llmath/llcrc.cpp @@ -161,9 +161,15 @@ void LLCRC::update(const U8* buffer, U32 buffer_size) } } -void LLCRC::update(const char *filename) +void LLCRC::update(const char* filename) { - FILE *fp = LLFile::fopen(filename, "rb"); + if (!filename) + { + llerrs << "No filename specified" << llendl; + return; + } + + FILE* fp = LLFile::fopen(filename, "rb"); /* Flawfinder: ignore */ if (fp) { @@ -172,12 +178,15 @@ void LLCRC::update(const char *filename) fseek(fp, 0, SEEK_SET); - U8 *data = new U8[size]; - fread(data, size, 1, fp); - fclose(fp); + if (size > 0) + { + U8* data = new U8[size]; + fread(data, size, 1, fp); + fclose(fp); - update(data, size); - delete[] data; + update(data, size); + delete[] data; + } } } @@ -186,7 +195,7 @@ void LLCRC::update(const char *filename) BOOL LLCRC::testHarness() { const S32 TEST_BUFFER_SIZE = 16; - const char TEST_BUFFER[TEST_BUFFER_SIZE] = "hello &#$)$&Nd0"; + const char TEST_BUFFER[TEST_BUFFER_SIZE] = "hello &#$)$&Nd0"; /* Flawfinder: ignore */ LLCRC c1, c2; c1.update((U8*)TEST_BUFFER, TEST_BUFFER_SIZE - 1); char* rh = (char*)TEST_BUFFER; diff --git a/linden/indra/llmath/llmath.vcproj b/linden/indra/llmath/llmath.vcproj index 9b6047d..82feb25 100644 --- a/linden/indra/llmath/llmath.vcproj +++ b/linden/indra/llmath/llmath.vcproj @@ -224,6 +224,9 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> + + - - + + diff --git a/linden/indra/llmath/llmath_vc8.vcproj b/linden/indra/llmath/llmath_vc8.vcproj new file mode 100644 index 0000000..ea23702 --- /dev/null +++ b/linden/indra/llmath/llmath_vc8.vcproj @@ -0,0 +1,453 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/linden/indra/llmath/llmd5.cpp b/linden/indra/llmath/llmd5.cpp index 19174af..267381c 100644 --- a/linden/indra/llmath/llmd5.cpp +++ b/linden/indra/llmath/llmd5.cpp @@ -122,10 +122,18 @@ void LLMD5::update (const uint1 *input, const uint4 input_length) { // Transform as many times as possible. if (input_length >= buffer_space) { // ie. we have enough to fill the buffer // fill the rest of the buffer and transform - memcpy (buffer + buffer_index, input, buffer_space); + memcpy( /* Flawfinder: ignore */ + buffer + buffer_index, + input, + buffer_space); transform (buffer); // now, transform each 64-byte piece of the input, bypassing the buffer + if (input == NULL || input_length == 0){ + std::cerr << "LLMD5::update: Invalid input!" << std::endl; + return; + } + for (input_index = buffer_space; input_index + 63 < input_length; input_index += 64) transform (input+input_index); @@ -137,7 +145,7 @@ void LLMD5::update (const uint1 *input, const uint4 input_length) { // and here we do the buffering: - memcpy(buffer+buffer_index, input+input_index, input_length-input_index); + memcpy(buffer+buffer_index, input+input_index, input_length-input_index); /* Flawfinder: ignore */ } @@ -145,9 +153,9 @@ void LLMD5::update (const uint1 *input, const uint4 input_length) { // MD5 update for files. // Like above, except that it works on files (and uses above as a primitive.) -void LLMD5::update(FILE *file){ +void LLMD5::update(FILE* file){ - unsigned char buffer[1024]; + unsigned char buffer[1024]; /* Flawfinder: ignore */ int len; while ( (len=(int)fread(buffer, 1, 1024, file)) ) @@ -167,11 +175,11 @@ void LLMD5::update(FILE *file){ void LLMD5::update(std::istream& stream){ - unsigned char buffer[1024]; + unsigned char buffer[1024]; /* Flawfinder: ignore */ int len; while (stream.good()){ - stream.read( (char*)buffer, 1024); // note that return value of read is unusable. + stream.read( (char*)buffer, 1024); /* Flawfinder: ignore */ // note that return value of read is unusable. len=stream.gcount(); update(buffer, len); } @@ -182,35 +190,13 @@ void LLMD5::update(std::istream& stream){ - -// MD5 update for ifstreams. -// Like update for files; see above. - -void LLMD5::update(llifstream& stream){ - - unsigned char buffer[1024]; - int len; - - while (stream.good()){ - stream.read( (char*)buffer, 1024); // note that return value of read is unusable. - len=stream.gcount(); - update(buffer, len); - } - -} - - - - - - // MD5 finalization. Ends an MD5 message-digest operation, writing the // the message digest and zeroizing the context. void LLMD5::finalize (){ - unsigned char bits[8]; + unsigned char bits[8]; /* Flawfinder: ignore */ unsigned int index, padLen; static uint1 PADDING[64]={ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -264,25 +250,16 @@ LLMD5::LLMD5(std::istream& stream){ finalize(); } - - -LLMD5::LLMD5(llifstream& stream) -{ - init(); // must called by all constructors - update (stream); - finalize(); -} - // Digest a string of the format ("%s:%i" % (s, number)) LLMD5::LLMD5(const unsigned char *string, const unsigned int number) { const char *colon = ":"; - char tbuf[16]; + char tbuf[16]; /* Flawfinder: ignore */ init(); - update(string, (U32)strlen((const char *) string)); - update((const unsigned char *) colon, (U32)strlen(colon)); - sprintf(tbuf, "%i", number); - update((const unsigned char *) tbuf, (U32)strlen(tbuf)); + update(string, (U32)strlen((const char *) string)); /* Flawfinder: ignore */ + update((const unsigned char *) colon, (U32)strlen(colon)); /* Flawfinder: ignore */ + snprintf(tbuf, sizeof(tbuf), "%i", number); /* Flawfinder: ignore */ + update((const unsigned char *) tbuf, (U32)strlen(tbuf)); /* Flawfinder: ignore */ finalize(); } @@ -290,7 +267,7 @@ LLMD5::LLMD5(const unsigned char *string, const unsigned int number) LLMD5::LLMD5(const unsigned char *s) { init(); - update(s, (U32)strlen((const char *) s)); + update(s, (U32)strlen((const char *) s)); /* Flawfinder: ignore */ finalize(); } @@ -304,7 +281,7 @@ void LLMD5::raw_digest(unsigned char *s) return; } - memcpy(s, digest, 16); + memcpy(s, digest, 16); /* Flawfinder: ignore */ return; } @@ -324,7 +301,7 @@ void LLMD5::hex_digest(char *s) for (i=0; i<16; i++) { - sprintf(s+i*2, "%02x", digest[i]); + sprintf(s+i*2, "%02x", digest[i]); /* Flawfinder: ignore */ } s[32]='\0'; @@ -338,7 +315,7 @@ void LLMD5::hex_digest(char *s) std::ostream& operator<<(std::ostream &stream, LLMD5 context) { - char s[33]; + char s[33]; /* Flawfinder: ignore */ context.hex_digest(s); stream << s; return stream; diff --git a/linden/indra/llmath/llmd5.h b/linden/indra/llmath/llmd5.h index 1874b45..7b185b6 100644 --- a/linden/indra/llmath/llmd5.h +++ b/linden/indra/llmath/llmd5.h @@ -90,7 +90,6 @@ public: void update (const uint1 *input, const uint4 input_length); void update (std::istream& stream); void update (FILE *file); - void update (llifstream& stream); void finalize (); // constructors for special circumstances. All these constructors finalize @@ -98,7 +97,6 @@ public: LLMD5 (const unsigned char *string); // digest string, finalize LLMD5 (std::istream& stream); // digest stream, finalize LLMD5 (FILE *file); // digest file, close, finalize - LLMD5 (llifstream& stream); // digest stream, close, finalize LLMD5 (const unsigned char *string, const unsigned int number); // methods to acquire finalized result diff --git a/linden/indra/llmath/lloctree.h b/linden/indra/llmath/lloctree.h index 6e068cd..22f298c 100644 --- a/linden/indra/llmath/lloctree.h +++ b/linden/indra/llmath/lloctree.h @@ -40,6 +40,11 @@ #endif #define LL_OCTREE_PARANOIA_CHECK 0 +#if LL_DARWIN +#define LL_OCTREE_MAX_CAPACITY 32 +#else +#define LL_OCTREE_MAX_CAPACITY 256 +#endif template class LLOctreeState; template class LLOctreeNode; @@ -107,7 +112,8 @@ public: virtual void removeByAddress(T* data) { getOctState()->removeByAddress(data); } virtual bool hasLeafState() const { return getOctState()->isLeaf(); } virtual void destroy() { getOctState()->destroy(); } - virtual oct_node* getNodeAt(T* data) { return getOctState()->getNodeAt(data); } + virtual oct_node* getNodeAt(T* data) { return getNodeAt(data->getPositionGroup(), data->getBinRadius()); } + virtual oct_node* getNodeAt(const LLVector3d& pos, const F64& rad) { return getOctState()->getNodeAt(pos, rad); } virtual U8 getOctant() const { return mOctant; } virtual void setOctant(U8 octant) { mOctant = octant; } virtual const oct_state* getOctState() const { return (const oct_state*) BaseType::mState; } @@ -136,9 +142,14 @@ public: return ret; } + virtual bool isInside(const LLVector3d& pos, const F64& rad) const + { + return rad <= mSize.mdV[0]*2.0 && isInside(pos); + } + virtual bool isInside(T* data) const { - return data->getBinRadius() <= mSize.mdV[0]*2.0 && isInside(data->getPositionGroup()); + return isInside(data->getPositionGroup(), data->getBinRadius()); } virtual bool isInside(const LLVector3d& pos) const @@ -174,6 +185,11 @@ public: bool contains(T* xform) { + return contains(xform->getBinRadius()); + } + + bool contains(F64 radius) + { if (mParent == NULL) { //root node contains nothing return false; @@ -181,7 +197,6 @@ public: F64 size = mSize.mdV[0]; F64 p_size = size * 2.0; - F64 radius = xform->getBinRadius(); return (radius <= 0.001 && size <= 0.001) || (radius <= p_size && radius > size); @@ -189,17 +204,10 @@ public: static void pushCenter(LLVector3d ¢er, LLVector3d &size, T* data) { - LLVector3 pos(data->getPositionGroup()); - F64 p[] = - { - (F64) pos.mV[0], - (F64) pos.mV[1], - (F64) pos.mV[2] - }; - + LLVector3d pos(data->getPositionGroup()); for (U32 i = 0; i < 3; i++) { - if (p[i] > center.mdV[i]) + if (pos.mdV[i] > center.mdV[i]) { center.mdV[i] += size.mdV[i]; } @@ -273,11 +281,15 @@ public: oct_node* getOctNode() { return (oct_node*) BaseType::getNode(); } virtual oct_node* getNodeAt(T* data) + { + return getNodeAt(data->getPositionGroup(), data->getBinRadius()); + } + + virtual oct_node* getNodeAt(const LLVector3d& pos, const F64& rad) { - const LLVector3d& pos = data->getPositionGroup(); LLOctreeNode* node = getOctNode(); - if (node->isInside(data)) + if (node->isInside(pos, rad)) { //do a quick search by octant U8 octant = node->getOctant(pos.mdV); @@ -287,7 +299,7 @@ public: //at the appropriate octant or is smaller than the object. //by definition, that node is the smallest node that contains // the data - while (keep_going && node->getSize().mdV[0] >= data->getBinRadius()) + while (keep_going && node->getSize().mdV[0] >= rad) { keep_going = FALSE; for (U32 i = 0; i < node->getChildCount() && !keep_going; i++) @@ -301,9 +313,9 @@ public: } } } - else if (!node->contains(data) && node->getParent()) + else if (!node->contains(rad) && node->getParent()) { //if we got here, data does not exist in this node - return ((LLOctreeNode*) node->getParent())->getNodeAt(data); + return ((LLOctreeNode*) node->getParent())->getNodeAt(pos, rad); } return node; @@ -317,22 +329,15 @@ public: return false; } LLOctreeNode* node = getOctNode(); + LLOctreeNode* parent = node->getOctParent(); - if (data->getBinRadius() <= node->getSize().mdV[0]) - { - oct_node* dest = getNodeAt(data); - - if (dest != node) - { - dest->insert(data); - return false; - } - } - - //no kid found, is it even here? - if (node->isInside(data)) + //is it here? + if (node->isInside(data->getPositionGroup())) { - if (node->contains(data)) + if (getElementCount() < LL_OCTREE_MAX_CAPACITY && + (node->contains(data->getBinRadius()) || + (data->getBinRadius() > node->getSize().mdV[0] && + parent && parent->getElementCount() >= LL_OCTREE_MAX_CAPACITY))) { //it belongs here if (data == NULL) { @@ -353,7 +358,19 @@ public: return true; } else - { + { + //find a child to give it to + oct_node* child = NULL; + for (U32 i = 0; i < getChildCount(); i++) + { + child = getChild(i); + if (child->isInside(data->getPositionGroup())) + { + child->insert(data); + return false; + } + } + //it's here, but no kids are in the right place, make a new kid LLVector3d center(node->getCenter()); LLVector3d size(node->getSize()*0.5); @@ -385,7 +402,7 @@ public: //make the new kid LLOctreeState* newstate = new LLOctreeState(); - oct_node* child = new LLOctreeNode(center, size, newstate, node); + child = new LLOctreeNode(center, size, newstate, node); addChild(child); child->insert(data); @@ -393,8 +410,15 @@ public: } else { - //it's not in here, give it to the parent - node->getOctParent()->insert(data); + //it's not in here, give it to the root + LLOctreeNode* parent = node->getOctParent(); + while (parent) + { + node = parent; + parent = node->getOctParent(); + } + + node->insert(data); } return false; diff --git a/linden/indra/llmath/llrand.cpp b/linden/indra/llmath/llrand.cpp index c0f03d2..ae52010 100644 --- a/linden/indra/llmath/llrand.cpp +++ b/linden/indra/llmath/llrand.cpp @@ -140,7 +140,14 @@ F32 ll_frand(F32 val) { // The clamping rules are described above. F32 rv = ll_internal_random_float() * val; - if(rv >= val) return 0.0f; + if(val > 0) + { + if(rv >= val) return 0.0f; + } + else + { + if(rv <= val) return 0.0f; + } return rv; } @@ -153,6 +160,13 @@ F64 ll_drand(F64 val) { // The clamping rules are described above. F64 rv = ll_internal_random_double() * val; - if(rv >= val) return 0.0; + if(val > 0) + { + if(rv >= val) return 0.0; + } + else + { + if(rv <= val) return 0.0; + } return rv; } diff --git a/linden/indra/llmath/llrand.h b/linden/indra/llmath/llrand.h index 47b5651..1bf055e 100644 --- a/linden/indra/llmath/llrand.h +++ b/linden/indra/llmath/llrand.h @@ -63,7 +63,7 @@ S32 ll_rand(); /** - *@brief Generate a float from [0, val). + *@brief Generate a float from [0, val) or (val, 0]. */ S32 ll_rand(S32 val); @@ -73,7 +73,7 @@ S32 ll_rand(S32 val); F32 ll_frand(); /** - *@brief Generate a float from [0, val). + *@brief Generate a float from [0, val) or (val, 0]. */ F32 ll_frand(F32 val); @@ -83,7 +83,7 @@ F32 ll_frand(F32 val); F64 ll_drand(); /** - *@brief Generate a double from [0, val). + *@brief Generate a double from [0, val) or (val, 0]. */ F64 ll_drand(F64 val); diff --git a/linden/indra/llmath/lltreenode.h b/linden/indra/llmath/lltreenode.h index 78ff759..ba3c867 100644 --- a/linden/indra/llmath/lltreenode.h +++ b/linden/indra/llmath/lltreenode.h @@ -41,7 +41,6 @@ class LLTreeState public: LLTreeState(LLTreeNode* node) { setNode(node); } virtual ~LLTreeState() { }; - virtual bool insert(T* data) = 0; virtual bool remove(T* data) = 0; virtual void setNode(LLTreeNode* node); @@ -54,7 +53,7 @@ private: }; template -class LLTreeListener +class LLTreeListener: public LLRefCount { public: virtual ~LLTreeListener() { }; @@ -94,7 +93,7 @@ protected: LLTreeState* mState; public: - std::vector*> mListeners; + std::vector > > mListeners; }; template diff --git a/linden/indra/llmath/lluuid.cpp b/linden/indra/llmath/lluuid.cpp index 3fb31a6..b943fd9 100644 --- a/linden/indra/llmath/lluuid.cpp +++ b/linden/indra/llmath/lluuid.cpp @@ -170,15 +170,15 @@ void LLUUID::toString(char *out) const void LLUUID::toCompressedString(char *out) const { - memcpy(out, mData, UUID_BYTES); + memcpy(out, mData, UUID_BYTES); /* Flawfinder: ignore */ out[UUID_BYTES] = '\0'; } -LLString LLUUID::getString() const +std::string LLUUID::asString() const { - char str[UUID_STR_SIZE]; + char str[UUID_STR_SIZE]; /* Flawfinder: ignore */ toString(str); - return LLString(str); + return std::string(str); } BOOL LLUUID::set(const std::string& in_string, BOOL emit) @@ -203,11 +203,11 @@ BOOL LLUUID::set(const char *in_string, BOOL emit) return TRUE; } - if (strlen(in_string) != (UUID_STR_LENGTH - 1)) + if (strlen(in_string) != (UUID_STR_LENGTH - 1)) /* Flawfinder: ignore */ { // I'm a moron. First implementation didn't have the right UUID format. // Shouldn't see any of these any more - if (strlen(in_string) == (UUID_STR_LENGTH - 2)) + if (strlen(in_string) == (UUID_STR_LENGTH - 2)) /* Flawfinder: ignore */ { if(emit) { @@ -307,10 +307,10 @@ BOOL LLUUID::validate(const char *in_string) { return FALSE; } - if (strlen(in_string) != (UUID_STR_LENGTH - 1)) + if (strlen(in_string) != (UUID_STR_LENGTH - 1)) /* Flawfinder: ignore */ { // I'm a moron. First implementation didn't have the right UUID format. - if (strlen(in_string) == (UUID_STR_LENGTH - 2)) + if (strlen(in_string) == (UUID_STR_LENGTH - 2)) /* Flawfinder: ignore */ { broken_format = TRUE; } @@ -414,7 +414,7 @@ std::ostream& operator<<(std::ostream& s, const LLUUID &uuid) std::istream& operator>>(std::istream &s, LLUUID &uuid) { U32 i; - char uuid_str[UUID_STR_LENGTH]; + char uuid_str[UUID_STR_LENGTH]; /* Flawfinder: ignore */ for (i = 0; i < UUID_STR_LENGTH-1; i++) { s >> uuid_str[i]; @@ -480,7 +480,7 @@ S32 LLUUID::getNodeID(unsigned char * node_id) Ncb.ncb_command = NCBASTAT; Ncb.ncb_lana_num = lenum.lana[i]; - strcpy( (char *)Ncb.ncb_callname, "* " ); + strcpy( (char *)Ncb.ncb_callname, "* " ); /* Flawfinder: ignore */ Ncb.ncb_buffer = (unsigned char *)&Adapter; Ncb.ncb_length = sizeof(Adapter); @@ -497,7 +497,7 @@ S32 LLUUID::getNodeID(unsigned char * node_id) // Adapter.adapt.adapter_address[3], // Adapter.adapt.adapter_address[4], // Adapter.adapt.adapter_address[5] ); - memcpy(node_id,Adapter.adapt.adapter_address,6); + memcpy(node_id,Adapter.adapt.adapter_address,6); /* Flawfinder: ignore */ retval = 1; } @@ -652,7 +652,7 @@ S32 LLUUID::getNodeID(unsigned char *node_id) n = ifc.ifc_len; for (i = 0; i < n; i+= ifreq_size(*ifr) ) { ifrp = (struct ifreq *)((char *) ifc.ifc_buf+i); - strncpy(ifr.ifr_name, ifrp->ifr_name, IFNAMSIZ); + strncpy(ifr.ifr_name, ifrp->ifr_name, IFNAMSIZ); /* Flawfinder: ignore */ #ifdef SIOCGIFHWADDR if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0) continue; @@ -674,7 +674,7 @@ S32 LLUUID::getNodeID(unsigned char *node_id) if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5]) continue; if (node_id) { - memcpy(node_id, a, 6); + memcpy(node_id, a, 6); /* Flawfinder: ignore */ close(sd); return 1; } @@ -783,7 +783,7 @@ void LLUUID::generate() // Create a UUID. uuid_time_t timestamp; - static unsigned char node_id[6]; + static unsigned char node_id[6]; /* Flawfinder: ignore */ static int has_init = 0; // Create a UUID. @@ -827,7 +827,7 @@ void LLUUID::generate() if (clock_seq == 0) clock_seq++; } - memcpy(mData+10, node_id, 6); + memcpy(mData+10, node_id, 6); /* Flawfinder: ignore */ U32 tmp; tmp = timestamp.low; mData[3] = (unsigned char) tmp; @@ -865,7 +865,7 @@ void LLUUID::generate() U32 LLUUID::getRandomSeed() { - static unsigned char seed[16]; + static unsigned char seed[16]; /* Flawfinder: ignore */ getNodeID(&seed[0]); seed[6]='\0'; diff --git a/linden/indra/llmath/lluuid.h b/linden/indra/llmath/lluuid.h index b8288eb..aeda734 100644 --- a/linden/indra/llmath/lluuid.h +++ b/linden/indra/llmath/lluuid.h @@ -29,8 +29,7 @@ #include #include - -#include "llstring.h" +#include "stdtypes.h" const S32 UUID_BYTES = 16; const S32 UUID_WORDS = 4; @@ -103,7 +102,9 @@ public: void toString(char *out) const; // Does not allocate memory, needs 36 characters (including \0) void toCompressedString(char *out) const; // Does not allocate memory, needs 17 characters (including \0) - LLString getString() const; + + std::string asString() const; + U16 getCRC16() const; U32 getCRC32() const; diff --git a/linden/indra/llmath/llvolume.cpp b/linden/indra/llmath/llvolume.cpp index c527e85..e42413a 100644 --- a/linden/indra/llmath/llvolume.cpp +++ b/linden/indra/llmath/llvolume.cpp @@ -724,11 +724,11 @@ BOOL LLProfile::generate(BOOL path_open,F32 detail, S32 split) BOOL LLProfileParams::importFile(FILE *fp) { const S32 BUFSIZE = 16384; - char buffer[BUFSIZE]; + char buffer[BUFSIZE]; /* Flawfinder: ignore */ // *NOTE: changing the size or type of these buffers will require // changing the sscanf below. - char keyword[256]; - char valuestr[256]; + char keyword[256]; /* Flawfinder: ignore */ + char valuestr[256]; /* Flawfinder: ignore */ keyword[0] = 0; valuestr[0] = 0; F32 tempF32; @@ -737,7 +737,10 @@ BOOL LLProfileParams::importFile(FILE *fp) while (!feof(fp)) { fgets(buffer, BUFSIZE, fp); - sscanf(buffer, " %255s %255s", keyword, valuestr); + sscanf( /* Flawfinder: ignore */ + buffer, + " %255s %255s", + keyword, valuestr); if (!keyword) { continue; @@ -796,11 +799,11 @@ BOOL LLProfileParams::exportFile(FILE *fp) const BOOL LLProfileParams::importLegacyStream(std::istream& input_stream) { const S32 BUFSIZE = 16384; - char buffer[BUFSIZE]; + char buffer[BUFSIZE]; /* Flawfinder: ignore */ // *NOTE: changing the size or type of these buffers will require // changing the sscanf below. - char keyword[256]; - char valuestr[256]; + char keyword[256]; /* Flawfinder: ignore */ + char valuestr[256]; /* Flawfinder: ignore */ keyword[0] = 0; valuestr[0] = 0; F32 tempF32; @@ -809,7 +812,11 @@ BOOL LLProfileParams::importLegacyStream(std::istream& input_stream) while (input_stream.good()) { input_stream.getline(buffer, BUFSIZE); - sscanf(buffer, " %255s %255s", keyword, valuestr); + sscanf( /* Flawfinder: ignore */ + buffer, + " %255s %255s", + keyword, + valuestr); if (!keyword) { continue; @@ -1218,11 +1225,11 @@ BOOL LLDynamicPath::generate(F32 detail, S32 split) BOOL LLPathParams::importFile(FILE *fp) { const S32 BUFSIZE = 16384; - char buffer[BUFSIZE]; + char buffer[BUFSIZE]; /* Flawfinder: ignore */ // *NOTE: changing the size or type of these buffers will require // changing the sscanf below. - char keyword[256]; - char valuestr[256]; + char keyword[256]; /* Flawfinder: ignore */ + char valuestr[256]; /* Flawfinder: ignore */ keyword[0] = 0; valuestr[0] = 0; @@ -1233,7 +1240,10 @@ BOOL LLPathParams::importFile(FILE *fp) while (!feof(fp)) { fgets(buffer, BUFSIZE, fp); - sscanf(buffer, " %255s %255s", keyword, valuestr); + sscanf( /* Flawfinder: ignore */ + buffer, + " %255s %255s", + keyword, valuestr); if (!keyword) { continue; @@ -1359,11 +1369,11 @@ BOOL LLPathParams::exportFile(FILE *fp) const BOOL LLPathParams::importLegacyStream(std::istream& input_stream) { const S32 BUFSIZE = 16384; - char buffer[BUFSIZE]; + char buffer[BUFSIZE]; /* Flawfinder: ignore */ // *NOTE: changing the size or type of these buffers will require // changing the sscanf below. - char keyword[256]; - char valuestr[256]; + char keyword[256]; /* Flawfinder: ignore */ + char valuestr[256]; /* Flawfinder: ignore */ keyword[0] = 0; valuestr[0] = 0; @@ -1374,7 +1384,10 @@ BOOL LLPathParams::importLegacyStream(std::istream& input_stream) while (input_stream.good()) { input_stream.getline(buffer, BUFSIZE); - sscanf(buffer, " %255s %255s", keyword, valuestr); + sscanf( /* Flawfinder: ignore */ + buffer, + " %255s %255s", + keyword, valuestr); if (!keyword) { continue; @@ -1771,9 +1784,6 @@ void LLVolume::createVolumeFaces() mVolumeFaces[i].create(); } } - - mBounds[1] = LLVector3(0,0,0); - mBounds[0] = LLVector3(512,512,512); } @@ -1818,21 +1828,28 @@ void LLVolumeParams::copyParams(const LLVolumeParams ¶ms) mPathParams.copyParams(params.mPathParams); } +// Less restricitve approx 0 for volumes +const F32 APPROXIMATELY_ZERO = 0.001f; +bool approx_zero( F32 f, F32 tolerance = APPROXIMATELY_ZERO) +{ + return (f >= -tolerance) && (f <= tolerance); +} + // return true if in range (or nearly so) -static bool limit_range(F32& v, F32 min, F32 max) +static bool limit_range(F32& v, F32 min, F32 max, F32 tolerance = APPROXIMATELY_ZERO) { F32 min_delta = v - min; if (min_delta < 0.f) { v = min; - if (!is_approx_zero(min_delta)) + if (!approx_zero(min_delta, tolerance)) return false; } F32 max_delta = max - v; if (max_delta < 0.f) { v = max; - if (!is_approx_zero(max_delta)) + if (!approx_zero(max_delta, tolerance)) return false; } return true; @@ -1847,9 +1864,10 @@ bool LLVolumeParams::setBeginAndEndS(const F32 b, const F32 e) valid &= limit_range(begin, 0.f, 1.f - MIN_CUT_DELTA); F32 end = e; + if (end >= .0149f && end < MIN_CUT_DELTA) end = MIN_CUT_DELTA; // eliminate warning for common rounding error valid &= limit_range(end, MIN_CUT_DELTA, 1.f); - valid &= limit_range(begin, 0.f, end - MIN_CUT_DELTA); + valid &= limit_range(begin, 0.f, end - MIN_CUT_DELTA, .01f); // Now set them. mProfileParams.setBegin(begin); @@ -1869,7 +1887,7 @@ bool LLVolumeParams::setBeginAndEndT(const F32 b, const F32 e) F32 end = e; valid &= limit_range(end, MIN_CUT_DELTA, 1.f); - valid &= limit_range(begin, 0.f, end - MIN_CUT_DELTA); + valid &= limit_range(begin, 0.f, end - MIN_CUT_DELTA, .01f); // Now set them. mPathParams.setBegin(begin); @@ -2026,7 +2044,7 @@ bool LLVolumeParams::setRadiusOffset(const F32 offset) { radius_offset = max_radius_mag; } - valid = is_approx_zero(delta); + valid = approx_zero(delta, .1f); } mPathParams.setRadiusOffset(radius_offset); @@ -2060,7 +2078,7 @@ bool LLVolumeParams::setSkew(const F32 skew_value) { skew = min_skew_mag; } - valid = is_approx_zero(delta); + valid = approx_zero(delta, .01f); } mPathParams.setSkew(skew); @@ -2185,7 +2203,7 @@ S32 *LLVolume::getTriangleIndices(U32 &num_indices) const size_s_out = getProfile().getTotalOut(); size_t = getPath().mPath.size(); - if (open) + if (open) /* Flawfinder: ignore */ { if (hollow) { @@ -2807,7 +2825,7 @@ noindices: return NULL; } num_indices = count; - memcpy(indices, index, count * sizeof(S32)); + memcpy(indices, index, count * sizeof(S32)); /* Flawfinder: ignore */ return indices; } @@ -2986,10 +3004,15 @@ void LLVolume::generateSilhouetteVertices(std::vector &vertices, S32 v2 = face.mIndices[j*3+((k+1)%3)]; vertices.push_back(face.mVertices[v1].mPosition*mat); - normals.push_back(face.mVertices[v1].mNormal*norm_mat); + LLVector3 norm1 = face.mVertices[v1].mNormal * norm_mat; + norm1.normVec(); + normals.push_back(norm1); vertices.push_back(face.mVertices[v2].mPosition*mat); - normals.push_back(face.mVertices[v2].mNormal*norm_mat); + LLVector3 norm2 = face.mVertices[v2].mNormal * norm_mat; + norm2.normVec(); + normals.push_back(norm2); + segments.push_back(vertices.size()); } } @@ -3310,7 +3333,7 @@ BOOL LLVolume::cleanupTriangleData( const S32 num_input_vertices, *output_triangles = new S32[cur_tri*3]; num_output_triangles = cur_tri; - memcpy(*output_triangles, sorted_tris, 3*cur_tri*sizeof(S32)); + memcpy(*output_triangles, sorted_tris, 3*cur_tri*sizeof(S32)); /* Flawfinder: ignore */ /* llinfos << "Out vertices: " << num_output_vertices << llendl; @@ -3347,16 +3370,16 @@ BOOL LLVolumeParams::importFile(FILE *fp) { //llinfos << "importing volume" << llendl; const S32 BUFSIZE = 16384; - char buffer[BUFSIZE]; + char buffer[BUFSIZE]; /* Flawfinder: ignore */ // *NOTE: changing the size or type of this buffer will require // changing the sscanf below. - char keyword[256]; + char keyword[256]; /* Flawfinder: ignore */ keyword[0] = 0; while (!feof(fp)) { fgets(buffer, BUFSIZE, fp); - sscanf(buffer, " %255s", keyword); + sscanf(buffer, " %255s", keyword); /* Flawfinder: ignore */ if (!keyword) { continue; @@ -3403,8 +3426,8 @@ BOOL LLVolumeParams::importLegacyStream(std::istream& input_stream) const S32 BUFSIZE = 16384; // *NOTE: changing the size or type of this buffer will require // changing the sscanf below. - char buffer[BUFSIZE]; - char keyword[256]; + char buffer[BUFSIZE]; /* Flawfinder: ignore */ + char keyword[256]; /* Flawfinder: ignore */ keyword[0] = 0; while (input_stream.good()) @@ -3753,6 +3776,9 @@ BOOL LLVolumeFace::createUnCutCubeCap() num_vertices = (grid_size+1)*(grid_size+1); num_indices = quad_count * 4; + LLVector3& min = mExtents[0]; + LLVector3& max = mExtents[1]; + S32 offset = 0; if (mTypeMask & TOP_MASK) offset = (max_t-1) * max_s; @@ -3792,32 +3818,6 @@ BOOL LLVolumeFace::createUnCutCubeCap() } S32 vtop = mVertices.size(); -// S32 itop = mIndices.size(); -/// vector_append(mVertices,4); -// vector_append(mIndices,4); -// LLVector3 new_pt = lerp(pt1, pt2, t_fraction); -#if 0 - for(int t=0;t<4;t++){ - VertexData vd; - vd.mPosition = corners[t].mPosition; - vd.mNormal = - ((corners[(t+1)%4].mPosition-corners[t].mPosition)% - (corners[(t+2)%4].mPosition-corners[(t+1)%4].mPosition)); - vd.mNormal.normVec(); - - if (mTypeMask & TOP_MASK) - vd.mNormal *= -1.0f; - vd.mBinormal = vd.mNormal; - vd.mTexCoord = corners[t].mTexCoord; - mVertices.push_back(vd); - } - int idxs[] = {0,1,2,2,3,0}; - if (mTypeMask & TOP_MASK){ - for(int i=0;i<6;i++)mIndices.push_back(vtop+idxs[i]); - }else{ - for(int i=5;i>=0;i--)mIndices.push_back(vtop+idxs[i]); - } -#else for(int gx = 0;gx& mesh = mVolumep->getMesh(); const std::vector& profile = mVolumep->getProfile().mProfile; const std::vector& path_data = mVolumep->getPath().mPath; @@ -4243,6 +4261,9 @@ BOOL LLVolumeFace::createSide() vector_append(mIndices,num_indices); vector_append(mEdge, num_indices); + LLVector3& face_min = mExtents[0]; + LLVector3& face_max = mExtents[1]; + mCenter.clearVec(); S32 begin_stex = llfloor( profile[mBeginS].mV[2] ); @@ -4290,17 +4311,26 @@ BOOL LLVolumeFace::createSide() i = mBeginS + s + max_s*t; } - mCenter += mVertices[cur_vertex].mPosition = mesh[i].mPos; + mVertices[cur_vertex].mPosition = mesh[i].mPos; mVertices[cur_vertex].mTexCoord = LLVector2(ss,tt); mVertices[cur_vertex].mNormal = LLVector3(0,0,0); mVertices[cur_vertex].mBinormal = LLVector3(0,0,0); + if (cur_vertex == 0) + { + face_min = face_max = mesh[i].mPos; + } + else + { + update_min_max(face_min, face_max, mesh[i].mPos); + } + cur_vertex++; if ((mTypeMask & INNER_MASK) && (mTypeMask & FLAT_MASK) && mNumS > 2 && s > 0) { - mCenter += mVertices[cur_vertex].mPosition = mesh[i].mPos; + mVertices[cur_vertex].mPosition = mesh[i].mPos; mVertices[cur_vertex].mTexCoord = LLVector2(ss,tt); mVertices[cur_vertex].mNormal = LLVector3(0,0,0); @@ -4322,15 +4352,19 @@ BOOL LLVolumeFace::createSide() i = mBeginS + s + max_s*t; ss = profile[mBeginS + s].mV[2] - begin_stex; - mCenter += mVertices[cur_vertex].mPosition = mesh[i].mPos; + mVertices[cur_vertex].mPosition = mesh[i].mPos; mVertices[cur_vertex].mTexCoord = LLVector2(ss,tt); mVertices[cur_vertex].mNormal = LLVector3(0,0,0); mVertices[cur_vertex].mBinormal = LLVector3(0,0,0); + + update_min_max(face_min,face_max,mesh[i].mPos); + cur_vertex++; } } - mCenter /= (F32)num_vertices; + + mCenter = (face_min + face_max) * 0.5f; S32 cur_index = 0; S32 cur_edge = 0; @@ -4454,32 +4488,14 @@ BOOL LLVolumeFace::createSide() } } - //this loop would LOVE OpenMP - LLVector3 min = mVolumep->mBounds[0] - mVolumep->mBounds[1]; - LLVector3 max = mVolumep->mBounds[0] + mVolumep->mBounds[1]; - - if (min == max && min == LLVector3(512,512,512)) + //normalize normals and binormals here so the meshes that reference + //this volume data don't have to + for (U32 i = 0; i < mVertices.size(); i++) { - min = max = mVertices[0].mPosition; - } - - for (U32 i = 0; i < mVertices.size(); i++) { mVertices[i].mNormal.normVec(); mVertices[i].mBinormal.normVec(); - - for (U32 j = 0; j < 3; j++) { - if (mVertices[i].mPosition.mV[j] > max.mV[j]) { - max.mV[j] = mVertices[i].mPosition.mV[j]; - } - if (mVertices[i].mPosition.mV[j] < min.mV[j]) { - min.mV[j] = mVertices[i].mPosition.mV[j]; - } - } } - mVolumep->mBounds[0] = (min + max) * 0.5f; //center - mVolumep->mBounds[1] = (max - min) * 0.5f; //half-height - return TRUE; } @@ -4578,7 +4594,7 @@ LLVector3 calc_binormal_from_triangle( -r0.mV[VZ] / r0.mV[VX], -r1.mV[VZ] / r1.mV[VX], -r2.mV[VZ] / r2.mV[VX]); - //binormal.normVec(); + // binormal.normVec(); return binormal; } else diff --git a/linden/indra/llmath/llvolume.h b/linden/indra/llmath/llvolume.h index 63981da..91f7c9b 100644 --- a/linden/indra/llmath/llvolume.h +++ b/linden/indra/llmath/llvolume.h @@ -775,6 +775,8 @@ public: S32 mNumS; S32 mNumT; + LLVector3 mExtents[2]; //minimum and maximum point of face + std::vector mVertices; std::vector mIndices; std::vector mEdge; @@ -868,7 +870,6 @@ public: const LLVolumeFace &getVolumeFace(const S32 f) const {return mVolumeFaces[f];} // DO NOT DELETE VOLUME WHILE USING THIS REFERENCE, OR HOLD A POINTER TO THIS VOLUMEFACE U32 mFaceMask; // bit array of which faces exist in this volume - LLVector3 mBounds[2]; // bounding box (center, half-height) LLVector3 mLODScaleBias; // vector for biasing LOD based on scale protected: diff --git a/linden/indra/llmath/llvolumemgr.cpp b/linden/indra/llmath/llvolumemgr.cpp index 6b6182a..2aa480c 100644 --- a/linden/indra/llmath/llvolumemgr.cpp +++ b/linden/indra/llmath/llvolumemgr.cpp @@ -286,7 +286,7 @@ F32 LLVolumeLODGroup::getVolumeScaleFromDetail(const S32 detail) F32 LLVolumeLODGroup::dump() { - char dump_str[255]; + char dump_str[255]; /* Flawfinder: ignore */ F32 usage = 0.f; for (S32 i = 0; i < NUM_LODS; i++) { @@ -297,7 +297,7 @@ F32 LLVolumeLODGroup::dump() } usage = usage / (F32)NUM_LODS; - sprintf(dump_str, "%.3f %d %d %d %d", usage, mAccessCount[0], mAccessCount[1], mAccessCount[2], mAccessCount[3]); + snprintf(dump_str, sizeof(dump_str), "%.3f %d %d %d %d", usage, mAccessCount[0], mAccessCount[1], mAccessCount[2], mAccessCount[3]); /* Flawfinder: ignore */ llinfos << dump_str << llendl; return usage; diff --git a/linden/indra/llmath/m3math.cpp b/linden/indra/llmath/m3math.cpp index c5d2c2d..4d93af6 100644 --- a/linden/indra/llmath/m3math.cpp +++ b/linden/indra/llmath/m3math.cpp @@ -52,14 +52,14 @@ LLMatrix3::LLMatrix3(const LLQuaternion &q) { - *this = q.getMatrix3(); + setRot(q); } LLMatrix3::LLMatrix3(const F32 angle, const LLVector3 &vec) { LLQuaternion quat(angle, vec); - *this = setRot(quat); + setRot(quat); } LLMatrix3::LLMatrix3(const F32 angle, const LLVector3d &vec) @@ -67,60 +67,25 @@ LLMatrix3::LLMatrix3(const F32 angle, const LLVector3d &vec) LLVector3 vec_f; vec_f.setVec(vec); LLQuaternion quat(angle, vec_f); - *this = setRot(quat); + setRot(quat); } LLMatrix3::LLMatrix3(const F32 angle, const LLVector4 &vec) { LLQuaternion quat(angle, vec); - *this = setRot(quat); + setRot(quat); } LLMatrix3::LLMatrix3(const F32 angle, const F32 x, const F32 y, const F32 z) { LLVector3 vec(x, y, z); LLQuaternion quat(angle, vec); - *this = setRot(quat); + setRot(quat); } LLMatrix3::LLMatrix3(const F32 roll, const F32 pitch, const F32 yaw) { - // Rotates RH about x-axis by 'roll' then - // rotates RH about the old y-axis by 'pitch' then - // rotates RH about the original z-axis by 'yaw'. - // . - // /|\ yaw axis - // | __. - // ._ ___| /| pitch axis - // _||\ \\ |-. / - // \|| \_______\_|__\_/_______ - // | _ _ o o o_o_o_o o /_\_ ________\ roll axis - // // /_______/ /__________> / - // /_,-' // / - // /__,-' - - F32 cx, sx, cy, sy, cz, sz; - F32 cxsy, sxsy; - - cx = (F32)cos(roll); //A - sx = (F32)sin(roll); //B - cy = (F32)cos(pitch); //C - sy = (F32)sin(pitch); //D - cz = (F32)cos(yaw); //E - sz = (F32)sin(yaw); //F - - cxsy = cx * sy; //AD - sxsy = sx * sy; //BD - - mMatrix[0][0] = cy * cz; - mMatrix[1][0] = -cy * sz; - mMatrix[2][0] = sy; - mMatrix[0][1] = sxsy * cz + cx * sz; - mMatrix[1][1] = -sxsy * sz + cx * cz; - mMatrix[2][1] = -sx * cy; - mMatrix[0][2] = -cxsy * cz + sx * sz; - mMatrix[1][2] = cxsy * sz + sx * cz; - mMatrix[2][2] = cx * cy; + setRot(roll,pitch,yaw); } // From Matrix and Quaternion FAQ @@ -307,34 +272,64 @@ LLQuaternion LLMatrix3::quaternion() const // These functions take Rotation arguments const LLMatrix3& LLMatrix3::setRot(const F32 angle, const F32 x, const F32 y, const F32 z) { - LLMatrix3 mat(angle, x, y, z); - *this = mat; + setRot(LLQuaternion(angle,x,y,z)); return *this; } const LLMatrix3& LLMatrix3::setRot(const F32 angle, const LLVector3 &vec) { - LLMatrix3 mat(angle, vec); - *this = mat; + setRot(LLQuaternion(angle, vec)); return *this; } const LLMatrix3& LLMatrix3::setRot(const F32 roll, const F32 pitch, const F32 yaw) { - LLMatrix3 mat(roll, pitch, yaw); - *this = mat; + // Rotates RH about x-axis by 'roll' then + // rotates RH about the old y-axis by 'pitch' then + // rotates RH about the original z-axis by 'yaw'. + // . + // /|\ yaw axis + // | __. + // ._ ___| /| pitch axis + // _||\ \\ |-. / + // \|| \_______\_|__\_/_______ + // | _ _ o o o_o_o_o o /_\_ ________\ roll axis + // // /_______/ /__________> / + // /_,-' // / + // /__,-' + + F32 cx, sx, cy, sy, cz, sz; + F32 cxsy, sxsy; + + cx = (F32)cos(roll); //A + sx = (F32)sin(roll); //B + cy = (F32)cos(pitch); //C + sy = (F32)sin(pitch); //D + cz = (F32)cos(yaw); //E + sz = (F32)sin(yaw); //F + + cxsy = cx * sy; //AD + sxsy = sx * sy; //BD + + mMatrix[0][0] = cy * cz; + mMatrix[1][0] = -cy * sz; + mMatrix[2][0] = sy; + mMatrix[0][1] = sxsy * cz + cx * sz; + mMatrix[1][1] = -sxsy * sz + cx * cz; + mMatrix[2][1] = -sx * cy; + mMatrix[0][2] = -cxsy * cz + sx * sz; + mMatrix[1][2] = cxsy * sz + sx * cz; + mMatrix[2][2] = cx * cy; return *this; } const LLMatrix3& LLMatrix3::setRot(const LLQuaternion &q) { - LLMatrix3 mat(q); - *this = mat; + *this = q.getMatrix3(); return *this; } - const LLMatrix3& LLMatrix3::setRows(const LLVector3 &fwd, const LLVector3 &left, const LLVector3 &up) { mMatrix[0][0] = fwd.mV[0]; diff --git a/linden/indra/llmath/m3math.h b/linden/indra/llmath/m3math.h index 74c5203..494856a 100644 --- a/linden/indra/llmath/m3math.h +++ b/linden/indra/llmath/m3math.h @@ -51,9 +51,6 @@ class LLQuaternion; static const U32 NUM_VALUES_IN_MAT3 = 3; -#if LL_WINDOWS -__declspec( align(16) ) -#endif class LLMatrix3 { public: @@ -138,11 +135,7 @@ class LLMatrix3 friend const LLMatrix3& operator*=(LLMatrix3 &a, const LLMatrix3 &b); // Return a * b friend std::ostream& operator<<(std::ostream& s, const LLMatrix3 &a); // Stream a -} -#if LL_DARWIN -__attribute__ ((aligned (16))) -#endif -; +}; inline LLMatrix3::LLMatrix3(void) { diff --git a/linden/indra/llmath/m4math.h b/linden/indra/llmath/m4math.h index fe9b26a..7de29ed 100644 --- a/linden/indra/llmath/m4math.h +++ b/linden/indra/llmath/m4math.h @@ -92,9 +92,6 @@ class LLQuaternion; static const U32 NUM_VALUES_IN_MAT4 = 4; -#if LL_WINDOWS -__declspec(align(16)) -#endif class LLMatrix4 { public: @@ -237,11 +234,7 @@ public: friend const LLMatrix4& operator*=(LLMatrix4 &a, const F32 &b); // Return a * b friend std::ostream& operator<<(std::ostream& s, const LLMatrix4 &a); // Stream a -} -#if LL_DARWIN -__attribute__ ((aligned (16))) -#endif -; +}; inline LLMatrix4::LLMatrix4() diff --git a/linden/indra/llmath/v2math.h b/linden/indra/llmath/v2math.h index 1832403..c978fc0 100644 --- a/linden/indra/llmath/v2math.h +++ b/linden/indra/llmath/v2math.h @@ -317,6 +317,21 @@ inline LLVector2 operator-(const LLVector2 &a) return LLVector2( -a.mV[0], -a.mV[1] ); } +inline void update_min_max(LLVector2& min, LLVector2& max, const LLVector2& pos) +{ + for (U32 i = 0; i < 2; i++) + { + if (min.mV[i] > pos.mV[i]) + { + min.mV[i] = pos.mV[i]; + } + if (max.mV[i] < pos.mV[i]) + { + max.mV[i] = pos.mV[i]; + } + } +} + inline std::ostream& operator<<(std::ostream& s, const LLVector2 &a) { s << "{ " << a.mV[VX] << ", " << a.mV[VY] << " }"; diff --git a/linden/indra/llmath/v3color.h b/linden/indra/llmath/v3color.h index 606a810..06a94db 100644 --- a/linden/indra/llmath/v3color.h +++ b/linden/indra/llmath/v3color.h @@ -166,7 +166,7 @@ inline LLColor3::LLColor3(const F32 *vec) inline LLColor3::LLColor3(char* color_string) // takes a string of format "RRGGBB" where RR is hex 00..FF { - if (strlen(color_string) < 6) + if (strlen(color_string) < 6) /* Flawfinder: ignore */ { mV[0] = 0.f; mV[1] = 0.f; @@ -174,8 +174,8 @@ inline LLColor3::LLColor3(char* color_string) // takes a string of format "RRGGB return; } - static char tempstr[7]; - strncpy(tempstr,color_string,6); + static char tempstr[7]; /* Flawfinder: ignore */ + strncpy(tempstr,color_string,6); /* Flawfinder: ignore */ tempstr[6] = '\0'; mV[VZ] = (F32)strtol(&tempstr[4],NULL,16)/255.f; tempstr[4] = '\0'; diff --git a/linden/indra/llmath/v3math.cpp b/linden/indra/llmath/v3math.cpp index 39d3b70..a97b6d8 100644 --- a/linden/indra/llmath/v3math.cpp +++ b/linden/indra/llmath/v3math.cpp @@ -137,7 +137,7 @@ const LLVector3& LLVector3::rotVec(F32 angle, const LLVector3 &vec) { if ( !vec.isExactlyZero() && angle ) { - *this = *this * LLMatrix3(angle, vec); + *this = *this * LLQuaternion(angle, vec); } return *this; } @@ -147,7 +147,7 @@ const LLVector3& LLVector3::rotVec(F32 angle, F32 x, F32 y, F32 z) LLVector3 vec(x, y, z); if ( !vec.isExactlyZero() && angle ) { - *this = *this * LLMatrix3(angle, vec); + *this = *this * LLQuaternion(angle, vec); } return *this; } @@ -198,6 +198,33 @@ LLVector3::LLVector3(const LLVector4 &vec) mV[VZ] = (F32)vec.mV[VZ]; } +LLVector3::LLVector3(const LLSD& sd) +{ + setValue(sd); +} + +LLSD LLVector3::getValue() const +{ + LLSD ret; + ret[0] = mV[0]; + ret[1] = mV[1]; + ret[2] = mV[2]; + return ret; +} + +void LLVector3::setValue(const LLSD& sd) +{ + mV[0] = (F32) sd[0].asReal(); + mV[1] = (F32) sd[1].asReal(); + mV[2] = (F32) sd[2].asReal(); +} + +const LLVector3& LLVector3::operator=(const LLSD& sd) +{ + setValue(sd); + return *this; +} + const LLVector3& operator*=(LLVector3 &a, const LLQuaternion &rot) { const F32 rw = - rot.mQ[VX] * a.mV[VX] - rot.mQ[VY] * a.mV[VY] - rot.mQ[VZ] * a.mV[VZ]; diff --git a/linden/indra/llmath/v3math.h b/linden/indra/llmath/v3math.h index 68e60de..e7134eb 100644 --- a/linden/indra/llmath/v3math.h +++ b/linden/indra/llmath/v3math.h @@ -37,7 +37,7 @@ class LLMatrix3; class LLVector3d; class LLQuaternion; -// Llvector3 = |x y z w| +// LLvector3 = |x y z w| static const U32 LENGTHOFVECTOR3 = 3; @@ -60,32 +60,13 @@ class LLVector3 inline explicit LLVector3(const F32 *vec); // Initializes LLVector3 to (vec[0]. vec[1], vec[2]) explicit LLVector3(const LLVector3d &vec); // Initializes LLVector3 to (vec[0]. vec[1], vec[2]) explicit LLVector3(const LLVector4 &vec); // Initializes LLVector4 to (vec[0]. vec[1], vec[2]) - LLVector3(const LLSD& sd) - { - setValue(sd); - } + LLVector3(const LLSD& sd); - LLSD getValue() const - { - LLSD ret; - ret[0] = mV[0]; - ret[1] = mV[1]; - ret[2] = mV[2]; - return ret; - } + LLSD getValue() const; - void setValue(const LLSD& sd) - { - mV[0] = (F32) sd[0].asReal(); - mV[1] = (F32) sd[1].asReal(); - mV[2] = (F32) sd[2].asReal(); - } + void setValue(const LLSD& sd); - const LLVector3& operator=(const LLSD& sd) - { - setValue(sd); - return *this; - } + const LLVector3& operator=(const LLSD& sd); inline BOOL isFinite() const; // checks to see if all values of LLVector3 are finite BOOL clamp(F32 min, F32 max); // Clamps all values to (min,max), returns TRUE if data changed @@ -434,6 +415,20 @@ inline BOOL LLVector3::isNull() const return FALSE; } +inline void update_min_max(LLVector3& min, LLVector3& max, const LLVector3& pos) +{ + for (U32 i = 0; i < 3; i++) + { + if (min.mV[i] > pos.mV[i]) + { + min.mV[i] = pos.mV[i]; + } + if (max.mV[i] < pos.mV[i]) + { + max.mV[i] = pos.mV[i]; + } + } +} inline F32 angle_between(const LLVector3& a, const LLVector3& b) { diff --git a/linden/indra/llmath/v4math.h b/linden/indra/llmath/v4math.h index 06ac777..f768ba7 100644 --- a/linden/indra/llmath/v4math.h +++ b/linden/indra/llmath/v4math.h @@ -40,10 +40,6 @@ class LLQuaternion; static const U32 LENGTHOFVECTOR4 = 4; -#if LL_WINDOWS -__declspec( align(16) ) -#endif - class LLVector4 { public: @@ -114,12 +110,7 @@ class LLVector4 friend const LLVector4& operator/=(LLVector4 &a, F32 k); // Return a divided by scaler k friend LLVector4 operator-(const LLVector4 &a); // Return vector -a -} -#if LL_DARWIN -__attribute__ ((aligned (16))) -#endif -; - +}; // Non-member functions F32 angle_between(const LLVector4 &a, const LLVector4 &b); // Returns angle (radians) between a and b -- cgit v1.1