本文整理汇总了C++中Matrix4::CreateFromQuaternion方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix4::CreateFromQuaternion方法的具体用法?C++ Matrix4::CreateFromQuaternion怎么用?C++ Matrix4::CreateFromQuaternion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix4
的用法示例。
在下文中一共展示了Matrix4::CreateFromQuaternion方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: viewRotation
SpaceShooter::SpaceShooter()
{
Renderer::Get().Initialize();
// Create the player's view.
Quaternion viewRotation( Vector3::Right, Pi / 2.f );
mCamera = ViewPtr( new View( Vector3( 0.f, 60.f, 0.f ), viewRotation, 1.04719755f, 1920.0f / 1080.0f, 0.1f, 100.f, false ) );
Renderer::Get().SetCamera( mCamera );
// Create the background.
MaterialPtr backgroundMaterial = MaterialPtr( new Material( L"Resources\\Shaders\\tangent.hlsl", L"Resources\\Textures\\starfield.dds" ) );
RawMeshPtr backgroundMesh = RawMeshPtr( new RawMesh() );
GenerateQuadVerticies( *backgroundMesh.get(), 90.f, 45.f );
MeshPrimitivePtr background = MeshPrimitivePtr( new MeshPrimitive( backgroundMesh, backgroundMaterial, GetTangentSpaceVertexSource() ) );
mBackground = GameObjectPtr( new GameObject( background ) );
Matrix4 backgroundOffset;
backgroundOffset.CreateFromQuaternion( Quaternion( Vector3::Right, Pi / 2.f ) );
mBackground->SetOffset( backgroundOffset );
mBackground->SetTranslation( Vector3( 0.f, -10.f, 0.f ) );
mBackground->Attach();
// Load the player's ship.
MaterialPtr playerShipMaterial = MaterialPtr( new Material( L"Resources\\Shaders\\tangent.hlsl", L"Resources\\Textures\\frigate.dds" ) );
RawMeshPtr shipMesh = RawMeshPtr( new RawMesh() );
LoadMeshFromObjFile( "Resources\\Meshes\\frigate_normal.obj", *shipMesh.get() );
CalculateTangents( *shipMesh.get() );
MeshPrimitivePtr player = MeshPrimitivePtr( new MeshPrimitive( shipMesh, playerShipMaterial, GetTangentSpaceVertexSource() ) );
mPlayerObject = PlayerShipPtr( new PlayerShip( player ) );
mPlayerObject->SetScale( 0.3f );
mPlayerObject->SetBounds( 6.5f );
Matrix4 playerOffset;
playerOffset.CreateFromQuaternion( Quaternion( Vector3::Up, Pi / 2.f ) );
mPlayerObject->SetOffset( playerOffset );
mPlayerObject->SetFrictionFactor( 0.5f );
mPlayerObject->Attach();
// Load asteroids
MaterialPtr asteroidMaterial = MaterialPtr( new Material( L"Resources\\Shaders\\tangent.hlsl", L"Resources\\Textures\\asteroid.dds" ) );
RawMeshPtr asteroidMesh = RawMeshPtr( new RawMesh() );
LoadMeshFromObjFile( "Resources\\Meshes\\asteroid1.obj", *asteroidMesh.get() );
CalculateTangents( *asteroidMesh.get() );
for ( int i = 0; i < 5; i++ )
{
MeshPrimitivePtr asteroid = MeshPrimitivePtr( new MeshPrimitive( asteroidMesh, asteroidMaterial, GetTangentSpaceVertexSource() ) );
GameObjectPtr newAsteroid = GameObjectPtr( new Asteroid( asteroid ) );
newAsteroid->SetScale( 1.f );
newAsteroid->SetBounds( 4.f );
newAsteroid->SetTranslation( Vector3( RandomFloat( -40.f, 40.f ), 0.f, RandomFloat( -40.f, 40.f ) ) );
mAsteroids.push_back( newAsteroid );
newAsteroid->Attach();
}
// Load the player's jet particles.
playerJetParticles = ParticleSystemPtr( new ParticleSystem() );
ParticleSystemLoader loader;
loader.LoadFromFile( "Resources\\ParticleSystems\\jet_fuel.part", playerJetParticles );
playerJetParticles->SetEmitterState( false ); // turn the particles off to start with
Renderer::Get().AddTranslucentPrimitive( playerJetParticles );
}
示例2: UpdatePlayerShip
void SpaceShooter::UpdatePlayerShip()
{
if ( InputManager::Get().GetKeyState( Key::W ) )
{
mPlayerObject->MoveForward();
playerJetParticles->SetEmitterState( true );
}
else
{
mPlayerObject->StopAcceleration();
playerJetParticles->SetEmitterState( false );
}
if ( InputManager::Get().GetKeyState( Key::A ) )
{
mPlayerObject->RotateLeft();
}
if ( InputManager::Get().GetKeyState( Key::D ) )
{
mPlayerObject->RotateRight();
}
// Update player's particles
Matrix4 jetFuelTranspose = Matrix4::Identity;
Matrix4 jetFuelOffset;
jetFuelOffset.CreateTranslation( Vector3(0.f, 0.f, -5.5f) );
Matrix4 jetFuelRotation;
jetFuelRotation.CreateFromQuaternion( mPlayerObject->GetRotation() );
Matrix4 jetFuelTranslation;
jetFuelTranslation.CreateTranslation( mPlayerObject->GetTranslation() );
jetFuelTranspose.Multiply( jetFuelTranslation );
jetFuelTranspose.Multiply( jetFuelRotation );
jetFuelTranspose.Multiply( jetFuelOffset );
playerJetParticles->SetTranslationMatrix( jetFuelTranspose );
}