LLCamera LLSpatialBridge::transformCamera(LLCamera& camera)
{
	LLCamera ret = camera;
	LLXformMatrix* mat = mDrawable->getXform();
	LLVector3 center = LLVector3(0,0,0) * mat->getWorldMatrix();
	LLQuaternion rotation = LLQuaternion(mat->getWorldMatrix());

	LLVector3 delta = ret.getOrigin() - center;
	LLQuaternion rot = ~mat->getRotation();

	delta *= rot;
	LLVector3 lookAt = ret.getAtAxis();
	LLVector3 up_axis = ret.getUpAxis();
	LLVector3 left_axis = ret.getLeftAxis();

	lookAt *= rot;
	up_axis *= rot;
	left_axis *= rot;

	if (!delta.isFinite())
	{
		delta.clearVec();
	}

	ret.setOrigin(delta);
	ret.setAxes(lookAt, left_axis, up_axis);
		
	return ret;
}
Beispiel #2
0
void LLSpatialBridge::updateSpatialExtents()
{
	LLSpatialGroup* root = (LLSpatialGroup*) mOctree->getListener(0);
	
	{
		LLFastTimer ftm(LLFastTimer::FTM_CULL_REBOUND);
		root->rebound();
	}
	
	LLXformMatrix* mat = mDrawable->getXform();
	
	LLVector3 offset = root->mBounds[0];
	LLVector3 size = root->mBounds[1];
		
	LLVector3 center = LLVector3(0,0,0) * mat->getWorldMatrix();
	LLQuaternion rotation = LLQuaternion(mat->getWorldMatrix());
	
	offset *= rotation;
	center += offset;
	
	LLVector3 v[4];
	//get 4 corners of bounding box
	v[0] = (size * rotation);
	v[1] = (LLVector3(-size.mV[0], -size.mV[1], size.mV[2]) * rotation);
	v[2] = (LLVector3(size.mV[0], -size.mV[1], -size.mV[2]) * rotation);
	v[3] = (LLVector3(-size.mV[0], size.mV[1], -size.mV[2]) * rotation);

	LLVector3& newMin = mExtents[0];
	LLVector3& newMax = mExtents[1];
	
	newMin = newMax = center;
	
	for (U32 i = 0; i < 4; i++)
	{
		for (U32 j = 0; j < 3; j++)
		{
			F32 delta = fabsf(v[i].mV[j]);
			F32 min = center.mV[j] - delta;
			F32 max = center.mV[j] + delta;
			
			if (min < newMin.mV[j])
			{
				newMin.mV[j] = min;
			}
			
			if (max > newMax.mV[j])
			{
				newMax.mV[j] = max;
			}
		}
	}

	LLVector3 diagonal = newMax - newMin;
	mRadius = diagonal.magVec() * 0.5f;
	
	mPositionGroup.setVec((newMin + newMax) * 0.5f);
	updateBinRadius();
}
Beispiel #3
0
LLCamera LLSpatialBridge::transformCamera(LLCamera& camera)
{
	LLCamera ret = camera;
	LLXformMatrix* mat = mDrawable->getXform();
	const LLVector4a& center = mat->getWorldMatrix().getRow<3>();

	LLQuaternion2 invRot;
	invRot.setConjugate( LLQuaternion2(mat->getRotation()) );

	LLVector4a delta;
	delta.load3(ret.getOrigin().mV);
	delta.sub(center);

	LLVector4a lookAt;
	lookAt.load3(ret.getAtAxis().mV);
	LLVector4a up_axis;

	up_axis.load3(ret.getUpAxis().mV);
	LLVector4a left_axis;
	left_axis.load3(ret.getLeftAxis().mV);

	delta.setRotated(invRot, delta);
	lookAt.setRotated(invRot, lookAt);
	up_axis.setRotated(invRot, up_axis);
	left_axis.setRotated(invRot, left_axis);

	if (!delta.isFinite3())
	{
		delta.clear();
	}

	ret.setOrigin(LLVector3(delta.getF32ptr()));
	ret.setAxes(LLVector3(lookAt.getF32ptr()), LLVector3(left_axis.getF32ptr()), LLVector3(up_axis.getF32ptr()));
		
	return ret;
}
Beispiel #4
0
	void xform_test_object_t::test<7>()	
	{
		LLXformMatrix formMatrix_obj;

		LLXformMatrix parent;
		LLVector3 llvecpos(1.0, 2.0, 3.0);
		LLVector3 llvecpospar(10.0, 20.0, 30.0);
		formMatrix_obj.setPosition(llvecpos);
		parent.setPosition(llvecpospar);

		LLVector3 llvecparentscale(1.0, 2.0, 0);
		parent.setScaleChildOffset(TRUE);
		parent.setScale(llvecparentscale);

		LLQuaternion quat(1, 2, 3, 4);
		LLQuaternion quatparent(5, 6, 7, 8);
		formMatrix_obj.setRotation(quat);
		parent.setRotation(quatparent);
		formMatrix_obj.setParent(&parent);

		parent.update();
		formMatrix_obj.update();

		LLVector3 worldPos = llvecpos;
		worldPos.scaleVec(llvecparentscale);
		worldPos *= quatparent;
		worldPos += llvecpospar;

		LLQuaternion worldRot = quat * quatparent; 

		ensure("getWorldPosition failed: ", formMatrix_obj.getWorldPosition() == worldPos);
		ensure("getWorldRotation failed: ", formMatrix_obj.getWorldRotation() == worldRot);

		ensure("getWorldPosition for parent failed: ", parent.getWorldPosition() == llvecpospar);
		ensure("getWorldRotation for parent failed: ", parent.getWorldRotation() == quatparent);
	}