PageRenderTime 17ms CodeModel.GetById 1ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmath/xform.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 119 lines | 77 code | 17 blank | 25 comment | 4 complexity | 5fbd19e7c2224129287eeb145769514c MD5 | raw file
  1/** 
  2 * @file xform.cpp
  3 *
  4 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  5 * Second Life Viewer Source Code
  6 * Copyright (C) 2010, Linden Research, Inc.
  7 * 
  8 * This library is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU Lesser General Public
 10 * License as published by the Free Software Foundation;
 11 * version 2.1 of the License only.
 12 * 
 13 * This library is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 16 * Lesser General Public License for more details.
 17 * 
 18 * You should have received a copy of the GNU Lesser General Public
 19 * License along with this library; if not, write to the Free Software
 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 21 * 
 22 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 23 * $/LicenseInfo$
 24 */
 25
 26#include "linden_common.h"
 27
 28#include "xform.h"
 29
 30LLXform::LLXform()
 31{
 32	init();
 33}
 34
 35LLXform::~LLXform()
 36{
 37}
 38
 39// Link optimization - don't inline these llwarns
 40void LLXform::warn(const char* const msg)
 41{
 42	llwarns << msg << llendl;
 43}
 44
 45LLXform* LLXform::getRoot() const
 46{
 47	const LLXform* root = this;
 48	while(root->mParent)
 49	{
 50		root = root->mParent;
 51	}
 52	return (LLXform*)root;
 53}
 54
 55BOOL LLXform::isRoot() const
 56{
 57	return (!mParent);
 58}
 59
 60BOOL LLXform::isRootEdit() const
 61{
 62	return (!mParent);
 63}
 64
 65LLXformMatrix::~LLXformMatrix()
 66{
 67}
 68
 69void LLXformMatrix::update()
 70{
 71	if (mParent) 
 72	{
 73		mWorldPosition = mPosition;
 74		if (mParent->getScaleChildOffset())
 75		{
 76			mWorldPosition.scaleVec(mParent->getScale());
 77		}
 78		mWorldPosition *= mParent->getWorldRotation();
 79		mWorldPosition += mParent->getWorldPosition();
 80		mWorldRotation = mRotation * mParent->getWorldRotation();
 81	}
 82	else
 83	{
 84		mWorldPosition = mPosition;
 85		mWorldRotation = mRotation;
 86	}
 87}
 88
 89void LLXformMatrix::updateMatrix(BOOL update_bounds)
 90{
 91	update();
 92
 93	mWorldMatrix.initAll(mScale, mWorldRotation, mWorldPosition);
 94
 95	if (update_bounds && (mChanged & MOVED))
 96	{
 97		mMin.mV[0] = mMax.mV[0] = mWorldMatrix.mMatrix[3][0];
 98		mMin.mV[1] = mMax.mV[1] = mWorldMatrix.mMatrix[3][1];
 99		mMin.mV[2] = mMax.mV[2] = mWorldMatrix.mMatrix[3][2];
100
101		F32 f0 = (fabs(mWorldMatrix.mMatrix[0][0])+fabs(mWorldMatrix.mMatrix[1][0])+fabs(mWorldMatrix.mMatrix[2][0])) * 0.5f;
102		F32 f1 = (fabs(mWorldMatrix.mMatrix[0][1])+fabs(mWorldMatrix.mMatrix[1][1])+fabs(mWorldMatrix.mMatrix[2][1])) * 0.5f;
103		F32 f2 = (fabs(mWorldMatrix.mMatrix[0][2])+fabs(mWorldMatrix.mMatrix[1][2])+fabs(mWorldMatrix.mMatrix[2][2])) * 0.5f;
104
105		mMin.mV[0] -= f0; 
106		mMin.mV[1] -= f1; 
107		mMin.mV[2] -= f2; 
108
109		mMax.mV[0] += f0; 
110		mMax.mV[1] += f1; 
111		mMax.mV[2] += f2; 
112	}
113}
114
115void LLXformMatrix::getMinMax(LLVector3& min, LLVector3& max) const
116{
117	min = mMin;
118	max = mMax;
119}