// Update frame-based values. void D3D12Multithreading::OnUpdate() { m_timer.Tick(NULL); PIXSetMarker(m_commandQueue.Get(), 0, L"Getting last completed fence."); // Get current GPU progress against submitted workload. Resources still scheduled // for GPU execution cannot be modified or else undefined behavior will result. const UINT64 lastCompletedFence = m_fence->GetCompletedValue(); // Move to the next frame resource. m_currentFrameResourceIndex = (m_currentFrameResourceIndex + 1) % FrameCount; m_pCurrentFrameResource = m_frameResources[m_currentFrameResourceIndex]; // Make sure that this frame resource isn't still in use by the GPU. // If it is, wait for it to complete. if (m_pCurrentFrameResource->m_fenceValue > lastCompletedFence) { HANDLE eventHandle = CreateEventEx(nullptr, FALSE, FALSE, EVENT_ALL_ACCESS); if (eventHandle == nullptr) { ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError())); } ThrowIfFailed(m_fence->SetEventOnCompletion(m_pCurrentFrameResource->m_fenceValue, eventHandle)); WaitForSingleObject(eventHandle, INFINITE); } m_cpuTimer.Tick(NULL); float frameTime = static_cast<float>(m_timer.GetElapsedSeconds()); float frameChange = 2.0f * frameTime; if (m_keyboardInput.leftArrowPressed) m_camera.RotateYaw(-frameChange); if (m_keyboardInput.rightArrowPressed) m_camera.RotateYaw(frameChange); if (m_keyboardInput.upArrowPressed) m_camera.RotatePitch(frameChange); if (m_keyboardInput.downArrowPressed) m_camera.RotatePitch(-frameChange); if (m_keyboardInput.animate) { for (int i = 0; i < NumLights; i++) { float direction = frameChange * pow(-1.0f, i); XMStoreFloat4(&m_lights[i].position, XMVector4Transform(XMLoadFloat4(&m_lights[i].position), XMMatrixRotationY(direction))); XMVECTOR eye = XMLoadFloat4(&m_lights[i].position); XMVECTOR at = { 0.0f, 8.0f, 0.0f }; XMStoreFloat4(&m_lights[i].direction, XMVector3Normalize(XMVectorSubtract(at, eye))); XMVECTOR up = { 0.0f, 1.0f, 0.0f }; m_lightCameras[i].Set(eye, at, up); m_lightCameras[i].Get3DViewProjMatrices(&m_lights[i].view, &m_lights[i].projection, 90.0f, static_cast<float>(m_width), static_cast<float>(m_height)); } } m_pCurrentFrameResource->WriteConstantBuffers(&m_viewport, &m_camera, m_lightCameras, m_lights); }
float EnemyIceBear::DistanceToIglo() { XMVECTOR vector1 = XMLoadFloat3(&m_pIgloPointer->GetTransform()->GetPosition()); XMVECTOR vector2 = XMLoadFloat3(&m_Position); XMVECTOR direction = XMVectorSubtract(vector1, vector2); return *XMVector3Length(direction).m128_f32; }
CFVec4& CFVec4::operator -= ( CFVec4Arg vArg ) { XMVECTOR& v4V = *reinterpret_cast<XMVECTOR*>( this ); const XMVECTOR& v4V2 = *reinterpret_cast<const XMVECTOR*>( &vArg ); v4V = XMVectorSubtract( v4V, v4V2 ); return *this; }
float DistanceEstimated(const XMVECTOR& v1, const XMVECTOR& v2) { XMVECTOR& vectorSub = XMVectorSubtract(v1, v2); XMVECTOR& length = XMVector3LengthEst(vectorSub); float Distance = 0.0f; XMStoreFloat(&Distance, length); return Distance; }
float LineConnection::Distance(const XMVECTOR& vector1,const XMVECTOR& vector2) { XMVECTOR vectorSub = XMVectorSubtract(vector1,vector2); XMVECTOR length = XMVector3Length(vectorSub); float distance = 0.0f; XMStoreFloat(&distance,length); return distance; }
void BatchRenderer::DrawGrid( const Vec3D& XAxis, const Vec3D& YAxis, const Vec3D& Origin, int iXDivisions, int iYDivisions, const FColor& color ) { // HRESULT hr; iXDivisions = Max( 1, iXDivisions ); iYDivisions = Max( 1, iYDivisions ); // build grid geometry // INT iLineCount = iXDivisions + iYDivisions + 2; //assert( (2*iLineCount) <= MAX_VERTS ); XMVECTOR vX = XMLoadFloat3( &as_float3(XAxis) ); XMVECTOR vY = XMLoadFloat3( &as_float3(YAxis) ); XMVECTOR vOrigin = XMLoadFloat3( &as_float3(Origin) ); for( INT i = 0; i <= iXDivisions; i++ ) { FLOAT fPercent = ( FLOAT )i / ( FLOAT )iXDivisions; fPercent = ( fPercent * 2.0f ) - 1.0f; XMVECTOR vScale = XMVectorScale( vX, fPercent ); vScale = XMVectorAdd( vScale, vOrigin ); XMVECTOR vA, vB; vA = XMVectorSubtract( vScale, vY ); vB = XMVectorAdd( vScale, vY ); DrawLine3D( as_vec4(vA).ToVec3(), as_vec4(vB).ToVec3(), color, color ); } // INT iStartIndex = ( iXDivisions + 1 ) * 2; for( INT i = 0; i <= iYDivisions; i++ ) { FLOAT fPercent = ( FLOAT )i / ( FLOAT )iYDivisions; fPercent = ( fPercent * 2.0f ) - 1.0f; XMVECTOR vScale = XMVectorScale( vY, fPercent ); vScale = XMVectorAdd( vScale, vOrigin ); XMVECTOR vA, vB; vA = XMVectorSubtract( vScale, vX ); vB = XMVectorAdd( vScale, vX ); DrawLine3D( as_vec4(vA).ToVec3(), as_vec4(vB).ToVec3(), color, color ); } }
void BoneModel::createBone(){ auto& bones = mBoneAssetDataPtr->GetFileData().GetBoneData().mBoneBuffer; auto& boneName = mBoneAssetDataPtr->GetFileData().GetBoneData().mBoneName; DWORD mBoneNum = bones.size(); mBone.clear(); mIk.clear(); mBone.resize(mBoneNum); DWORD ikCount = 0; for (DWORD i = 0; i < mBoneNum; i++){ auto& bone = bones[i]; mBone[i].mStrName = boneName[i]; mBone[i].mHierarchy.mIdxSelf = i; mBone[i].mHierarchy.mIdxParent = bone.parent_bidx; if (bone.parent_bidx >= (int)mBoneNum) mBone[i].mHierarchy.mIdxParent = UINT(-1); XMVECTOR head_pos = XMVectorSet(bone.bone_head_pos[0], bone.bone_head_pos[1], bone.bone_head_pos[2], 0.0f); XMVECTOR parent_pos = { 0, 0, 0, 1 }; if (mBone[i].mHierarchy.mIdxParent < (int)mBoneNum){ UINT p = mBone[i].mHierarchy.mIdxParent; parent_pos = XMVectorSet(bones[p].bone_head_pos[0], bones[p].bone_head_pos[1], bones[p].bone_head_pos[2], 0.0f); } XMVECTOR local_pos = XMVectorSubtract(head_pos, parent_pos); mBone[i].mPos = XMFLOAT3(XMVectorGetX(local_pos), XMVectorGetY(local_pos), XMVectorGetZ(local_pos)); mBone[i].mScale = XMFLOAT3(1.0f, 1.0f, 1.0f); XMVECTOR q = XMQuaternionIdentity(); mBone[i].mRot = XMFLOAT4(XMVectorGetX(q), XMVectorGetY(q), XMVectorGetZ(q), XMVectorGetW(q)); //ワールド行列計算 XMVECTOR scale = { 1, 1, 1, 1 }; mBone[i].mMtxPose = SRTMatrix(scale, q, local_pos); if (mBone[i].mHierarchy.mIdxParent < (int)mBoneNum){ mBone[i].mMtxPose = XMMatrixMultiply(mBone[i].mMtxPose, mBone[mBone[i].mHierarchy.mIdxParent].mMtxPose); } if (bone.bone_flag & pmx::t_bone::BIT_IK){ mBone[i].mIkBoneIdx = (WORD)bone.t_ik_data_idx; createIk(ikCount, i); ikCount++; } else{ mBone[i].mIkBoneIdx = 0; } mBone[i].mMtxPoseInit = mBone[i].mMtxPose; } }
//-------------------------------------------------------------------------------------- // The VelDamp function estimates velocity as part of the smoothing function // //-------------------------------------------------------------------------------------- VOID FilterVelDamp::Update( const XMVECTOR* pJoints ) { if ( m_iPreviousFrame == -1 ) { memcpy( &m_SkeletonData[0], pJoints, sizeof( FilterSkeletonData ) ); m_iPreviousFrame = 1; // Redundancy to ensure both previous and current frames are checked if ( m_iCurrentFrame == -1 ) { memcpy( &m_SkeletonData[1], pJoints, sizeof( FilterSkeletonData ) ); m_iCurrentFrame = 0; } } else if ( m_iCurrentFrame == -1 ) { memcpy( &m_SkeletonData[1], pJoints, sizeof( FilterSkeletonData ) ); m_iCurrentFrame = 0; } else { ++m_iPreviousFrame; m_iPreviousFrame%=2; ++m_iCurrentFrame; m_iCurrentFrame%=2; memcpy( &m_SkeletonData[m_iCurrentFrame], pJoints, sizeof( FilterSkeletonData ) ); static const FLOAT fAlphaCoeff = 0.4f; static const FLOAT fBetaCoeff = ( fAlphaCoeff * fAlphaCoeff ) / ( 2.0f - fAlphaCoeff ); FilterSkeletonData* pPreviousSkeleton = &m_SkeletonData[m_iPreviousFrame]; FilterSkeletonData* pCurrentSkeleton = &m_SkeletonData[m_iCurrentFrame]; FilterVelocitySingleEstimate* pPreviousEstimate = &m_VelocityEstimate[m_iPreviousFrame]; FilterVelocitySingleEstimate* pCurrentEstimate = &m_VelocityEstimate[m_iCurrentFrame]; XMVECTOR vPredicted; XMVECTOR vError; for ( INT joint = 0; joint < NUI_SKELETON_POSITION_COUNT ; ++joint ) { // Calculate vPredicted position using last frames corrected position and velocity. vPredicted = XMVectorAdd( pPreviousSkeleton->m_Positions[ joint ], pPreviousEstimate->m_vEstVel[ joint ] ); // Calculate vError between vPredicted and measured position. vError = XMVectorSubtract( pCurrentSkeleton->m_Positions[ joint ], vPredicted ); // Calculate corrected position. pCurrentSkeleton->m_Positions[ joint ] = XMVectorAdd( vPredicted, vError * fAlphaCoeff ); // Calculate corrected velocity. pCurrentEstimate->m_vEstVel[ joint ]= XMVectorAdd( pPreviousEstimate->m_vEstVel[ joint ], vError * fBetaCoeff ); } } }
VOID Bound::Merge( const Bound& Other ) { Sphere OtherSphere; OtherSphere.Center = Other.GetCenter(); OtherSphere.Radius = Other.GetMaxRadius(); if( m_Type == Bound::No_Bound ) { SetSphere( OtherSphere ); return; } Sphere ThisSphere; if( m_Type != Bound::Sphere_Bound ) { // convert this bound into a sphere ThisSphere.Center = GetCenter(); ThisSphere.Radius = GetMaxRadius(); } else { ThisSphere = GetSphere(); } XMVECTOR vThisCenter = XMLoadFloat3( &ThisSphere.Center ); XMVECTOR vOtherCenter = XMLoadFloat3( &OtherSphere.Center ); XMVECTOR vThisToOther = XMVectorSubtract( vOtherCenter, vThisCenter ); XMVECTOR vDistance = XMVector3LengthEst( vThisToOther ); FLOAT fCombinedDiameter = XMVectorGetX( vDistance ) + ThisSphere.Radius + OtherSphere.Radius; if( fCombinedDiameter <= ( ThisSphere.Radius * 2 ) ) { SetSphere( ThisSphere ); return; } if( fCombinedDiameter <= ( OtherSphere.Radius * 2 ) ) { SetSphere( OtherSphere ); return; } XMVECTOR vDirectionNorm = XMVector3Normalize( vThisToOther ); XMVECTOR vRadius = XMVectorSet( ThisSphere.Radius, OtherSphere.Radius, 0, 0 ); XMVECTOR vThisRadius = XMVectorSplatX( vRadius ); XMVECTOR vOtherRadius = XMVectorSplatY( vRadius ); XMVECTOR vCombinedDiameter = vThisRadius + vDistance + vOtherRadius; XMVECTOR vMaxDiameter = XMVectorMax( vCombinedDiameter, vThisRadius * 2 ); vMaxDiameter = XMVectorMax( vMaxDiameter, vOtherRadius * 2 ); XMVECTOR vMaxRadius = vMaxDiameter * 0.5f; ThisSphere.Radius = XMVectorGetX( vMaxRadius ); vMaxRadius -= vThisRadius; XMVECTOR vCombinedCenter = vThisCenter + vMaxRadius * vDirectionNorm; XMStoreFloat3( &ThisSphere.Center, vCombinedCenter ); SetSphere( ThisSphere ); }
void XM_CALLCONV Camera::LookAt( FXMVECTOR iPos, FXMVECTOR iTarget, FXMVECTOR iUp ) { XMVECTOR L = XMVector3Normalize( XMVectorSubtract( iTarget, iPos ) ); XMVECTOR R = XMVector3Normalize( XMVector3Cross( iUp, L ) ); XMVECTOR U = XMVector3Cross( L, R ); XMStoreFloat3( &pos, iPos ); XMStoreFloat3( &look, L ); XMStoreFloat3( &right, R ); XMStoreFloat3( &up, U ); }
VOID DebugDraw::DrawGrid( const XMFLOAT3& XAxis, const XMFLOAT3& YAxis, const XMFLOAT3& Origin, INT iXDivisions, INT iYDivisions, D3DCOLOR Color ) { iXDivisions = max( 1, iXDivisions ); iYDivisions = max( 1, iYDivisions ); // build grid geometry INT iLineCount = iXDivisions + iYDivisions + 2; XMFLOAT3* pLines = new XMFLOAT3[ 2 * iLineCount ]; XMVECTOR vX = XMLoadFloat3( &XAxis ); XMVECTOR vY = XMLoadFloat3( &YAxis ); XMVECTOR vOrigin = XMLoadFloat3( &Origin ); for( INT i = 0; i <= iXDivisions; i++ ) { FLOAT fPercent = ( FLOAT )i / ( FLOAT )iXDivisions; fPercent = ( fPercent * 2.0f ) - 1.0f; XMVECTOR vScale = XMVectorScale( vX, fPercent ); vScale = XMVectorAdd( vScale, vOrigin ); XMStoreFloat3( &pLines[ ( i * 2 ) ], XMVectorSubtract( vScale, vY ) ); XMStoreFloat3( &pLines[ ( i * 2 ) + 1 ], XMVectorAdd( vScale, vY ) ); } INT iStartIndex = ( iXDivisions + 1 ) * 2; for( INT i = 0; i <= iYDivisions; i++ ) { FLOAT fPercent = ( FLOAT )i / ( FLOAT )iYDivisions; fPercent = ( fPercent * 2.0f ) - 1.0f; XMVECTOR vScale = XMVectorScale( vY, fPercent ); vScale = XMVectorAdd( vScale, vOrigin ); XMStoreFloat3( &pLines[ ( i * 2 ) + iStartIndex ], XMVectorSubtract( vScale, vX ) ); XMStoreFloat3( &pLines[ ( i * 2 ) + 1 + iStartIndex ], XMVectorAdd( vScale, vX ) ); } // draw grid SimpleShaders::SetDeclPos(); SimpleShaders::BeginShader_Transformed_ConstantColor( g_matViewProjection, Color ); g_pd3dDevice->DrawPrimitiveUP( D3DPT_LINELIST, iLineCount, pLines, sizeof( XMFLOAT3 ) ); SimpleShaders::EndShader(); delete[] pLines; }
XMVECTOR BoidManager::getVectorBetween(birds &a, birds &b) { XMVECTOR tempVectorA, tempVectorB, vectorBetween; tempVectorA = XMLoadFloat4(&a.getPosition()); tempVectorB = XMLoadFloat4(&b.getPosition()); vectorBetween = XMVectorSubtract(tempVectorA, tempVectorB); return vectorBetween; }
/** * Code available for download at http://cg.alexandra.dk/?p=147 used as reference for addWindForce */ void Cloth::addWindForce(Particle& p1, Particle& p2, Particle& p3) { XMVECTOR pos1, pos2, pos3, temp1, temp2, normal, force; pos1 = p1.getPosition(); pos2 = p2.getPosition(); pos3 = p3.getPosition(); temp1 = XMVectorSubtract(pos2, pos1); temp2 = XMVectorSubtract(pos3, pos1); normal = XMVector3Cross(temp1, temp2); temp1 = XMVector3Normalize(normal); force = XMVectorScale(normal, XMVectorScale(XMVector3Dot(temp1, windDirection), windConstant).m128_f32[0]); p1.addForce(force); p2.addForce(force); p3.addForce(force); }
bool Collider::IsColliding(GameObject* other) { auto otherTransform = other->transform; auto v1 = XMLoadFloat3(&transform->position); auto v2 = XMLoadFloat3(&otherTransform->position); auto vectorDiff = XMVectorSubtract(v1, v2); auto distVector = XMVector3LengthSq(vectorDiff); float dist; XMStoreFloat(&dist, distVector); float radSq = transform->scale.x * transform->scale.x*.56 + otherTransform->scale.x * otherTransform->scale.x*.56; return dist <= radSq; }
_Use_decl_annotations_ bool __vectorcall ShapeCast(const XMFLOAT3& posA, const XMFLOAT3& moveA, SupportMapping* supA, const XMFLOAT3& posB, const XMFLOAT3& moveB, SupportMapping* supB, XMFLOAT3* normal, float* distance) { XMVECTOR s = XMLoadFloat3(&posA); XMVECTOR r = XMVectorSubtract(XMLoadFloat3(&moveA), XMLoadFloat3(&moveB)); XMVECTOR lambda = XMVectorZero(); XMVECTOR x = s; XMVECTOR v = x - XMLoadFloat3(&posB); XMVECTOR vDotR; XMVECTOR p; XMVECTOR w; XMVECTOR simplexP[5] = {}; uint32_t bits = 0; *distance = 0.0f; *normal = XMFLOAT3(0, 0, 0); XMVECTOR e2 = g_XMEpsilon * g_XMEpsilon; uint32_t iterations = 0; while (XMVector2Greater(XMVector3LengthSq(v), e2) && iterations++ < 1000) { v = XMVector3Normalize(v); p = supA->GetSupportPoint(v) + supB->GetSupportPoint(v); w = x - p; if (XMVector2Greater(XMVector3Dot(v, w), XMVectorZero())) { vDotR = XMVector3Dot(v, r); if (XMVector2GreaterOrEqual(vDotR, XMVectorZero())) { return false; } lambda = lambda - XMVector3Dot(v, w) / vDotR; if (XMVector2Greater(lambda, XMVectorSet(1, 1, 1, 1))) { return false; } x = s + lambda * r; XMStoreFloat3(normal, v); } AddPoint(simplexP, p, &bits); v = FindSupportVectorAndReduce(simplexP, x, &bits); } *distance = XMVectorGetX(lambda); return true; }
void Camera::LookAt(FXMVECTOR pos, FXMVECTOR target, FXMVECTOR up){ XMVECTOR L = XMVector3Normalize(XMVectorSubtract(target, pos)); XMVECTOR R = XMVector3Normalize(XMVector3Cross(up, L)); XMVECTOR U = XMVector3Cross(L, R); XMStoreFloat3(&m_position, pos); XMStoreFloat3(&m_right, R); XMStoreFloat3(&m_up, U); XMStoreFloat3(&m_look, L); }
void Camera::LookAt(FXMVECTOR pos, FXMVECTOR target, FXMVECTOR worldUp) { XMVECTOR L = XMVector3Normalize(XMVectorSubtract(target, pos)); XMVECTOR R = XMVector3Normalize(XMVector3Cross(worldUp, L)); XMVECTOR U = XMVector3Cross(L, R); XMStoreFloat3(&mPosition, pos); XMStoreFloat3(&mLook, L); XMStoreFloat3(&mRight, R); XMStoreFloat3(&mUp, U); }
CFVec4 CFVec4::operator - ( CFVec4Arg vArg ) const { CFVec4 v4Return; const XMVECTOR& v4V = *reinterpret_cast<const XMVECTOR*>( this ); const XMVECTOR& v4V2 = *reinterpret_cast<const XMVECTOR*>( &vArg ); XMVECTOR& v4Result = *reinterpret_cast<XMVECTOR*>( &v4Return ); //Negate v4Result = XMVectorSubtract( v4V, v4V2 ); return v4Return; }
static void RenderScene(ID3D11DeviceContext* pd3dImmediateContext,bool shadow) { XMFLOAT4 ViewDir; XMStoreFloat4(&ViewDir,XMVectorSubtract(g_Camera.GetLookAtPt(),g_Camera.GetEyePt())); pd3dImmediateContext->OMSetBlendState(g_StateObjects->Opaque(),nullptr,0xFFFFFFFF); pd3dImmediateContext->OMSetDepthStencilState(g_StateObjects->DepthDefault(),0); ID3D11SamplerState* samplerState=g_StateObjects->LinearClamp(); pd3dImmediateContext->PSSetSamplers(0,1,&samplerState); XMMATRIX mView=g_Camera.GetViewMatrix(); XMMATRIX mProj=g_Camera.GetProjMatrix(); if(shadow){ pd3dImmediateContext->IASetInputLayout(g_pShadowVertexLayout.Get()); pd3dImmediateContext->VSSetShader(g_pShadowVertexShader.Get(),nullptr,0); pd3dImmediateContext->PSSetShader(nullptr,nullptr,0); } else{ g_PSVector.Set(pd3dImmediateContext,s_LightDir,ViewDir); g_PSLightColor.Set(pd3dImmediateContext,XMFLOAT4(0.075f,0.075f,0.075f,1.f), XMFLOAT4(0.85f,0.85f,0.85f,1.f),XMFLOAT4(0.8f,0.8f,0.8f,1.f)); g_PSMaterial.Set(pd3dImmediateContext,XMFLOAT4(1.0f,1.0f,1.0f,1.0f), XMFLOAT3(1.0f,1.0f,1.0f),500.0f,XMFLOAT3(0.0f,0.0f,0.0f)); g_PSVector.VSSet(pd3dImmediateContext); g_PSVector.PSSet(pd3dImmediateContext); g_PSLightColor.PSSet(pd3dImmediateContext); g_PSMaterial.PSSet(pd3dImmediateContext); pd3dImmediateContext->IASetInputLayout(g_pVertexLayout.Get()); pd3dImmediateContext->VSSetShader(g_pVertexShader.Get(),nullptr,0); pd3dImmediateContext->PSSetShader(g_pPixelShader.Get(),nullptr,0); pd3dImmediateContext->PSSetShaderResources(1,1,g_pShadowMapSRV.GetAddressOf()); } pd3dImmediateContext->PSSetSamplers(0,1,g_pSamplerLinear.GetAddressOf()); XMMATRIX world_view=world*view; XMMATRIX world_view_projection=world_view*projection; g_VSShadow.Set(pd3dImmediateContext,world*g_ShadowView*g_ShadowProjection); g_VSShadow.VSSet(pd3dImmediateContext); g_PSMaterial.Set(pd3dImmediateContext,color, XFLOAT3(0.0f,0.0f,0.0f),500.0f,XMFLOAT3(0.0f,0.0f,0.0f)); g_PSMaterial.PSSet(pd3dImmediateContext); }
void MainLoop() { Layer[0] = new VRLayer(Session); while (HandleMessages()) { ActionFromInput(); Layer[0]->GetEyePoses(); // Read the remote state ovrInputState inputState; ovr_GetInputState(Session, ovrControllerType_Remote, &inputState); unsigned int result = ovr_GetConnectedControllerTypes(Session); bool isRemoteConnected = (result & ovrControllerType_Remote) ? true : false; // Some auxiliary controls we're going to read from the remote. XMVECTOR forward = XMVector3Rotate(XMVectorSet(0, 0, -0.05f, 0), MainCam->Rot); XMVECTOR right = XMVector3Rotate(XMVectorSet(0.05f, 0, 0, 0), MainCam->Rot); if (inputState.Buttons & ovrButton_Up) MainCam->Pos = XMVectorAdd(MainCam->Pos, forward); if (inputState.Buttons & ovrButton_Down) MainCam->Pos = XMVectorSubtract(MainCam->Pos, forward); if (inputState.Buttons & ovrButton_Left) MainCam->Pos = XMVectorSubtract(MainCam->Pos, right); if (inputState.Buttons & ovrButton_Right) MainCam->Pos = XMVectorAdd(MainCam->Pos, right); for (int eye = 0; eye < 2; ++eye) { //Tint the world, green for it the controller is attached, otherwise red if (isRemoteConnected) Layer[0]->RenderSceneToEyeBuffer(MainCam, RoomScene, eye, 0, 0, 1,/**/ 1, 0.5f, 1, 0.5f /*green*/); else Layer[0]->RenderSceneToEyeBuffer(MainCam, RoomScene, eye, 0, 0, 1,/**/ 1, 1, 0, 0 /*red*/); } Layer[0]->PrepareLayerHeader(); DistortAndPresent(1); } }
void XM_CALLCONV PrimitveDrawer::DrawCylinder(FXMVECTOR P1, FXMVECTOR P2, float radius, FXMVECTOR Color) { auto center = 0.5f * XMVectorAdd(P1, P2); auto dir = XMVectorSubtract(P1, P2); auto scale = XMVector3Length(dir); scale = XMVectorSet(radius, XMVectorGetX(scale), radius, 1.0f); XMVECTOR rot; if (XMVector4Equal(dir, g_XMZero)) rot = XMQuaternionIdentity(); else rot = XMQuaternionRotationVectorToVector(g_XMIdentityR1, dir); XMMATRIX world = XMMatrixAffineTransformation(scale, g_XMZero, rot, center); m_pCylinder->Draw(world, ViewMatrix, ProjectionMatrix, Color); }
void Entity::SetGoToPoint(float x, float y, float z) { mGoToPos.x = x; mGoToPos.y = y, mGoToPos.z = z; goToPos = true; XMVECTOR first = XMLoadFloat3(&mGoToPos); XMVECTOR second = XMLoadFloat3(&mPosition); XMVECTOR end = XMVectorSubtract(first, second); XMVECTOR length = XMVector3Length(end); mDistanceLeft = XMVectorGetX(length); XMStoreFloat3(&mLook, XMVector3Normalize(end)); XMStoreFloat3(&mRight, XMVector3Cross(XMLoadFloat3(&mUp), XMLoadFloat3(&mLook))); }
void EnemyIceBear::DecideDirection(float distanceToPlayer, bool spawnSickNess) { XMVECTOR bearVector = XMLoadFloat3(&m_Position); XMVECTOR dir; if (distanceToPlayer < m_PlayerDetectionRadius && !spawnSickNess) { XMVECTOR playerVector = XMLoadFloat3(&m_pPlayerPointer->GetTransform()->GetPosition()); dir = XMVectorSubtract(playerVector, bearVector); } else { XMVECTOR igloVector = XMLoadFloat3(&m_pIgloPointer->GetTransform()->GetPosition()); dir = XMVectorSubtract(igloVector, bearVector); } XMFLOAT3 localDir; XMStoreFloat3(&localDir, dir); localDir.y = 0; dir = XMLoadFloat3(&localDir); dir = XMVector3Normalize(dir); XMStoreFloat3(&m_Direction, dir); }
// @brief 调整摄像机的朝向 // // @param pos 摄像机的位置 // @param target 目标的位置 // @param worldUp 摄像机所处世界的上方向量 void Camera::LookAt(FXMVECTOR pos, FXMVECTOR target, FXMVECTOR worldUp) { // 摄像机朝向即为摄像机位置指向目标位置的向量 XMVECTOR L = XMVector3Normalize(XMVectorSubtract(target, pos)); // 根据给定的up向量得出mRight, 一般为世界的up方向, 即y轴正方向 XMVECTOR R = XMVector3Normalize(XMVector3Cross(worldUp, L)); // 根据已确定的两个向量确定摄像机的up向量 XMVECTOR U = XMVector3Cross(L, R); XMStoreFloat3(&mLook, L); XMStoreFloat3(&mRight, R); XMStoreFloat3(&mUp, U); XMStoreFloat3(&mPos, pos); }
// static void ff::VectorKey::InitTangents(VectorKey *pKeys, size_t nKeys, float tension) { tension = (1.0f - tension) / 2.0f; for (size_t i = 0; i < nKeys; i++) { const VectorKey &keyBefore = pKeys[i ? i - 1 : nKeys - 1]; const VectorKey &keyAfter = pKeys[i + 1 < nKeys ? i + 1 : 0]; XMStoreFloat4(&pKeys[i]._tangent, XMVectorMultiply( XMVectorReplicate(tension), XMVectorSubtract( XMLoadFloat4(&keyAfter._value), XMLoadFloat4(&keyBefore._value)))); } }
int CMinotaurIdle::UpdateState(CMinotaur* _agent) { XMFLOAT3 curPos = *_agent->GetPosition(); // Convert them for math XMVECTOR mathPos = XMLoadFloat3(&curPos); XMVECTOR mathTarget = XMLoadFloat3(_agent->GetPlayer()->GetPosition()); // Find the vector between the two points XMVECTOR mathToVec = XMVectorSubtract(mathTarget, mathPos); XMVECTOR mathDistToTarget = XMVector3Length(mathToVec); /*if (mathDistToTarget.m128_f32[0] <= 1000.0f) return CMinotaur::eChaseState; if (m_fWaitTimer < 0)*/ return CMinotaur::ePatrolState; //return CMinotaur::eIdleState; }
XMVECTOR BoidManager::findAvoid(birds &bird) { birds tempBird = bird; XMVECTOR avoid = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f); XMVECTOR tempVectorI, tempVectorTB, vectorBetween; float distanceBetween; for (int i = 0; i < maxBirds; i++) { if (m_birds.at(i)->getID() != tempBird.getID()) //If bird is not itself { distanceBetween = getDistanceBetween(getVectorBetween(*m_birds.at(i), tempBird)); if (distanceBetween < 5.0f) { avoid = XMVectorSubtract(avoid, getVectorBetween(*m_birds.at(i), tempBird)); avoid = XMVector4Normalize(avoid); } } } return avoid; }
Vector3& Vector3::operator -= (const Vector3& other) { XMStoreFloat3(&mVector, XMVectorSubtract(XMLoadFloat3(&mVector), XMLoadFloat3(&other.mVector))); return *this; }
Vector3 Vector3::operator - (const Vector3& other) const { return Vector3(XMVectorSubtract(XMLoadFloat3(&mVector), XMLoadFloat3(&other.mVector))); }
CSkeleton::ESkeletonStates CSkeleton::Follow() { if (NearlyEqual(GetCurrAnimation()->GetCurrTime(), 0.05f)) { AudioSystemWwise::Get()->PostEvent(AK::EVENTS::PLAYERFOOTSTEP, *GetPosition()); } if (NearlyEqual(GetCurrAnimation()->GetCurrTime(), 0.5f)) { AudioSystemWwise::Get()->PostEvent(AK::EVENTS::PLAYERFOOTSTEP, *GetPosition()); } if (m_bIsGrounded) SetWorldVelocity({ 0, m_f3Velocity.y, 0 }); else SetWorldVelocity({ knockBackVelocity.x, m_f3Velocity.y, knockBackVelocity.z }); // Get the current path vector<XMFLOAT3>& vPath = GetPath(); // path here from group // Get the current velocity //XMVECTOR currentVelocity; XMLoadFloat3(&m_f3vel); if (DistanceToPlayer() < 500.0f) { return MOVING_IN; } // Node that I'm on along the path int nCurrentNode = GetCurNodeOnPath(); if (nCurrentNode < 0 || vPath.empty()) { BuildPathToPlayer(); vPath = GetPath(); if (vPath.size() < 2) { return FOLLOW; } } nCurrentNode = GetCurNodeOnPath(); // Get the current positions XMFLOAT3 curPos = *GetPosition(); XMFLOAT3 targetPos = vPath[nCurrentNode]; // Convert them for math XMVECTOR mathPos = XMLoadFloat3(&curPos); XMVECTOR mathTarget = XMLoadFloat3(&targetPos); // Find the vector between the two points XMVECTOR mathToVec = XMVectorSubtract(mathTarget, mathPos); //XMFLOAT3 toVec; XMStoreFloat3(&toVec, mathToVec); // Normalize the toVector to get the direction XMVECTOR mathVelocity = XMVector3Normalize(mathToVec); // Add the separation factor // mathVelocity += GetParentGroup()->CalculateSeparation(this); mathVelocity *= MOVE_SPEED; XMFLOAT3 realVelocity; XMStoreFloat3(&realVelocity, mathVelocity); realVelocity.y = m_f3Velocity.y; // Get the distance to target - ANY XYZ HOLDS THE LENGTH XMVECTOR mathDistToTarget = XMVector3Length(mathToVec); XMFLOAT3 distToTarget; XMStoreFloat3(&distToTarget, mathDistToTarget); // Offset the current node float nNextNodeDistance = 300.0f; // If i reached the node, move on the next one if (distToTarget.x < nNextNodeDistance && nCurrentNode >= 0) { nCurrentNode--; } Steering().Seek(targetPos); if (m_bIsGrounded) { Steering().Update(false, m_fScale); SetWorldVelocity(realVelocity); } SetNodeOnPath(nCurrentNode); return FOLLOW; }