_Use_decl_annotations_ void XM_CALLCONV Camera::SetViewParams(_In_ FXMVECTOR vDirection) { XMMATRIX view = XMMatrixIdentity(); view.r[2] = XMVectorSetW(-XMVector3Normalize(vDirection), 0.0f); view.r[3] = XMVectorSetW(XMVector3Normalize(vDirection), 1.0f); //m_mView = view; }
bool CPointLightNode::intersectRay(const math::SRay& ray, f32* pDist) const { XMVECTOR origin = XMLoadFloat3(&ray.Origin); origin = XMVectorSetW(origin, 1.0f); XMVECTOR direction = XMLoadFloat3(&ray.Direction); direction = XMVectorSetW(direction, 0); return intersectRay(origin, direction, pDist); }
/** * Creates a rotation matrix about the described axis. * * @param fX Describes the x component of the axis. * @param fY Describes the y component of the axis. * @param fZ Describes the z component of the axis. * @param fRadians Angle of rotation, measured clockwise when looking along the rotation axis. * @return The resulting matrix. */ CFMat4x4 CFMat4x4::CreateRotationAxis( FLOAT32 fX, FLOAT32 fY, FLOAT32 fZ, FLOAT32 fRadians ) { CFMat4x4 matReturn; CFVec3 v3Axis; v3Axis.X( fX ); v3Axis.Y( fY ); v3Axis.Z( fZ ); XMMATRIX& matResult = *reinterpret_cast<XMMATRIX*>( &matReturn ); XMVECTOR& vAxis = *reinterpret_cast<XMVECTOR*>( &v3Axis ); vAxis = XMVectorSetW( vAxis, 0.0f ); matResult = XMMatrixRotationAxis( vAxis, fRadians ); return matReturn; }
void D3DCamera::Render(XMVECTOR translate, XMVECTOR rotate, bool move, bool playback) { XMVECTOR upVector, lookAtVector, rightVector; XMMATRIX rotationMatrix; rightVector = XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f); upVector = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); lookAtVector = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f); if (move) { XMVECTOR quaternion = XMQuaternionRotationRollPitchYawFromVector(rotate); quaternion = XMQuaternionNormalize(quaternion); m_rotation = XMQuaternionMultiply(quaternion, m_rotation); } if (playback) m_rotation = rotate; rotationMatrix = XMMatrixRotationQuaternion(m_rotation); // Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin. lookAtVector = XMVector3TransformCoord(lookAtVector, rotationMatrix); upVector = XMVector3TransformCoord(upVector, rotationMatrix); rightVector = XMVector3TransformCoord(upVector, rotationMatrix); if (move) { translate = XMVector3TransformCoord(translate, rotationMatrix); translate = XMVectorSetW(translate, 0); m_position += translate; } if (playback) m_position = translate; // Translate the rotated camera position to the location of the viewer. lookAtVector = XMVectorAdd(m_position, lookAtVector); m_lookAtVector.x = lookAtVector.m128_f32[0]; m_lookAtVector.y = lookAtVector.m128_f32[1]; m_lookAtVector.z = lookAtVector.m128_f32[2]; // Finally create the view matrix from the three updated vectors. m_viewMatrix = XMMatrixLookAtLH(m_position, lookAtVector, upVector); return; }
void World::update( float dt ) { //Update the population, mostly does AI decisions mPop.update( dt ); float mBlockDimensions = 0.3f; //Do collision for moving characters for( int i = 0; i < POPULATION_MAX_CHARACTERS; i++){ Character& character = mPop.getCharacter(i); if( character.getExistence() > Character::Existence::Dead ){ XMFLOAT4& dir = mPop.getCharacter(i).getWalkingDirection(); //Make sure we are at least moving when checking collision float dist = fabs( dir.x ) + fabs( dir.z ); if( dist < 0.1f ){ continue; } //TEMPORARY WAY OF SOLVING THIS! //As long as we are not on a ramp, bring us to the floor int bx = static_cast<int>( character.getPosition().x / mBlockDimensions ); int bz = static_cast<int>( character.getPosition().z / mBlockDimensions ); CLAMP( bx, 0, getLevel().getWidth() - 1 ); CLAMP( bz, 0, getLevel().getDepth() - 1 ); XMVECTOR moveVec = XMLoadFloat4( &dir ); moveVec = XMVector3Normalize( moveVec ); moveVec = XMVectorSetW( moveVec, 1.0f ); moveEntity( &character, moveVec, dt * CHARACTER_MOVE_SPEED ); //Reset the direction back to 0 dir.x = 0.0f; dir.y = 0.0f; dir.z = 0.0f; } } for(ushort i = 0; i < mLevel.getNumDoors(); i++){ Level::Door& door = mLevel.getDoor(i); if( door.state == Level::Door::Opening ){ door.setYRotation( door.getYRotation() + 0.02f ); if( door.getYRotation() > ( door.startAngle + ( 3.14159f * 0.5f ) ) ){ door.state = Level::Door::Opened; door.setYRotation( door.startAngle + ( 3.14159f * 0.5f ) ); } }else if( door.state == Level::Door::Closing ){ door.setYRotation( door.getYRotation() - 0.02f ); if( door.getYRotation() < ( door.startAngle - ( 3.14159f * 0.5f ) ) ){ door.state = Level::Door::Closed; door.setYRotation( door.startAngle - ( 3.14159f * 0.5f ) ); } } } }
void CFVec4::W( FLOAT32 fVal ) { XMVECTOR& V4 = *reinterpret_cast<XMVECTOR*>(this); V4 = XMVectorSetW( V4, fVal ); }
void CFVec4::WAdd( FLOAT32 fVal ) { XMVECTOR& v4V = *reinterpret_cast<XMVECTOR*>(this); v4V = XMVectorSetW( v4V, XMVectorGetW( v4V ) + fVal ); }
void Frustum::CreateFrustum(float screenDepth, XMMATRIX viewMatrix, XMMATRIX projMatrix) { float zMinimum, r; XMFLOAT4X4 projMatrixFloat; XMFLOAT4X4 frustumMatrix; XMStoreFloat4x4(&projMatrixFloat, projMatrix); // Calculate the minimum Z distance in the frustum. zMinimum = -projMatrixFloat._43 / projMatrixFloat._33; r = screenDepth / (screenDepth - zMinimum); projMatrixFloat._33 = r; projMatrixFloat._43 = -r * zMinimum; XMMATRIX updatedProjMatrix = XMLoadFloat4x4(&projMatrixFloat); //Create the frustum from the viewMatrix and updated projectionMatrix XMStoreFloat4x4(&frustumMatrix, XMMatrixMultiply(viewMatrix, updatedProjMatrix)); ; //Calculate near plane of frustum XMVectorSetX(this->planes[0], frustumMatrix._14 + frustumMatrix._13); XMVectorSetY(this->planes[0], frustumMatrix._24 + frustumMatrix._23); XMVectorSetZ(this->planes[0], frustumMatrix._34 + frustumMatrix._33); XMVectorSetW(this->planes[0], frustumMatrix._44 + frustumMatrix._43); this->planes[0] = XMPlaneNormalize(this->planes[0]); //this->planes[0] = XMVector3Normalize(this->planes[0]); //Calculate far plane of frustum XMVectorSetX(this->planes[1], frustumMatrix._14 - frustumMatrix._13); XMVectorSetY(this->planes[1], frustumMatrix._24 - frustumMatrix._23); XMVectorSetZ(this->planes[1], frustumMatrix._34 - frustumMatrix._33); XMVectorSetW(this->planes[1], frustumMatrix._44 - frustumMatrix._43); this->planes[1] = XMPlaneNormalize(this->planes[1]); //this->planes[1] = XMVector3Normalize(this->planes[1]); //Calculate left plane of frustum XMVectorSetX(this->planes[2], frustumMatrix._14 + frustumMatrix._11); XMVectorSetY(this->planes[2], frustumMatrix._24 + frustumMatrix._21); XMVectorSetZ(this->planes[2], frustumMatrix._34 + frustumMatrix._31); XMVectorSetW(this->planes[2], frustumMatrix._44 + frustumMatrix._41); this->planes[2] = XMPlaneNormalize(this->planes[2]); //this->planes[2] = XMVector3Normalize(this->planes[2]); //Calculate right plane of frustum XMVectorSetX(this->planes[3], frustumMatrix._14 - frustumMatrix._11); XMVectorSetY(this->planes[3], frustumMatrix._24 - frustumMatrix._21); XMVectorSetZ(this->planes[3], frustumMatrix._34 - frustumMatrix._31); XMVectorSetW(this->planes[3], frustumMatrix._44 - frustumMatrix._41); this->planes[3] = XMPlaneNormalize(this->planes[3]); //this->planes[3] = XMVector3Normalize(this->planes[3]); //Calculate top plane of frustum XMVectorSetX(this->planes[4], frustumMatrix._14 - frustumMatrix._12); XMVectorSetY(this->planes[4], frustumMatrix._24 - frustumMatrix._22); XMVectorSetZ(this->planes[4], frustumMatrix._34 - frustumMatrix._32); XMVectorSetW(this->planes[4], frustumMatrix._44 - frustumMatrix._42); this->planes[4] = XMPlaneNormalize(this->planes[4]); //this->planes[4] = XMVector3Normalize(this->planes[4]); //Calculate bottom plane of frustum XMVectorSetX(this->planes[5], frustumMatrix._14 + frustumMatrix._12); XMVectorSetY(this->planes[5], frustumMatrix._24 + frustumMatrix._22); XMVectorSetZ(this->planes[5], frustumMatrix._34 + frustumMatrix._32); XMVectorSetW(this->planes[5], frustumMatrix._44 + frustumMatrix._42); this->planes[5] = XMPlaneNormalize(this->planes[5]); //this->planes[5] = XMVector3Normalize(this->planes[5]); /*for (int i = 0; i < 6; i++) { float denom = 1.0f / XMVectorGetX(XMVector3Length(this->planes[i])); XMVectorSetX(this->planes[i], XMVectorGetX(this->planes[i]) * denom); XMVectorSetY(this->planes[i], XMVectorGetY(this->planes[i]) * denom); XMVectorSetZ(this->planes[i], XMVectorGetZ(this->planes[i]) * denom); XMVectorSetW(this->planes[i], XMVectorGetW(this->planes[i]) * denom); }*/ return; }
void Light::set_intensity(float i) { XMVECTOR v = colorv(); XMVectorSetW(v, i); set_color(v); }