void Camera::Update() { mRotationMatrix = XMMatrixRotationRollPitchYaw(Roll, Pitch, Yaw); mTarget = XMVector3TransformCoord(DefaultForward, mRotationMatrix ); mTarget = XMVector3Normalize(mTarget); XMMATRIX RotateYTempMatrix; RotateYTempMatrix = XMMatrixRotationRollPitchYaw(Roll, Pitch, Yaw); mRight = XMVector3TransformCoord(DefaultRight, RotateYTempMatrix); mUp = XMVector3TransformCoord(DefaultUp, RotateYTempMatrix); mForward = XMVector3TransformCoord(DefaultForward, RotateYTempMatrix); mPosition += mMoveLeftRight*mRight; mPosition += mMoveTopDown*mUp; mPosition += mMoveBackForward*mForward; mMoveLeftRight = 0.0f; mMoveTopDown = 0.0f; mMoveBackForward = 0.0f; mTarget = mPosition + mTarget; UpdateViewMatrix(); }
void CameraClass::RenderBaseViewMatrix() { XMFLOAT3 f3_lookAt; XMVECTOR up, position, lookAt; float yaw, pitch, roll; XMMATRIX rotationMatrix; // Setup the vector that points upwards. up = XMLoadFloat3(&XMFLOAT3(0.0f, 1.0f, 0.0f)); // Setup the position of the camera in the world. position = XMLoadFloat3(&XMFLOAT3(m_positionX, m_positionY, m_positionZ)); // Setup where the camera is looking by default. lookAt = XMLoadFloat3(&XMFLOAT3(0.0f, 0.0f, 1.0f)); // Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians. pitch = m_rotationX * 0.0174532925f; yaw = m_rotationY * 0.0174532925f; roll = m_rotationZ * 0.0174532925f; // Create the rotation matrix from the yaw, pitch, and roll values. rotationMatrix = XMMatrixRotationRollPitchYaw(yaw, pitch, roll); // Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin. lookAt = XMVector3TransformCoord(lookAt, rotationMatrix); up = XMVector3TransformCoord(up, rotationMatrix); // Translate the rotated camera position to the location of the viewer. lookAt = position + lookAt; // Finally create the base view matrix from the three updated vectors. m_baseViewMatrix = XMMatrixLookAtLH(position, lookAt, up); }
void CameraHandler::Frame(float dt, InputHandler* inputH, GroundModel* model) { XMVECTOR lookAt = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f); XMVECTOR camRight = XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f); XMVECTOR camUp = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); //Get input from keyboard and mouse movement to change camera values this->updateCamera(dt, inputH, model); this->camRotationMatrix = XMMatrixRotationRollPitchYaw(this->camPitch, this->camYaw, 0); lookAt = XMVector3TransformCoord(lookAt, this->camRotationMatrix); lookAt = XMVector3Normalize(lookAt); camRight = XMVector3TransformCoord(camRight, this->camRotationMatrix); camUp = XMVector3TransformCoord(camUp, this->camRotationMatrix); //Set new camPos this->camPos += this->moveLeftRight * camRight; this->camPos += this->moveBackForward * lookAt; this->camPos += this->moveUpDown * camUp; //Reset this->moveLeftRight = 0.0f; this->moveBackForward = 0.0f; this->moveUpDown = 0.0f; lookAt = this->camPos + lookAt; this->viewMatrix = XMMatrixLookAtLH(this->camPos, lookAt, camUp); return; }
void Camera::RenderReflection(float height) { XMFLOAT3 up, position, lookAt; float yaw, pitch, roll; //Up vector up = XMFLOAT3(0, 1, 0); //World position of reflection camera position = XMFLOAT3(m_positionX, -m_positionY + (height*2.0f), m_positionZ); lookAt = XMFLOAT3(0, 0, 1); pitch = m_rotationX * 0.0174532925f; yaw = m_rotationY * 0.0174532925f; roll = m_rotationZ * 0.0174532925f; XMMATRIX rotationMatrix = XMMatrixRotationRollPitchYaw(pitch, yaw, roll); //Transform lookat and up by rotation matrix XMVECTOR lookAtVec = XMVector3TransformCoord(XMLoadFloat3(&lookAt), rotationMatrix); XMVECTOR upVec = XMVector3TransformCoord(XMLoadFloat3(&up), rotationMatrix); XMVECTOR positionVec = XMLoadFloat3(&position); lookAtVec = XMVectorAdd(positionVec, lookAtVec); m_reflectionViewMatrix = XMMatrixLookAtLH(positionVec, lookAtVec, upVec); return; }
void CameraClass::Render(){ XMFLOAT3 f3_lookAt; XMVECTOR up, position, lookAt; float yaw, pitch, roll, radians; XMMATRIX rotationMatrix; // set "up vector" up = XMLoadFloat3(&XMFLOAT3(0.0f, 1.0f, 0.f)); // setup camera's world position position = XMLoadFloat3(&XMFLOAT3(m_positionX, m_positionY, m_positionZ)); //BIGCHANGES // set default lookAt lookAt = XMLoadFloat3(&XMFLOAT3(0.0f, 0.0f, 1.0f)); // set yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians pitch = m_rotationX * 0.0174532925f; yaw = m_rotationY * 0.0174532925f; roll = m_rotationZ * 0.0174532925f; // create rotation matrix from yaw, pitch, roll values rotationMatrix = XMMatrixRotationRollPitchYaw(yaw, pitch, roll); // Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin. lookAt = XMVector3TransformCoord(lookAt, rotationMatrix); up = XMVector3TransformCoord(up, rotationMatrix); // Translate the rotated camera position to the location of the viewer. lookAt = position + lookAt; // Finally create the view matrix from the three updated vectors. m_viewMatrix = XMMatrixLookAtLH(position, lookAt, up); }
void DXBox::DrawBox(ID3D11DeviceContext* md3dImmediateContext, ID3DX11EffectTechnique* activeTech, DX11Camera mCam) { //Perform matrix operations for stored scale and position XMMATRIX mBoxRotation = XMMatrixRotationRollPitchYaw(mRotation.GetZ(), mRotation.GetY(), mRotation.GetX()); XMMATRIX mBoxScale = XMMatrixScaling(mScale.GetX(), mScale.GetY(), mScale.GetZ()); XMMATRIX mBoxPosition = XMMatrixTranslation(mPosition.GetX(), mPosition.GetY(), mPosition.GetZ()); XMStoreFloat4x4(&mBoxWorld, XMMatrixMultiply(XMMatrixMultiply(mBoxRotation,mBoxScale), mBoxPosition)); UINT stride = sizeof(Vertex::Basic32); UINT offset = 0; md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset); md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0); // Draw the box. XMMATRIX world = XMLoadFloat4x4(&mBoxWorld); XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world); XMMATRIX worldViewProj = world * mCam.View() * mCam.Proj(); Effects::BasicFX->SetWorld(world); Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose); Effects::BasicFX->SetWorldViewProj(worldViewProj); Effects::BasicFX->SetTexTransform(XMLoadFloat4x4(&mTexTransform)); Effects::BasicFX->SetMaterial(mBoxMat); Effects::BasicFX->SetDiffuseMap(boxDiffuseTexture); activeTech->GetPassByIndex(0)->Apply(0, md3dImmediateContext); md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset); }
// Run // void Model::Render(ID3D11DeviceContext* deviceContext) { // Rotate the model float yaw, pitch, roll; m_rotation.y += (float)XM_PI * 0.0005f; m_rotation.x += (float)XM_PI * 0.0005f; m_position.x += 1.0f; if (m_position.x > 50) m_position.x -= 50; if (m_rotation.x > 360.0f) m_rotation.x -= 360.0f; if (m_rotation.y > 360.0f) m_rotation.y-= 360.0f; if (m_rotation.z > 360.0f) m_rotation.z -= 360.0f; pitch = m_rotation.x * 0.0174532925f; yaw = m_rotation.y * 0.0174532925f; roll = m_rotation.z * 0.0174532925f; pitch = 0.0f; yaw = 0.0f; roll = 0.0f; XMMATRIX rotationMatrix = XMMatrixRotationRollPitchYaw(pitch, yaw, roll); XMStoreFloat4x4(&m_rotationMatrix, rotationMatrix); RenderBuffers(deviceContext); return; }
void Camera::UpdateCamera() { camRotationMatrix = XMMatrixRotationRollPitchYaw(camPitch, camYaw, 0); //Updates the rotation matrix in pitch and yaw camTarget = XMVector3TransformCoord(DefaultForward, camRotationMatrix); //Updates the target with the NEW rotation matrix camTarget = XMVector3Normalize(camTarget); //Normalizing Matrix RotateYTempMatrix; RotateYTempMatrix = XMMatrixRotationY(camYaw); //To keep our camera's forward and right vectors pointing only in the x and z axis camRight = XMVector3TransformCoord(DefaultRight, RotateYTempMatrix); //Transforms the vector using the RotateYTempMatrix camUp = XMVector3TransformCoord(camUp, RotateYTempMatrix); //Transforms the vector using the RotateYTempMatrix camForward = XMVector3TransformCoord(DefaultForward, RotateYTempMatrix); //Transforms the vector using the RotateYTempMatrix camPosition += moveLeftRight*camRight; //Calculates the cameras NEW position in the right and left position camPosition += moveBackForward*camForward; //Calculates the cameras NEW position in the back and forward position moveLeftRight = 0.0f; //Resets the movement moveBackForward = 0.0f; //Resets the movement camTarget = camPosition + camTarget; //Adds the position with the target fbxPtr->test.camPos = camPosition; camView = XMMatrixLookAtLH(camPosition, camTarget, camUp); //Stores the NEW View Matrix }
void ModelLightingClass::ModelMatrix(XMMATRIX& p_out) { XMMATRIX trans = XMMatrixTranslation(Position.x, Position.y, Position.z); XMMATRIX rot = XMMatrixRotationRollPitchYaw(Rotation.x, Rotation.y, Rotation.z ); XMMATRIX scale = XMMatrixScaling(Scale.x, Scale.y, Scale.z); p_out = scale * rot * trans; }
void d3d_display::update_camera() { XMVECTOR DefaultForward, DefaultRight, camPosition; DefaultForward = XMLoadFloat4(&_camera.DefaultForward); DefaultRight = XMLoadFloat4(&_camera.DefaultRight); camPosition = XMLoadFloat4(&_camera.camPosition); XMMATRIX camRotationMatrix = XMMatrixRotationRollPitchYaw(_camera.camPitch, _camera.camYaw, 0); XMVECTOR camTarget = XMVector3TransformCoord(DefaultForward, camRotationMatrix); camTarget = XMVector3Normalize(camTarget); XMVECTOR camRight = XMVector3TransformCoord(DefaultRight, camRotationMatrix); XMVECTOR camForward = XMVector3TransformCoord(DefaultForward, camRotationMatrix); XMVECTOR camUp = XMVector3Cross(camForward, camRight); camPosition += _camera.moveLeftRight * camRight; camPosition += _camera.moveBackForward * camForward; XMStoreFloat4(&_camera.camPosition, camPosition); _camera.moveLeftRight = 0.0f; _camera.moveBackForward = 0.0f; camTarget = camPosition + camTarget; XMStoreFloat4x4(&_View, XMMatrixLookAtLH(camPosition, camTarget, camUp)); }
void Player::FrameMove(float fElapsedTime) { GetInput(); XMMATRIX mBodyCameraRot = XMMatrixRotationRollPitchYaw(0, m_fYawAngle, 0); XMMATRIX mHeadCameraRot = XMMatrixRotationRollPitchYaw(m_fPitchAngle, 0, 0); mHeadCameraRot.r[3] = XMVectorSet(0.f, 0.6f, 0.f, 1.f); mWorld = mBodyCameraRot * XMMatrixTranslationFromVector(mWorld.Translation()); m_pHead->SetRelativeWorld(mHeadCameraRot); UpdateAcceleration(fElapsedTime); ControllerNode::FrameMove(fElapsedTime); }
void CameraClass::Render() { XMVECTOR up, position, lookAt; float yaw, pitch, roll; XMMATRIX rotationMatrix; up = XMLoadFloat3(&mUp); position = XMLoadFloat3(&mPosition); lookAt = XMLoadFloat3(&mLookAt); pitch = XMConvertToRadians(mRotation.x); yaw = XMConvertToRadians(mRotation.y); roll = XMConvertToRadians(mRotation.z); rotationMatrix = XMMatrixRotationRollPitchYaw(pitch, yaw, roll); up = XMVector3TransformNormal(up, rotationMatrix); lookAt = XMVector3TransformNormal(lookAt, rotationMatrix); mLookZ = XMVectorGetByIndex(lookAt, 2); lookAt = position + lookAt; XMStoreFloat4x4(&mViewMatrix, XMMatrixLookAtLH(position, lookAt, up)); }
void CameraHandler::GenerateBaseViewMatrix() { XMVECTOR lookAt = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f); XMVECTOR camRight = XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f); XMVECTOR camUp = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); this->camRotationMatrix = XMMatrixRotationRollPitchYaw(this->camPitch, this->camYaw, 0); lookAt = XMVector3TransformCoord(lookAt, this->camRotationMatrix); lookAt = XMVector3Normalize(lookAt); camRight = XMVector3TransformCoord(camRight, this->camRotationMatrix); camUp = XMVector3TransformCoord(camUp, this->camRotationMatrix); //Set new camPos this->camPos += this->moveLeftRight * camRight; this->camPos += this->moveBackForward * lookAt; this->camPos += this->moveUpDown * camUp; //Reset this->moveLeftRight = 0.0f; this->moveBackForward = 0.0f; this->moveUpDown = 0.0f; lookAt = this->camPos + lookAt; this->baseViewMatrix = XMMatrixLookAtLH(this->camPos, lookAt, camUp); return; }
void CALLBACK OnFrameMove(_In_ double fTime, _In_ float fElapsedTime, _In_opt_ void* pUserContext) { static float rot = 0.0f; rot += fElapsedTime; XMMATRIX mscale = XMMatrixScaling(1.0f, 1.0f, 1.0f); XMMATRIX mrot = XMMatrixRotationRollPitchYaw(0.0f, 0.0f, rot); XMMATRIX mtrans = XMMatrixTranslation(20.0f, 50.0f, 0.0f); // gmesh 의 월드 매트릭스 -> XMMATRIX XMMATRIX mParent = XMLoadFloat4x4(&g_mesh->getWorld()); g_matLight = (mscale * mtrans * mrot) * mParent; // 조명 메시 연결 XMFLOAT4X4 mlit = XMFLOAT4X4(); XMStoreFloat4x4(&mlit, g_matLight); g_meshLight->setWorld(mlit); g_camera.FrameMove(fElapsedTime); }
void Aircraft::Rotate(float yaw, float pitch, float roll) { XMStoreFloat4x4(&_rotate, XMMatrixRotationRollPitchYaw(yaw, pitch, roll)); if (_rotate._33 > 18.0) _rotate._33 = 18.0; if (_rotate._33 < -18.0) _rotate._33 = -18.0f; }
bool ModelsDemo::DrawGameObject( GameObject * game_object ) { ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // THESE OPERATIONS ARE NOT ENCAPSULATED YET !!! // activate the vertex layout on the graphics card d3dContext_->IASetInputLayout( inputLayout_ ); // activate the vertex shader on the graphics card d3dContext_->VSSetShader( textureMapVS_, 0, 0 ); // activate the pixel shader on the graphics card d3dContext_->PSSetShader( textureMapPS_, 0, 0 ); // activate the texture sampler on the graphics card d3dContext_->PSSetSamplers( 0, 1, &colorMapSampler_ ); ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // get the display object from the game object DisplayObject * display_object = game_object->GetDisplayObject(); // activate the GameObject's vertex buffer on the graphics card display_object->GetModel()->Render( d3dContext_ ); // activate the GameObject's texture buffer on the graphics card display_object->GetTexture()->Render( d3dContext_ ); // create matrices to create a single world matrix for the GameObject's transform XMMATRIX scale_mat = XMMatrixScaling(game_object->getSX(), game_object->getSY(), game_object->getSZ()); XMMATRIX rotation_mat = XMMatrixRotationRollPitchYaw(game_object->getRX(), game_object->getRY(), game_object->getRZ()); XMMATRIX position_mat = XMMatrixTranslation(game_object->getX(), game_object->getY(), game_object->getZ()); // 1) scale // 2) rotate // 3) position XMMATRIX world_mat = XMMatrixTranspose( scale_mat * rotation_mat * position_mat ); ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // THESE OPERATIONS ARE NOT ENCAPSULATED YET !!! // update the world matrix on the graphics card d3dContext_->UpdateSubresource( worldCB_, 0, 0, &world_mat, 0, 0 ); // set the world matrix on the vertex shader d3dContext_->VSSetConstantBuffers( 0, 1, &worldCB_ ); ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// d3dContext_->Draw( display_object->GetModel()->GetVertexCount(), 0 ); return true; }
void Camera::moveCam() { XMVECTOR tempRight = XMLoadFloat3(&mRight); XMVECTOR tempUp = XMLoadFloat3(&mUp); XMVECTOR tempPosition = XMLoadFloat3(&mPosition); XMVECTOR tempForward = XMLoadFloat3(&mLook); //set the camera to look at the character camTarget = playerPosition; XMVECTOR tempTarget = XMLoadFloat3(&camTarget); tempTarget = XMVectorSetY(tempTarget,10); //rotate camera around the character camRotationMatrix = XMMatrixRotationRollPitchYaw(-camPitch, camYaw, 0); tempPosition = XMVector3TransformNormal(PlayerForward, camRotationMatrix); tempPosition = XMVector3Normalize(tempPosition); tempPosition = (tempPosition * -50) + tempTarget; tempPosition = XMVectorSetY(tempPosition, 30.0f); tempForward = XMVector3Normalize(tempTarget - tempPosition); // Get forward vector based on target tempForward = XMVectorSetY(tempForward, 0.0f); // set forwards y component to 0 so it lays only on tempForward= XMVector3Normalize(tempForward); tempRight = XMVectorSet(XMVectorGetZ(-tempForward), 0.0f, XMVectorGetX(tempForward), 0.0f); tempUp = XMVector3Normalize(XMVector3Cross(XMVector3Normalize(tempPosition - tempTarget), tempRight)); XMStoreFloat3(&mRight, tempRight); XMStoreFloat3(&mUp, tempUp); XMStoreFloat3(&mPosition, tempPosition); XMStoreFloat3(&mLook, tempForward); XMMATRIX tempView = XMLoadFloat4x4(&mView); tempView = XMMatrixLookAtLH(tempPosition, tempTarget, tempUp); XMStoreFloat4x4(&mView, tempView); ///////////mising some code maybe }
XMVECTOR GameObject::GetForwardVector() { XMMATRIX rotmat = XMMatrixRotationRollPitchYaw(XMConvertToRadians(rotation.x), XMConvertToRadians(rotation.y), XMConvertToRadians(rotation.z)); XMFLOAT4X4 rotationMatrixF; XMStoreFloat4x4(&rotationMatrixF, rotmat); forwardVector = -XMVectorSet(rotationMatrixF._11, rotationMatrixF._12, rotationMatrixF._13, rotationMatrixF._14); return XMVector3Normalize ( forwardVector ); }
const XMMATRIX & ModelLightingClass::ModelMatrix() { XMMATRIX trans = XMMatrixTranslation(Position.x, Position.y, Position.z); XMMATRIX rot = XMMatrixRotationRollPitchYaw(Rotation.x, Rotation.y, Rotation.z ); XMMATRIX scale = XMMatrixScaling(Scale.x, Scale.y, Scale.z); model_ModelWorld = scale * rot * trans; return model_ModelWorld; }
void Game::UpdateScene() { floorWorld = XMMatrixIdentity(); scale = XMMatrixScaling(250.0f, 1.0f, 250.0f); translation = XMMatrixTranslation(0.0f, 0.0f, 0.0f); floorWorld = scale*translation; //Keep the cubes rotating rotSpeed += .0005f; if (rotSpeed > 6.26f) rotSpeed = 0.0f; //When used, these matrices will rotate objects rotateAboutX = XMMatrixRotationAxis(rotXAxis, -rotSpeed); rotateAboutY = XMMatrixRotationAxis(rotYAxis, -rotSpeed); rotateAboutZ = XMMatrixRotationAxis(rotZAxis, -rotSpeed); scale = XMMatrixScaling(2, scaleY, 2); //Reset cubes locations cube1World = XMMatrixIdentity(); cube2World = XMMatrixIdentity(); //When used, these matrices will set an objects position translation = XMMatrixTranslation(-5.0f, 2.0f, 0.0f); //Set cube1's world space using the transformations cube1World = rotateAboutX * translation * scale; //When used, these matrices will set an objects position translation = XMMatrixTranslation(5.0f, 2.0f, 0.0f); //Set cube2's world space matrix cube2World = rotateAboutY * translation * scale; meshWorld = XMMatrixIdentity(); travelSpeed += 0.0003f; //Setting meshes scale, translation and rotation scale = XMMatrixScaling(0.2f,0.2f,0.2f); translation = XMMatrixTranslation(-travelSpeed, 0.0f, 0.0f); rotation = XMMatrixRotationRollPitchYaw(0, XMConvertToRadians(180), 0); meshWorld = translation * rotation * scale; //Reset sphereWorld sphereWorld = XMMatrixIdentity(); //Define sphereWorld's world space matrix scale = XMMatrixScaling(5.0f, 5.0f, 5.0f); //Make sure the sphere is always centered around camera translation = XMMatrixTranslation(XMVectorGetX(camPosition), XMVectorGetY(camPosition), XMVectorGetZ(camPosition)); //Set sphereWorld's world space using the transformations sphereWorld = scale * translation; }
//! Returns the world matrix. XMMATRIX Object3D::GetWorldMatrix() { XMMATRIX T, R, S, W; T = XMMatrixTranslation(mPosition.x, mPosition.y, mPosition.z); R = XMMatrixRotationRollPitchYaw(mRotation.x, mRotation.y, mRotation.z); S = XMMatrixScaling(mScale.x * mDefaultScale.x, mScale.y * mDefaultScale.y, mScale.z * mDefaultScale.z); return S*R*T; }
/** * Creates a rotation matrix from Euler angles expressed as radians. * Perform roll, then pitch then yaw. * Angles are clockwise when looking along the axis towards the origin. * * @param fYaw Yaw, in radians. * @param fPitch Pitch, in radians. * @param fRoll Roll, in radians. * @return The resulting matrix. */ CFMat4x4 CFMat4x4::CreateYawPitchRoll( FLOAT32 fYaw, FLOAT32 fPitch, FLOAT32 fRoll ) { CFMat4x4 matReturn; XMMATRIX& matResult = *reinterpret_cast<XMMATRIX*>( &matReturn ); matResult = XMMatrixRotationRollPitchYaw( fPitch, fYaw, fRoll ); return matReturn; }
void SlideCamera::UpdateSlideCamera(std::vector<XMFLOAT3> collidableGeometryPositions, std::vector<DWORD> collidableGeometryIndices) { static XMVECTOR DefaultForward = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f); static XMVECTOR DefaultRight = XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f); static XMVECTOR camForward = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f); static XMVECTOR camRight = XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f); static XMVECTOR camUp = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); static XMVECTOR camPosition = XMVectorSet(0.0f, 2.0f, -5.0f, 0.0f); static XMVECTOR camTarget = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f); static XMMATRIX camView; //Rotating the SlideCamera by euler angle XMMATRIX camRotationMatrix = XMMatrixRotationRollPitchYaw(camPitch, camYaw, 0); camTarget = XMVector3TransformCoord(DefaultForward, camRotationMatrix ); camTarget = XMVector3Normalize(camTarget); XMMATRIX RotateYTempMatrix; RotateYTempMatrix = XMMatrixRotationY(camYaw); //We only move the xz plane by axis y //Update the SlideCamera vector camRight = XMVector3TransformCoord(DefaultRight, RotateYTempMatrix); camUp = XMVector3TransformCoord(camUp, RotateYTempMatrix); camForward = XMVector3TransformCoord(DefaultForward, RotateYTempMatrix); CollisionPacket SlideCameraCP; SlideCameraCP.ellipsoidSpace = XMVectorSet(1.0f, 3.0f, 1.0f, 0.0f); SlideCameraCP.w_Position = camPosition; SlideCameraCP.w_Velocity = (moveLeftRight*camRight) + (moveBackForward*camForward); camPosition = CollisionSlide(SlideCameraCP, collidableGeometryPositions, collidableGeometryIndices); /* // Free-Look SlideCamera camRight = XMVector3TransformCoord(DefaultRight, camRotationMatrix); camForward = XMVector3TransformCoord(DefaultForward, camRotationMatrix); camUp = XMVector3Cross(camForward, camRight); //Moving the SlideCamera camPosition += moveLeftRight*camRight; camPosition += moveBackForward*camForward; */ moveLeftRight = 0.0f; moveBackForward = 0.0f; camTarget = camPosition + camTarget; //Set the SlideCamera matrix camView = XMMatrixLookAtLH( camPosition, camTarget, camUp ); XMStoreFloat4x4(&m_camView, XMMatrixTranspose(camView)); }
//---------------------------------------------------------------------------------------- void CSkeletalObject::SetScaleRotationPosition(float ScaleX, float ScaleY, float ScaleZ, float Roll, float Pitch, float Yaw, float OffsetX, float OffsetY, float OffsetZ) { if (IsLoaded()) { XMMATRIX LocalToWorldNormals = XMMatrixRotationRollPitchYaw(Pitch, Yaw, Roll); XMMATRIX LocalToWorld = XMMatrixScaling(ScaleX, ScaleY, ScaleZ) * LocalToWorldNormals * XMMatrixTranslation(OffsetX, OffsetY, OffsetZ); m_pRenderObject->SetLocalToWorld(LocalToWorld, LocalToWorldNormals); } }
void ParticleManager::UpdateParticles(float dt, DxGraphics* pDxGraphics, Camera& cam) { // Update the world mat XMMATRIX transMat = XMMatrixTranslation(0.0f, 0.0f, 0.0f); XMMATRIX rotMat = XMMatrixRotationRollPitchYaw(0.0f, 0.0f, 0.0f); XMMATRIX scaleMat = XMMatrixScaling(1.0f, 1.0f, 1.0f); m_worldMat = rotMat * scaleMat * transMat; cam.CalculateViewMatrix(); // stream out the particles which runs through the physics XMMATRIX tWorld = XMMatrixTranspose(m_worldMat); XMMATRIX tView = XMMatrixTranspose(cam.GetViewMatrix()); XMMATRIX tProj = XMMatrixTranspose(cam.GetProjMatrix()); m_massPoint.dt = dt; ID3D11DeviceContext* pCon = pDxGraphics->GetImmediateContext(); // Set the stream out buffer UINT offsetSO[1] = { 0 }; pCon->SOSetTargets(1, &m_vStream, offsetSO); UINT stride = sizeof(Particle); UINT offset = 0; pCon->IASetVertexBuffers(0, 1, &m_vBuffer, &stride, &offset); pCon->IASetInputLayout(m_inputLayout); pCon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); pCon->VSSetShader(m_vUpdate, 0, 0); pCon->GSSetShader(m_gUpdate, 0, 0); pCon->PSSetShader(NULL, 0, 0); //// Update the cBuffer pCon->UpdateSubresource(m_pointBuffer, 0, NULL, &m_massPoint, 0, 0); pCon->VSSetConstantBuffers(3, 1, &m_pointBuffer); pCon->Draw(m_particleList.size(), 0); pCon->VSSetShader(NULL, 0, 0); pCon->GSSetShader(NULL, 0, 0); pCon->PSSetShader(NULL, 0, 0); // Unbind the SO ID3D11Buffer* bufferArray[1] = { 0 }; pCon->SOSetTargets(1, bufferArray, offsetSO); std::swap(m_vStream, m_vBuffer); }
void EntitySphere::render() { XMMATRIX translation = XMMatrixTranslationFromVector(m_position); XMMATRIX orientation = XMMatrixRotationRollPitchYaw(m_orientation.x, m_orientation.y, m_orientation.z); XMMATRIX scaling = XMMatrixScaling(m_diameter, m_diameter, m_diameter); XMMATRIX viewMatrix, projectionMatrix, transform; transform = scaling * orientation * translation; GRAPHICS->getCamera()->GetViewMatrix(viewMatrix); GRAPHICS->getDirectXWrapper()->getProjectionMatrix(projectionMatrix); m_gfx->render(transform, viewMatrix, projectionMatrix, m_color, m_texture, m_wireframe); }
void Camera::BuildMatrices() { XMMATRIX rotation = XMMatrixRotationRollPitchYaw(phi, theta, 0); // rotation around x axis, y axis, z axis XMVECTOR look = rotation.r[2]; XMVECTOR up = {0,1,0}; view = XMMatrixLookToLH(eye, look, up); float fov = 45 / 360.0f * 2 * XM_PI; float aspect = 4/3.0f; float nearz = 0.1f; float farz = 2000; proj = XMMatrixPerspectiveFovLH(fov, aspect, nearz, farz); }
void Camera::turn(float dx, float dy) { pitch = dy * 0.0005f; yaw = dx * 0.0005f; pitch = restrictAngle(pitch); yaw = restrictAngle(yaw); XMVECTOR fwd = XMLoadFloat3(&forward); XMVECTOR camPos = XMLoadFloat3(&position); XMMATRIX rotMat = XMMatrixRotationRollPitchYaw(pitch, yaw, 0.0f); fwd = XMVector3TransformCoord(fwd, rotMat); fwd = XMVector3Normalize(fwd); XMStoreFloat3(&forward, fwd); }
void Transform::update() { m_matScale=XMMatrixScaling(m_vecScale.x,m_vecScale.y,m_vecScale.z); m_matRotation=XMMatrixRotationRollPitchYaw(m_vecRotation.x,m_vecRotation.y,m_vecRotation.z); m_matTranslation=XMMatrixTranslation(m_vecPosition.x,m_vecPosition.y,m_vecPosition.z); m_matWorld=XMMatrixMultiply(m_matScale,m_matRotation); m_matWorld=XMMatrixMultiply(m_matWorld,m_matTranslation); //get parent if (m_pOwnerGameObject->getParent()) { Transform parentTransform=m_pOwnerGameObject->getTransform(); m_matWorld=XMMatrixMultiply(m_matWorld,parentTransform.getWorld()); } };
void Camera::SetRotation(float x, float y, float z) { m_rotationX = x; m_rotationY = y; m_rotationZ = z; // Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians. float yaw, pitch, roll; pitch = m_rotationX * 0.0174532925f; yaw = m_rotationY * 0.0174532925f; roll = m_rotationZ * 0.0174532925f; // Create the rotation matrix from the yaw, pitch, and roll values. m_rotationMatrix = XMMatrixRotationRollPitchYaw(pitch, yaw, roll); return; }