//--------------------------------------------------------------------------------------
	void PrePixelLightTransform::_SetParameters ()
	{
		Engine& engine = Engine::Instance();
		Device* device = engine.GetDevice();
		Environment* env = engine.GetEnvironment();
		ICamera* camera = engine.GetCamera();

		Matrix44f wvp = *m_pTransform * camera->GetViewProj();

		device->SetShaderParameter(m_hTransform, *m_pTransform);
		if( NULL == m_pColor )
		{
			device->SetShaderParameter(m_hColor, vector4f(1,1,1,1) );
		}
		else
		{
			device->SetShaderParameter(m_hColor, *m_pColor);
		}
		device->SetShaderParameter(m_hNormalTransform, Matrix33f( *m_pTransform ) );
		device->SetShaderParameter(m_hWorldViewProjMatrixLoc, wvp);
		device->SetShaderParameter(m_hLightDirectionLoc, -env->GetCurrentLight().GetWorldDirection());//phong光是像素到光源的方向,所以这里反向
		device->SetShaderParameter(m_hCameraPositionLoc, camera->GetPosition() );
		device->SetShaderParameter(m_hAmbientLoc, env->GetAmbient());
		device->SetShaderParameter(m_hLightLoc, env->GetCurrentLight().GetColor());
		//clean up
		m_pTransform = NULL;
		m_pColor = NULL;
	}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    /*MainWindow w;
    w.show();*/
    Vector<float, 2> A = Vector<float, 2>(0.0f);
    Vector<float, 2> B = Vector<float, 2>(0.0f);
    A[0] = 1.0f;
    A[1] = 0.5f;
    B[0] = 2.0f;
    B[1] = 4.0f;
    Vector<float, 2> C = Vector<float, 2>(B);
    Vec3f D = Vec3f(0.0f, 5.0f, 2.0f);
    Vec3f E = Vec3f(D);
    E[0] = 1.0f;
    Vec3f F = Vec3f(E);
    Vec2f translation = Vec2f(C);
    Matrix33f T = Matrix33f(D, E, F);
    Matrix33f M = T;
    Matrix33f R = T.applyTranslation(translation);
    R.applyRotation(30.0f);


    std::cout << "C :" << C << std::endl;
    std::cout << "T : {" << T[0] << ", " << T[1] << ", "
              << T[2] << "}" << std::endl;
    std::cout << "M : {" << M[0] << ", " << M[1] << ", "
              << M[2] << "}" << std::endl;
    std::cout << "R : {" << R[0] << ", " << R[1] << ", "
              << R[2] << "}" << std::endl;

    return a.exec();
}
Ejemplo n.º 3
0
	//--------------------------------------------------------------------------------------------------------------------------------------
	void EditCamera::Move( const vector3f& dis )
	{
		Matrix33f rot = Matrix33f( this->GetUnView() );
		vector3f movedis = dis * rot;
		movedis.m_y = 0;
		m_Target += movedis;
		this->_LookAt(this->GetPosition() + movedis, this->GetLookAt() + movedis, this->GetUp());
	}
Ejemplo n.º 4
0
//------------------------------------------------------------------------------
SceEllipsoid::SceEllipsoid(Vec3f const & center, 
                           Vec3f const & u, 
                           Vec3f const & v, 
                           Vec3f const & w, 
                           Material const & material)
: SceObject         (material)
, mCenter           (center)
, mMatrixInv        (Matrix33f(u, v, w).inverted())
, mMatrixInvTInv    (mMatrixInv.transposed() * mMatrixInv)
{
}
Ejemplo n.º 5
0
namespace gmtl {
    const Matrix22f MAT_IDENTITY22F = Matrix22f();
    const Matrix22d MAT_IDENTITY22D = Matrix22d();
    const Matrix23f MAT_IDENTITY23F = Matrix23f();
    const Matrix23d MAT_IDENTITY23D = Matrix23d();
    const Matrix33f MAT_IDENTITY33F = Matrix33f();
    const Matrix33d MAT_IDENTITY33D = Matrix33d();
    const Matrix34f MAT_IDENTITY34F = Matrix34f();
    const Matrix34d MAT_IDENTITY34D = Matrix34d();
    const Matrix44f MAT_IDENTITY44F = Matrix44f();
    const Matrix44d MAT_IDENTITY44D = Matrix44d();
}
Ejemplo n.º 6
0
Matrix33f UserTracker::getJointOrientation( XnUserID userId, XnSkeletonJoint jointId, float *conf /* = NULL */ )
{
	if (mObj->mUserGenerator.GetSkeletonCap().IsTracking( userId ))
	{
		XnSkeletonJointOrientation jointOri;
		mObj->mUserGenerator.GetSkeletonCap().GetSkeletonJointOrientation( userId, jointId, jointOri );

		if ( conf != NULL )
			*conf = jointOri.fConfidence;

		float *oriM = jointOri.orientation.elements;
		return Matrix33f( oriM[ 0 ], oriM[ 3 ], oriM[ 6 ],
						  oriM[ 1 ], oriM[ 4 ], oriM[ 7 ],
						  oriM[ 2 ], oriM[ 5 ], oriM[ 8 ] );
	}
	else
	{
		if ( conf != NULL )
			*conf = 0;

		return Matrix33f();
	}
}
Ejemplo n.º 7
0
	//
	// returns a matrix with a transformation that rotates around a certain axis which starts at the origin
	//
	// code from Graphics Gems (Glassner, Academic Press, 1990)
	//
	Matrix33f Matrix33f::RotationMatrix( const Vec3f &axis, const float &angle )
	{
		float c = cos( angle );
		float t = 1.0f - c;
		float s = sin( angle );
		float txy = t*axis.x*axis.y;
		float txz = t*axis.x*axis.z;
		float tyz = t*axis.y*axis.z;
		float sx = s*axis.x;
		float sy = s*axis.y;
		float sz = s*axis.z;
		return Matrix33f( t*axis.x*axis.x+c, txy+sz, txz-sy,
			              txy-sz, t*axis.y*axis.y+c, tyz+sx,
						  txz+sy, tyz-sx, t*axis.z*axis.z+c);
	}
Ejemplo n.º 8
0
	//--------------------------------------------------------------------------------------------------------------------------------------
	void Model::_UpDataJoint()
	{
		//计算子节点新位置
		for ( JointNode::iterator it = m_JointNodes.begin();
			it != m_JointNodes.end();
			)
		{
			if ( 0 == it->second->SonCount() )//没有子节点了,删除自己
			{
				DetachNode( it->second );
				SAFE_DELETE( it->second );
				JointNode::iterator temp = it++;
				m_JointNodes.erase( temp );
			}
			else//更新矩阵
			{
				Quaternionf real = m_JointVector[ it->second->m_JointIndex ].m_RealBind;
				Quaternionf dual = m_JointVector[ it->second->m_JointIndex ].m_DaulBind;

				const void* data;
				data = it->second->FatherAttribute( IAttributeNode::ATT_WORLDSCALE );
				it->second->m_Scale = NULL == data ? vector3f(1,1,1) :  *((const vector3f*)data);

				data = it->second->FatherAttribute( IAttributeNode::ATT_WORLDTRANSFORM );
				it->second->m_Transfrom = NULL == data ? Math::DualQuaternionToMatrix44( real, dual ) : Math::DualQuaternionToMatrix44( real, dual ) * *((const Matrix44f*)data);

				it->second->m_Position = vector3f( it->second->m_Transfrom.a41, it->second->m_Transfrom.a42, it->second->m_Transfrom.a43 );

				it->second->m_Rotation = it->second->m_Transfrom.ToQuaternion();

				it->second->m_RotationMatrix = Matrix33f( it->second->m_Transfrom );

				it->second->CastChangedMessage();//通知子节点
				it ++;
			}
		}
	}
Ejemplo n.º 9
0
	//
	// returns the identitymatrix
	//
	Matrix33f Matrix33f::Identity( void )
	{
		return Matrix33f( 1.0f, 0.0f, 0.0f,
			              0.0f, 1.0f, 0.0f,
						  0.0f, 0.0f, 1.0f);
	}
Ejemplo n.º 10
0
	//
	// returns the zeromatrix
	//
	Matrix33f Matrix33f::Zero( void )
	{
		return Matrix33f( 0.0f, 0.0f, 0.0f,
			              0.0f, 0.0f, 0.0f,
						  0.0f, 0.0f, 0.0f);
	}
Ejemplo n.º 11
0
	//--------------------------------------------------------------------------------------------------------------------------------------
	void FPSCamera::Move( const vector3f& dis )
	{
		Matrix33f rot = Matrix33f( this->GetUnView() );
		vector3f movedis = dis * rot;
		this->_LookAt(this->GetPosition() + movedis, this->GetLookAt() + movedis, this->GetUp());
	}
Ejemplo n.º 12
0
AppRenderer::AppRenderer()
{
	transform = Matrix33f();
}