transform.cpp

来自「java实现的简单的分形树。简单易学!是学习分形知识的很好的例子。其java语法」· C++ 代码 · 共 65 行

CPP
65
字号
// --------------------------------------------------------------------------
// Dingus project - a collection of subsystems for game/graphics applications
// --------------------------------------------------------------------------
#include "stdafx.h"

#include "Transform.h"

using namespace dingus;


CTransform::CTransform()
{
	identify();
}

CTransform::CTransform( SVector3 const& pos, D3DXQUATERNION const& rot )
:	mPosition( pos ),
	mRotation( rot )
{
}

CTransform::CTransform( CTransform const& r )
:	mPosition( r.mPosition ),
	mRotation( r.mRotation )
{
}

CTransform const& CTransform::operator=( CTransform const& rh )
{
	mPosition = rh.mPosition;
	mRotation = rh.mRotation;
	return *this;
}

void CTransform::setFromMatrix( SMatrix4x4 const& m )
{
	mPosition = m.getOrigin();
	D3DXQuaternionRotationMatrix( &mRotation, &m );
}

void CTransform::identify()
{
	D3DXQuaternionIdentity( &mRotation );
	mPosition.set( 0,0,0 );
}

void CTransform::toMatrix( SMatrix4x4& m ) const
{
	D3DXMatrixRotationQuaternion( &m, &mRotation );
	m.getOrigin() = mPosition;
}


/**

Have a parent transform: Pv/Pq and child: Cv/Cq.

If we had matrices Pm and Cm, then child matrix in world space would be:
	CWm = Cm * PWm.

For transforms:
	CWm = (Cq, Cv) * PWm
	    = (Cq, Cv) * (Pq, Pw)
*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?