当前位置: 首页>>代码示例>>C++>>正文


C++ Matrix4x4::DXMatrix方法代码示例

本文整理汇总了C++中Matrix4x4::DXMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix4x4::DXMatrix方法的具体用法?C++ Matrix4x4::DXMatrix怎么用?C++ Matrix4x4::DXMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Matrix4x4的用法示例。


在下文中一共展示了Matrix4x4::DXMatrix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SetupMatrices

//-----------------------------------------------------------------------------
// Name: SetupMatrices()
// Desc: Sets up the world, view, and projection transform matrices.
//-----------------------------------------------------------------------------
VOID SetupMatrices()
{
	// Yaw: Rotate around the Y axis
	// USING MATRIX (EULER ANGLE, YAW):
	//Matrix4x4 matYaw = Yaw( timeGetTime() / 2000.0f );
	
	// USING QUATERNION:
	Vector3 rotationAxis(0, 1, 0);		// Rotate Y axis
	float rotationAngle = sinf( timeGetTime() / 2000.0f );
	Quaternion myRotation( FromAxisAngle( rotationAxis, rotationAngle ) );
	Quaternion additionalRotation( 0, 0, 1, 0 );
	Quaternion slerpTest = Slerp( myRotation, additionalRotation, rotationAngle );
	g_rotationMatrix = ConvertToMatrix4x4( slerpTest );
	
	// NOTE: I DON'T KNOW IF I'M USING QUATERNIONS RIGHT!!!

	// Position matrix:
	Matrix4x4 matMove;
	if ( g_renderSetting == 6 )
		matMove = Position( 0.0f, 0.0f, 0.5f * sinf( timeGetTime() / 500.0f) * 3.0f );
	else
		matMove = Position( 0.0f, 0.0f, 0.0f );
	
	// Multiply the quaternion matrix by the position matrix
	g_matWorld = g_rotationMatrix * matMove;

	// Set it and forget it
	g_pd3dDevice->SetTransform( D3DTS_WORLD, &g_matWorld.DXMatrix() );
	
    // Set up our view matrix. A view matrix can be defined given an eye point,
    // a point to lookat, and a direction for which way is up. Here, we set the
    // eye five units back along the z-axis and up three units, look at the
    // origin, and define "up" to be in the y-direction.
    Vector3 vEyePt( 0.0f, 3.0f, -7.0f );
    Vector3 vLookatPt( 0.0f, 0.0f, 0.0f );
    Vector3 vUpVec( 0.0f, 1.0f, 0.0f );
	Matrix4x4 matView = View( vEyePt, vLookatPt, vUpVec );
	g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView.DXMatrix() );

    // For the projection matrix, we set up a perspective transform (which
    // transforms geometry from 3D view space to 2D viewport space, with
    // a perspective divide making objects smaller in the distance). To build
    // a perpsective transform, we need the field of view (1/4 pi is common),
    // the aspect ratio, and the near and far clipping planes (which define at
    // what distances geometry should be no longer be rendered).
	Matrix4x4 matProj = Perspective( D3DX_PI / 4, (float)(WIDTH) / (float)(HEIGHT), 1.0f, 100.0f );
	g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj.DXMatrix() );
}
开发者ID:FOBBEH,项目名称:Rendering-Demo,代码行数:52,代码来源:RenderingDemo.cpp


注:本文中的Matrix4x4::DXMatrix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。