void MeshUtil::TransformMesh(const std::shared_ptr<Mesh> &mesh, const Matrix4 &matrix) const { unsigned int count = mesh->Positions.Data.size(); if (count == 0) return; count = count / 3; bool hasNormal = mesh->Normals.Data.size() > 0; for (unsigned int i = 0; i < count; i++) { unsigned int j = i * 3; Vector4 pos(mesh->Positions.Data[j], mesh->Positions.Data[j + 1], mesh->Positions.Data[j + 2], 1); pos = matrix.Multiply(pos); mesh->Positions.Data[j] = pos.x; mesh->Positions.Data[j + 1] = pos.y; mesh->Positions.Data[j + 2] = pos.z; if (hasNormal) { Vector4 normal(mesh->Normals.Data[j], mesh->Normals.Data[j + 1], mesh->Normals.Data[j + 2], 0); normal = matrix.Multiply(normal).Normalized(); mesh->Normals.Data[j] = normal.x; mesh->Normals.Data[j + 1] = normal.y; mesh->Normals.Data[j + 2] = normal.z; } } mesh->Positions.UpdateBuffer(true); }
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 ); }
void Matrix4::ApplyRotation(Matrix4& matrix, float angle, const Vector3& axis) { matrix = matrix.Multiply(Matrix4::Rotation(angle, axis)); }
Matrix4 operator*(Matrix4 left, const Matrix4& right) { return left.Multiply(right); }
void Matrix4::ApplyScaling(Matrix4& matrix, const Vector3& scaling) { matrix = matrix.Multiply(Matrix4::Scaling(scaling)); }
void Matrix4::ApplyTranslation(Matrix4& matrix, const Vector3& translation) { matrix = matrix.Multiply(Matrix4::Translation(translation)); }