_Use_decl_annotations_ void KdTreeCompiler2::SplitEdge(_In_ const StaticGeometryVertex& v0, _In_ const StaticGeometryVertex& v1, uint32_t axis, float value, _Out_ StaticGeometryVertex* v) { XMFLOAT3 vv0 = v0.Position; XMFLOAT3 vv1 = v1.Position; float d0 = *(&vv0.x + axis) - value; XMVECTOR sub = XMVectorSubtract(XMLoadFloat3(&vv1), XMLoadFloat3(&vv0)); XMVECTOR dir = XMVector3Normalize(sub); XMVECTOR n = XMLoadFloat3(&_normals[axis]); float d = d0; if (d > 0) { n = XMVectorNegate(n); } else if (d < 0) { d = -d; } else { assert(false); } float x = d / XMVectorGetX(XMVector3Dot(n, dir)); XMStoreFloat3(&v->Position, XMVectorAdd(XMLoadFloat3(&vv0), XMVectorScale(dir, x))); }
_Use_decl_annotations_ void BspCompiler::SplitEdge(const Vertex& v0, const Vertex& v1, const XMFLOAT4& plane, Vertex* v) { XMFLOAT3 vv0 = v0.Position; XMFLOAT3 vv1 = v1.Position; float d0 = DistToPlane(plane, vv0); XMVECTOR sub = XMVectorSubtract(XMLoadFloat3(&vv1), XMLoadFloat3(&vv0)); XMVECTOR dir = XMVector3Normalize(sub); XMVECTOR n = XMLoadFloat4(&plane); float d = d0; if (d > 0) { n = XMVectorNegate(n); } else if (d < 0) { d = -d; } else { assert(false); } float x = d / XMVectorGetX(XMVector3Dot(n, dir)); XMStoreFloat3(&v->Position, XMVectorAdd(XMLoadFloat3(&vv0), XMVectorScale(dir, x))); }
// vector operations CFVec4 CFVec4::operator - ( void ) const { CFVec4 v4Return; const XMVECTOR& v4V = *reinterpret_cast<const XMVECTOR*>( this ); XMVECTOR& v4Result = *reinterpret_cast<XMVECTOR*>( &v4Return ); //Negate v4Result = XMVectorNegate( v4V ); return v4Return; }
void World::moveEntity( WorldEntity* entity, XMVECTOR moveVec, float dist ) { //Try to move the entity in the world along the moveVec XMVECTOR pos = XMLoadFloat4( &entity->getPosition() ); XMVECTOR wall = XMVectorZero(); XMVECTOR vel = XMVectorScale( moveVec, dist ); XMVECTOR desiredPos; XMFLOAT4 check; XMFLOAT4 negativeCheck; int checks = 0; int maxChecks = 10; float saveDist = dist; float distInterval = dist / static_cast<float>(maxChecks); XMStoreFloat4( &check, XMVector3Length(moveVec) ); //Don't bother doing anything if there is no movement direction if( check.x <= 0.0f ){ return; } //Check collision at where we plan to be if( checkEntityCollision( entity, pos, &wall ) ){ XMStoreFloat4( &check, wall ); XMStoreFloat4( &negativeCheck, vel ); //Check the negative bit of the x and z values and see if they are equal, if they are, then stop movement bool negativeXWall = *(int*)(&check.x) < 0; bool negativeZWall = *(int*)(&check.z) < 0; bool negativeXVel = *(int*)(&negativeCheck.x) < 0; bool negativeZVel = *(int*)(&negativeCheck.z) < 0; //If we are not in a corner, collide with the wall, otherwise stop movement if(check.w <= 1.5f || ( negativeXWall != negativeXVel || negativeZWall != negativeZVel ) ){ XMVECTOR invWall = XMVectorNegate( wall ); wall = wall * XMVector3Length( moveVec * invWall ); vel = (moveVec - wall) * dist; }else{ vel = XMVectorZero(); } } desiredPos = pos + vel; XMStoreFloat4( &entity->getPosition(), desiredPos ); }
void ForwardPlusRenderer::RenderFinal(const RenderView& view, const RenderTarget& renderTarget) { auto& pass = (MsaaEnabled) ? FinalPassMsaa : FinalPass; if (!MsaaEnabled) { pass->SetRenderTarget(0, renderTarget.Texture->GetRTV()); } pass->Begin(); XMMATRIX worldToView = XMLoadFloat4x4(&view.WorldToView); XMMATRIX worldToProjection = XMMatrixMultiply(worldToView, XMLoadFloat4x4(&view.ViewToProjection)); // Directional Lights are shared for all objects, so fill up front FinalPassPSConstants psConstants{}; psConstants.NumLights = 0; psConstants.TileSize = NUM_PIXELS_PER_GROUP_X; psConstants.NumTilesX = RTWidth / NUM_PIXELS_PER_GROUP_X; for (auto& light : Lights) { if (light->GetType() == LightType::Directional) { psConstants.Lights[psConstants.NumLights].Color = light->GetColor(); XMFLOAT4X4 localToWorld = light->GetLocalToWorld(); XMVECTOR lightDir = XMVectorNegate(XMVectorSet(localToWorld.m[2][0], localToWorld.m[2][1], localToWorld.m[2][2], 0.f)); lightDir = XMVector3TransformNormal(lightDir, worldToView); XMStoreFloat3(&psConstants.Lights[psConstants.NumLights].Direction, lightDir); ++psConstants.NumLights; } } FinalPassPSCB->Update(&psConstants, sizeof(psConstants)); // Remainder of data is object-specific FinalPassVSConstants constants{}; for (auto& visual : Visuals) { XMMATRIX localToWorld = XMLoadFloat4x4(&visual->GetLocalToWorld()); XMStoreFloat4x4(&constants.LocalToView, XMMatrixMultiply(localToWorld, worldToView)); XMStoreFloat4x4(&constants.LocalToProjection, XMMatrixMultiply(localToWorld, worldToProjection)); HRESULT hr = FinalPassVSCB->Update(&constants, sizeof(constants)); if (FAILED(hr)) { assert(false); continue; } pass->SetPSResource(3, visual->GetAlbedoTexture() ? visual->GetAlbedoTexture()->GetSRV() : nullptr); pass->SetPSResource(4, visual->GetNormalTexture() ? visual->GetNormalTexture()->GetSRV() : nullptr); pass->Draw(visual); } pass->End(); if (MsaaEnabled) { Context->ResolveSubresource(renderTarget.Texture->GetTexture().Get(), 0, FinalRTMsaa->GetTexture().Get(), 0, FinalRTMsaa->GetDesc().Format); } }