V2 llmath merge part 2

This commit is contained in:
Shyotl
2011-02-23 01:40:47 -06:00
parent 7deee9336c
commit 723fa64f6f
20 changed files with 426 additions and 38 deletions

View File

@@ -37,36 +37,6 @@
#include "llsd.h"
// vector3
class LLVector3;
LLSD ll_sd_from_vector3(const LLVector3& vec);
LLVector3 ll_vector3_from_sd(const LLSD& sd, S32 start_index = 0);
// vector4
class LLVector4;
LLSD ll_sd_from_vector4(const LLVector4& vec);
LLVector4 ll_vector4_from_sd(const LLSD& sd, S32 start_index = 0);
// vector3d (double)
class LLVector3d;
LLSD ll_sd_from_vector3d(const LLVector3d& vec);
LLVector3d ll_vector3d_from_sd(const LLSD& sd, S32 start_index = 0);
// vector2
class LLVector2;
LLSD ll_sd_from_vector2(const LLVector2& vec);
LLVector2 ll_vector2_from_sd(const LLSD& sd);
// Quaternion
class LLQuaternion;
LLSD ll_sd_from_quaternion(const LLQuaternion& quat);
LLQuaternion ll_quaternion_from_sd(const LLSD& sd);
// color4
class LLColor4;
LLSD ll_sd_from_color4(const LLColor4& c);
LLColor4 ll_color4_from_sd(const LLSD& sd);
// U32
LL_COMMON_API LLSD ll_sd_from_U32(const U32);
LL_COMMON_API U32 ll_U32_from_sd(const LLSD& sd);

View File

@@ -43,7 +43,7 @@
#include "llsdutil.h"
#include "lltransactiontypes.h"
#include "lltransactionflags.h"
#include "llsdutil.h"
#include "llsdutil_math.h"
#include "message.h"
#include "u64.h"
@@ -677,6 +677,7 @@ void LLParcel::packMessage(LLMessageSystem* msg)
// Assumes we are in a block "ParcelData"
void LLParcel::packMessage(LLSD& msg)
{
// used in the viewer, the sim uses it's own packer
msg["local_id"] = getLocalID();
msg["parcel_flags"] = ll_sd_from_U32(getParcelFlags());
msg["sale_price"] = getSalePrice();
@@ -705,7 +706,6 @@ void LLParcel::packMessage(LLSD& msg)
msg["category"] = (U8)mCategory;
msg["auth_buyer_id"] = mAuthBuyerID;
msg["snapshot_id"] = mSnapshotID;
msg["snapshot_id"] = mSnapshotID;
msg["user_location"] = ll_sd_from_vector3(mUserLocation);
msg["user_look_at"] = ll_sd_from_vector3(mUserLookAt);
msg["landing_type"] = (U8)mLandingType;

View File

@@ -10,12 +10,14 @@ include_directories(
)
set(llmath_SOURCE_FILES
llbbox.cpp
llbboxlocal.cpp
llcalc.cpp
llcalcparser.cpp
llcamera.cpp
llcoordframe.cpp
llline.cpp
llmodularmath.cpp
llperlin.cpp
llquaternion.cpp
llrect.cpp
@@ -41,6 +43,7 @@ set(llmath_HEADER_FILES
camera.h
coordframe.h
llbbox.h
llbboxlocal.h
llcalc.h
llcalcparser.h
@@ -50,6 +53,7 @@ set(llmath_HEADER_FILES
llinterp.h
llline.h
llmath.h
llmodularmath.h
lloctree.h
llperlin.h
llplane.h
@@ -64,6 +68,7 @@ set(llmath_HEADER_FILES
llv4vector3.h
llvolume.h
llvolumemgr.h
llsdutil_math.h
m3math.h
m4math.h
raytrace.h

186
indra/llmath/llbbox.cpp Normal file
View File

@@ -0,0 +1,186 @@
/**
* @file llbbox.cpp
* @brief General purpose bounding box class (Not axis aligned)
*
* $LicenseInfo:firstyear=2001&license=viewergpl$
*
* Copyright (c) 2001-2010, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlife.com/developers/opensource/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlife.com/developers/opensource/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*
*/
#include "linden_common.h"
// self include
#include "llbbox.h"
// library includes
#include "m4math.h"
void LLBBox::addPointLocal(const LLVector3& p)
{
if (mEmpty)
{
mMinLocal = p;
mMaxLocal = p;
mEmpty = FALSE;
}
else
{
mMinLocal.mV[VX] = llmin( p.mV[VX], mMinLocal.mV[VX] );
mMinLocal.mV[VY] = llmin( p.mV[VY], mMinLocal.mV[VY] );
mMinLocal.mV[VZ] = llmin( p.mV[VZ], mMinLocal.mV[VZ] );
mMaxLocal.mV[VX] = llmax( p.mV[VX], mMaxLocal.mV[VX] );
mMaxLocal.mV[VY] = llmax( p.mV[VY], mMaxLocal.mV[VY] );
mMaxLocal.mV[VZ] = llmax( p.mV[VZ], mMaxLocal.mV[VZ] );
}
}
void LLBBox::addPointAgent( LLVector3 p)
{
p -= mPosAgent;
p.rotVec( ~mRotation );
addPointLocal( p );
}
void LLBBox::addBBoxAgent(const LLBBox& b)
{
if (mEmpty)
{
mPosAgent = b.mPosAgent;
mRotation = b.mRotation;
mMinLocal.clearVec();
mMaxLocal.clearVec();
}
LLVector3 vertex[8];
vertex[0].setVec( b.mMinLocal.mV[VX], b.mMinLocal.mV[VY], b.mMinLocal.mV[VZ] );
vertex[1].setVec( b.mMinLocal.mV[VX], b.mMinLocal.mV[VY], b.mMaxLocal.mV[VZ] );
vertex[2].setVec( b.mMinLocal.mV[VX], b.mMaxLocal.mV[VY], b.mMinLocal.mV[VZ] );
vertex[3].setVec( b.mMinLocal.mV[VX], b.mMaxLocal.mV[VY], b.mMaxLocal.mV[VZ] );
vertex[4].setVec( b.mMaxLocal.mV[VX], b.mMinLocal.mV[VY], b.mMinLocal.mV[VZ] );
vertex[5].setVec( b.mMaxLocal.mV[VX], b.mMinLocal.mV[VY], b.mMaxLocal.mV[VZ] );
vertex[6].setVec( b.mMaxLocal.mV[VX], b.mMaxLocal.mV[VY], b.mMinLocal.mV[VZ] );
vertex[7].setVec( b.mMaxLocal.mV[VX], b.mMaxLocal.mV[VY], b.mMaxLocal.mV[VZ] );
LLMatrix4 m( b.mRotation );
m.translate( b.mPosAgent );
m.translate( -mPosAgent );
m.rotate( ~mRotation );
for( S32 i=0; i<8; i++ )
{
addPointLocal( vertex[i] * m );
}
}
LLBBox LLBBox::getAxisAligned() const
{
// no rotation = axis aligned rotation
LLBBox aligned(mPosAgent, LLQuaternion(), LLVector3(), LLVector3());
// add the center point so that it's not empty
aligned.addPointAgent(mPosAgent);
// add our BBox
aligned.addBBoxAgent(*this);
return aligned;
}
void LLBBox::expand( F32 delta )
{
mMinLocal.mV[VX] -= delta;
mMinLocal.mV[VY] -= delta;
mMinLocal.mV[VZ] -= delta;
mMaxLocal.mV[VX] += delta;
mMaxLocal.mV[VY] += delta;
mMaxLocal.mV[VZ] += delta;
}
LLVector3 LLBBox::localToAgent(const LLVector3& v) const
{
LLMatrix4 m( mRotation );
m.translate( mPosAgent );
return v * m;
}
LLVector3 LLBBox::agentToLocal(const LLVector3& v) const
{
LLMatrix4 m;
m.translate( -mPosAgent );
m.rotate( ~mRotation ); // inverse rotation
return v * m;
}
LLVector3 LLBBox::localToAgentBasis(const LLVector3& v) const
{
LLMatrix4 m( mRotation );
return v * m;
}
LLVector3 LLBBox::agentToLocalBasis(const LLVector3& v) const
{
LLMatrix4 m( ~mRotation ); // inverse rotation
return v * m;
}
BOOL LLBBox::containsPointLocal(const LLVector3& p) const
{
if ( (p.mV[VX] < mMinLocal.mV[VX])
||(p.mV[VX] > mMaxLocal.mV[VX])
||(p.mV[VY] < mMinLocal.mV[VY])
||(p.mV[VY] > mMaxLocal.mV[VY])
||(p.mV[VZ] < mMinLocal.mV[VZ])
||(p.mV[VZ] > mMaxLocal.mV[VZ]))
{
return FALSE;
}
return TRUE;
}
BOOL LLBBox::containsPointAgent(const LLVector3& p) const
{
LLVector3 point_local = agentToLocal(p);
return containsPointLocal(point_local);
}
LLVector3 LLBBox::getMinAgent() const
{
return localToAgent(mMinLocal);
}
LLVector3 LLBBox::getMaxAgent() const
{
return localToAgent(mMaxLocal);
}
/*
LLBBox operator*(const LLBBox &a, const LLMatrix4 &b)
{
return LLBBox( a.mMin * b, a.mMax * b );
}
*/

109
indra/llmath/llbbox.h Normal file
View File

@@ -0,0 +1,109 @@
/**
* @file llbbox.h
* @brief General purpose bounding box class
*
* $LicenseInfo:firstyear=2001&license=viewergpl$
*
* Copyright (c) 2001-2010, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlife.com/developers/opensource/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlife.com/developers/opensource/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*
*/
#ifndef LL_BBOX_H
#define LL_BBOX_H
#include "v3math.h"
#include "llquaternion.h"
// Note: "local space" for an LLBBox is defined relative to agent space in terms of
// a translation followed by a rotation. There is no scale term since the LLBBox's min and
// max are not necessarily symetrical and define their own extents.
class LLBBox
{
public:
LLBBox() {mEmpty = TRUE;}
LLBBox( const LLVector3& pos_agent,
const LLQuaternion& rot,
const LLVector3& min_local,
const LLVector3& max_local )
:
mMinLocal( min_local ), mMaxLocal( max_local ), mPosAgent(pos_agent), mRotation( rot), mEmpty( TRUE )
{}
// Default copy constructor is OK.
const LLVector3& getPositionAgent() const { return mPosAgent; }
const LLQuaternion& getRotation() const { return mRotation; }
LLVector3 getMinAgent() const;
const LLVector3& getMinLocal() const { return mMinLocal; }
void setMinLocal( const LLVector3& min ) { mMinLocal = min; }
LLVector3 getMaxAgent() const;
const LLVector3& getMaxLocal() const { return mMaxLocal; }
void setMaxLocal( const LLVector3& max ) { mMaxLocal = max; }
LLVector3 getCenterLocal() const { return (mMaxLocal - mMinLocal) * 0.5f + mMinLocal; }
LLVector3 getCenterAgent() const { return localToAgent( getCenterLocal() ); }
LLVector3 getExtentLocal() const { return mMaxLocal - mMinLocal; }
BOOL containsPointLocal(const LLVector3& p) const;
BOOL containsPointAgent(const LLVector3& p) const;
void addPointAgent(LLVector3 p);
void addBBoxAgent(const LLBBox& b);
void addPointLocal(const LLVector3& p);
void addBBoxLocal(const LLBBox& b) { addPointLocal( b.mMinLocal ); addPointLocal( b.mMaxLocal ); }
void expand( F32 delta );
LLVector3 localToAgent( const LLVector3& v ) const;
LLVector3 agentToLocal( const LLVector3& v ) const;
// Changes rotation but not position
LLVector3 localToAgentBasis(const LLVector3& v) const;
LLVector3 agentToLocalBasis(const LLVector3& v) const;
// Get the smallest possible axis aligned bbox that contains this bbox
LLBBox getAxisAligned() const;
// friend LLBBox operator*(const LLBBox& a, const LLMatrix4& b);
private:
LLVector3 mMinLocal;
LLVector3 mMaxLocal;
LLVector3 mPosAgent; // Position relative to Agent's Region
LLQuaternion mRotation;
BOOL mEmpty; // Nothing has been added to this bbox yet
};
//LLBBox operator*(const LLBBox &a, const LLMatrix4 &b);
#endif // LL_BBOX_H

View File

@@ -0,0 +1,38 @@
/**
* @file llmodularmath.cpp
* @brief LLModularMath class implementation
*
* $LicenseInfo:firstyear=2001&license=viewergpl$
*
* Copyright (c) 2001-2010, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlife.com/developers/opensource/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlife.com/developers/opensource/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*
*/
#include "linden_common.h"
// implementation is all in the header, this include dep ensures the unit test is rerun if the implementation changes.
#include "llmodularmath.h"

View File

@@ -0,0 +1,72 @@
/**
* @file llsdutil_math.h
* @author Brad
* @date 2009-05-19
* @brief Utility classes, functions, etc, for using structured data with math classes.
*
* $LicenseInfo:firstyear=2009&license=viewergpl$
*
* Copyright (c) 2009-2010, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlife.com/developers/opensource/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlife.com/developers/opensource/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*
*/
#ifndef LL_LLSDUTIL_MATH_H
#define LL_LLSDUTIL_MATH_H
class LL_COMMON_API LLSD;
// vector3
class LLVector3;
LLSD ll_sd_from_vector3(const LLVector3& vec);
LLVector3 ll_vector3_from_sd(const LLSD& sd, S32 start_index = 0);
// vector4
class LLVector4;
LLSD ll_sd_from_vector4(const LLVector4& vec);
LLVector4 ll_vector4_from_sd(const LLSD& sd, S32 start_index = 0);
// vector3d (double)
class LLVector3d;
LLSD ll_sd_from_vector3d(const LLVector3d& vec);
LLVector3d ll_vector3d_from_sd(const LLSD& sd, S32 start_index = 0);
// vector2
class LLVector2;
LLSD ll_sd_from_vector2(const LLVector2& vec);
LLVector2 ll_vector2_from_sd(const LLSD& sd);
// Quaternion
class LLQuaternion;
LLSD ll_sd_from_quaternion(const LLQuaternion& quat);
LLQuaternion ll_quaternion_from_sd(const LLSD& sd);
// color4
class LLColor4;
LLSD ll_sd_from_color4(const LLColor4& c);
LLColor4 ll_color4_from_sd(const LLSD& sd);
#endif // LL_LLSDUTIL_MATH_H

View File

@@ -40,7 +40,7 @@
#include "lluuid.h"
#include "llsd.h"
#include "llsdserialize.h"
#include "llsdutil.h"
#include "llsdutil_math.h"
#include "llmemory.h"
#include "message.h"

View File

@@ -39,6 +39,8 @@
#include "v4coloru.h"
#include "llsdutil.h"
#include "llsdutil_math.h"
const S32 PS_PART_DATA_BLOCK_SIZE = 4 + 2 + 4 + 4 + 2 + 2; // 18

View File

@@ -37,6 +37,7 @@
#include "llmessagetemplate.h"
#include "llquaternion.h"
#include "llsdutil.h"
#include "llsdutil_math.h"
#include "llsdserialize.h"
#include "u64.h"
#include "v3dmath.h"

View File

@@ -38,6 +38,7 @@
#include "llsdmessagebuilder.h"
#include "llsdutil.h"
#include "llsdutil_math.h"
#include "v3math.h"
#include "v4math.h"
#include "v3dmath.h"

View File

@@ -43,7 +43,7 @@
#include "llvolumemgr.h"
#include "llstring.h"
#include "lldatapacker.h"
#include "llsdutil.h"
#include "llsdutil_math.h"
/**
* exported constants

View File

@@ -33,7 +33,7 @@
#include "linden_common.h"
#include "lltextureentry.h"
#include "llsdutil.h"
#include "llsdutil_math.h"
const U8 DEFAULT_BUMP_CODE = 0; // no bump or shininess

View File

@@ -4,6 +4,7 @@
#include "llfloaterexport.h"
#include "lluictrlfactory.h"
#include "llsdutil.h"
#include "llsdutil_math.h"
#include "llsdserialize.h"
#include "llselectmgr.h"
#include "llscrolllistctrl.h"

View File

@@ -42,6 +42,7 @@
#include "llfloaterchat.h"
#include "llsdserialize.h"
#include "llsdutil.h"
#include "llsdutil_math.h"
#include "lluictrlfactory.h" // builds floaters from XML
#include "llurlhistory.h"
#include "lluserauth.h" // for saving placeavatarresponder result

View File

@@ -7,7 +7,7 @@
#include "llviewerprecompiledheaders.h"
#include "llimportobject.h"
#include "llsdserialize.h"
#include "llsdutil.h"
#include "llsdutil_math.h"
#include "llviewerobject.h"
#include "llagent.h"
#include "llchat.h"

View File

@@ -39,7 +39,7 @@
#include "llerror.h"
#include "llbutton.h"
#include "llhttpclient.h"
#include "llsdutil.h"
#include "llsdutil_math.h"
#include "llstring.h"
#include "lluictrlfactory.h"

View File

@@ -57,6 +57,7 @@
//#include "llviewermenu.h" // create_landmark()
#include "llweb.h"
#include "llsdutil.h"
#include "llsdutil_math.h"
#include "hippogridmanager.h"

View File

@@ -74,7 +74,7 @@
#include "llregionhandle.h"
#include "llsd.h"
#include "llsdserialize.h"
#include "llsdutil.h"
#include "llsdutil_math.h"
#include "llsecondlifeurls.h"
#include "llstring.h"
#include "lluserrelations.h"

View File

@@ -58,6 +58,7 @@
#include "llparcelselection.h"
#include "llresmgr.h"
#include "llsdutil.h"
#include "llsdutil_math.h"
#include "llstatusbar.h"
#include "llui.h"
#include "llviewerimage.h"