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 LevelParts::setWorld(XMFLOAT4X4 tempLevelPartsWorld) { mLevelPartsWorld = tempLevelPartsWorld; XMMATRIX tempWorld = XMLoadFloat4x4(&mLevelPartsWorld); XMVECTOR Scale; XMVECTOR Position; XMVECTOR Rotation; XMMatrixDecompose(&Scale, &Rotation, &Position, tempWorld); XMStoreFloat3(&mLevelPartsPosition, Position); XMStoreFloat3(&mLevelPartsScale, Scale); XMStoreFloat4(&mLevelPartsRotation, Rotation); XMVECTOR S = XMLoadFloat3(&mLevelPartsScale); XMVECTOR P = XMLoadFloat3(&mLevelPartsPosition); XMVECTOR Q = XMLoadFloat4(&mLevelPartsRotationQuad); XMVECTOR rot = XMLoadFloat4(&mLevelPartsRotation); XMStoreFloat4x4(&mLevelPartsStartingWorld, XMMatrixAffineTransformation(S, rot, Q, P)); }
void AasRenderer::RecalcNormals(int vertexCount, const XMFLOAT4* pos, XMFLOAT4* normals, int primCount, const uint16_t* indices) { static XMFLOAT4 recalcNormalsBuffer[0x8000]; memset(recalcNormalsBuffer, 0, vertexCount * sizeof(XMFLOAT4)); // Process every TRI we have auto curIdx = indices; for (auto tri = 0; tri < primCount; ++tri) { // Indices of the three vertices making up this triangle auto idx1 = *curIdx++; auto idx2 = *curIdx++; auto idx3 = *curIdx++; auto pos1 = XMLoadFloat4(&pos[idx1]); auto pos2 = XMLoadFloat4(&pos[idx2]); auto pos3 = XMLoadFloat4(&pos[idx3]); auto v1to2(pos2 - pos1); auto v1to3(pos3 - pos1); // Calculate the surface normal of the surface defined // by the two directional vectors auto surfNormal(XMVector3Cross(v1to2, v1to3) * -1); // The surface normal contributes to all three vertex normals XMStoreFloat4(&normals[idx1], surfNormal); XMStoreFloat4(&normals[idx2], surfNormal); XMStoreFloat4(&normals[idx3], surfNormal); } // Re-Normalize the normals we calculated for (auto i = 0; i < vertexCount; ++i) { auto normal(XMVector3Normalize(XMLoadFloat4(&normals[i]))); XMStoreFloat4(&normals[i], normal); } }
void Body::Update(float dt, btTransform& Parent) { btVector3 parentPos; parentPos = Parent.getOrigin(); //Get Offset Rotation of a model(child) btQuaternion LocalRot; LocalRot = btQuaternion(m_yaw, m_pitch, m_roll); btQuaternion parentRotation; parentRotation = Parent.getRotation(); //Construct Directx Matricies out of give Quaternion rotations, sets up proper transformation of a model, Global + local XMMATRIX matrixChildRotation = XMMatrixRotationQuaternion(XMLoadFloat4(&XMFLOAT4(LocalRot.getX(), LocalRot.getY(), LocalRot.getZ(), LocalRot.getW()))); XMMATRIX matrixParentRotation = XMMatrixRotationQuaternion(XMLoadFloat4(&XMFLOAT4(parentRotation.getX(), parentRotation.getY(), parentRotation.getZ(), parentRotation.getW()))); //calcualte the final rotation by multiplying quaternions using dxmatrix XMMATRIX matrixFinalRotation = matrixChildRotation * matrixParentRotation; XMFLOAT3 m_offset = XMFLOAT3(0, 0, 0); XMMATRIX childOffset = XMMatrixTranslation(m_offset.x, m_offset.y, m_offset.z); XMMATRIX zeroWorld = XMMatrixTranslation(0, 0, 0); XMMATRIX translationMat = XMMatrixTranslation(parentPos.getX(), parentPos.getY(), parentPos.getZ()); XMMATRIX scaleMat = XMMatrixScaling(m_scale, m_scale, m_scale); XMMATRIX worldMat = childOffset * matrixFinalRotation * zeroWorld * scaleMat * translationMat; XMStoreFloat4x4(&m_worldMat, worldMat); }
Enemy::Enemy() : mEnemyPosition(0.0f, 0.0f, 0.0f), mEnemyScale(3.0f, 3.0f, 3.0f), mEnemyRotation(0.0f, 0.0f, 0.0f, 1.0f), mEnemyRotationQuad(0.0f, 0.0f, 0.0f, 0.0f), mEnemyPositionOne(0.0f, 0.0f, 0.0f), mEnemyPositionTwo(0.0f, 0.0f, 0.0f), travelToPoint(2), timesThrough(0) { ///initialize player XMVECTOR S = XMLoadFloat3(&mEnemyScale); XMVECTOR P = XMLoadFloat3(&mEnemyPosition); XMVECTOR Q = XMLoadFloat4(&mEnemyRotationQuad); XMVECTOR rot = XMLoadFloat4(&mEnemyRotation); XMStoreFloat4x4(&mEnemyWorld, XMMatrixAffineTransformation(S, rot, Q, P)); currCharDirection = XMVectorSet(0.0f, 3.0f, 0.0f, 0.0f); oldCharDirection = XMVectorSet(0.0f, 3.0f, 0.0f, 0.0f); charPosition = XMVectorSet(0.0f, 3.0f, 0.0f, 0.0f); EnemyForward = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f); EnemyRight = XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f); direction = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f); lastPoint = mEnemyPositionOne; }
// 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 = CreateEvent(nullptr, FALSE, FALSE, nullptr); if (eventHandle == nullptr) { ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError())); } ThrowIfFailed(m_fence->SetEventOnCompletion(m_pCurrentFrameResource->m_fenceValue, eventHandle)); WaitForSingleObject(eventHandle, INFINITE); CloseHandle(eventHandle); } 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); }
// static void ff::QuaternionKey::InitTangents(QuaternionKey *pKeys, size_t nKeys, float tension) { for (size_t i = 0; i < nKeys; i++) { QuaternionKey &keyCur = pKeys[i]; QuaternionKey &keyBefore = pKeys[i ? i - 1 : nKeys - 1]; QuaternionKey &keyNext = pKeys[(i + 1) % nKeys]; QuaternionKey &keyAfterNext = pKeys[(i + 2) % nKeys]; XMVECTOR keyCurTangent; XMVECTOR keyNextTangent; XMVECTOR keyNextValue; XMQuaternionSquadSetup( &keyCurTangent, // A &keyNextTangent, // B &keyNextValue, // C XMLoadFloat4(&keyBefore._value), // Q0 XMLoadFloat4(&keyCur._value), // Q1 XMLoadFloat4(&keyNext._value), // Q2 XMLoadFloat4(&keyAfterNext._value)); // Q3 XMStoreFloat4(&keyCur._tangent, keyCurTangent); XMStoreFloat4(&keyNext._tangent, keyNextTangent); XMStoreFloat4(&keyNext._value, keyNextValue); } }
void AnimModel::CreateFinalMatrices(UINT clipNumber1, UINT frameNumber1, UINT clipNumber2, UINT frameNumber2, float blendFactor, XMFLOAT4X4* finalMatrices) { // смешивание двух клипов XMFLOAT3 positionF3; XMVECTOR quatF4; std::vector<XMFLOAT4X4> toRoot(bonesAmount); for (UINT i(0); i < bonesAmount; i++) { // загрузка матриц XMVECTOR position1 = XMLoadFloat3(&clips[clipNumber1].bonesPositions[i + bonesAmount * frameNumber1]); XMVECTOR position2 = XMLoadFloat3(&clips[clipNumber2].bonesPositions[i + bonesAmount * frameNumber2]); XMStoreFloat3(&positionF3, XMVectorLerp(position1, position2, blendFactor)); XMVECTOR quaternion1 = XMLoadFloat4(&clips[clipNumber1].bonesQuaternions[i + bonesAmount * frameNumber1]); XMVECTOR quaternion2 = XMLoadFloat4(&clips[clipNumber2].bonesQuaternions[i + bonesAmount * frameNumber2]); quatF4 = XMQuaternionSlerp(quaternion1, quaternion2, blendFactor); // интерполяция матриц XMMATRIX T = XMMatrixTranslation(positionF3.x, positionF3.y, positionF3.z); XMMATRIX R = XMMatrixRotationQuaternion(quatF4); XMStoreFloat4x4(&toRoot[i], R * T); } // перемножение матриц для получения final for (UINT i(0); i < bonesAmount; i++) { UINT coef = order[i]; if (hierarchy[coef] == -1) continue; XMStoreFloat4x4(&toRoot[coef], XMLoadFloat4x4(&toRoot[coef]) * XMLoadFloat4x4(&toRoot[hierarchy[coef]])); } for (UINT i(0); i < bonesAmount; i++) { XMMATRIX offSet = XMLoadFloat4x4(&offsetMatrices[i]); XMStoreFloat4x4(&finalMatrices[i], offSet * XMLoadFloat4x4(&toRoot[i])); } }
DirectX::XMFLOAT4 BoneAnimationData::GetRotationValue(float time) { if(time <= rotationKeys[0].time) return rotationKeys[0].val; if(time >= rotationKeys[numberOfRotationKeys-1].time) return rotationKeys[numberOfRotationKeys-1].val; int rIndex; for(int i = 0;i < numberOfRotationKeys;i++) { if(rotationKeys[i].time >= time) { rIndex = i; break; } } float coef = (time - rotationKeys[rIndex-1].time) / (rotationKeys[rIndex].time - rotationKeys[rIndex-1].time); DirectX::XMVECTOR v1 = XMLoadFloat4(&rotationKeys[rIndex-1].val); DirectX::XMVECTOR v2 = XMLoadFloat4(&rotationKeys[rIndex].val); DirectX::XMVECTOR res = DirectX::XMQuaternionNormalize(DirectX::XMQuaternionSlerp(v1,v2,coef)); DirectX::XMFLOAT4 r; DirectX::XMStoreFloat4(&r,res); return r; }
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; }
LightComponent::LightComponent(XMFLOAT4 pos, Light::LIGHTTYPE type, XMFLOAT4 dir, bool isCastingShadow, XMFLOAT4 color, float range, float spotAngle, float attenuation) : m_range(range), m_isCastingShadow(isCastingShadow) { m_light.Position = XMLoadFloat4(&pos); m_light.Color = XMLoadFloat4(&color); m_light.Direction = XMLoadFloat4(&dir); XMFLOAT4 misc = XMFLOAT4(spotAngle, attenuation, (float)type, 0.0f); m_light.X_SpotAngleAndY_AttenuationAndZ_LightType = XMLoadFloat4(&misc); }
void Graphics::exe_cam_curr(uint32_t const _i_zad) { XMStoreFloat4x4(&cam.mtx_view, XMMatrixLookAtLH( XMLoadFloat3(&cam.pos), XMVector3Rotate(XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f), XMLoadFloat4(&cam.quat)) + XMLoadFloat3(&cam.pos), XMVector3Rotate(XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f), XMLoadFloat4(&cam.quat)) )); XMStoreFloat4x4(&cam.mtx_proj, XMMatrixPerspectiveFovLH( cam.angle * 3.14f/180, float(szerRend)/wysRend, cam.near_z, cam.far_z )); task.erase(_i_zad); }
void Camera::rotateZ(float amount) { XMMATRIX mRotate = XMMatrixRotationZ(amount); XMVECTOR new_x = XMVector4Transform(XMLoadFloat4(&v_Right), mRotate); XMVECTOR new_z = XMVector4Transform(XMLoadFloat4(&v_Look), mRotate); XMStoreFloat4(&v_Right, new_x); XMStoreFloat4(&v_Look, new_z); update(); }
void Camera::CalculateViewProjection() { // Initialize the view matrix XMVECTOR Eye = XMLoadFloat4(&_eye); XMVECTOR At = XMLoadFloat4(&_at); XMVECTOR Up = XMLoadFloat4(&_up); XMStoreFloat4x4(&_view, XMMatrixLookAtLH(Eye, At, Up)); // Initialize the projection matrix XMStoreFloat4x4(&_projection, XMMatrixPerspectiveFovLH(XM_PIDIV2, _windowWidth / _windowHeight, _nearDepth, _farDepth)); }
void Camera::rotateX(float amount) { XMMATRIX mRotate = XMMatrixRotationAxis(XMLoadFloat4(&v_Right), amount); XMVECTOR new_y = XMVector4Transform(XMLoadFloat4(&v_Up), mRotate); XMVECTOR new_z = XMVector4Transform(XMLoadFloat4(&v_Look), mRotate); XMStoreFloat4(&v_Up, new_y); XMStoreFloat4(&v_Look, new_z); update(); }
bool FrustumClass::CheckPoint(float x, float y, float z) { for (int i = 0; i < 6; i++) { XMVECTOR vector = XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4(x, y, z, 1.0f))); if (vector.m128_f32[0] < 0.0f) { return false; } } return true; }
bool Frustum::CheckSphere(FLOAT xCenter, FLOAT yCenter, FLOAT zCenter, FLOAT radius) { // Check if the radius of the sphere is inside the view frustum. for (INT i = 0; i < 6; i++) { if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4(xCenter, yCenter, zCenter, 1.0f))).vector4_f32[0] < -radius) { return false; } } return true; }
void TestTriangleStripsDX::Update() { if (processInput) { float rotAmount = 0.0f; XMMATRIX rotMatrix = XMMatrixIdentity(); if (input.right || input.left) { if (input.right) rotAmount = rotDelta; if (input.left) rotAmount = -rotDelta; rotMatrix = XMMatrixRotationAxis(XMLoadFloat4(&up), XMConvertToRadians(rotAmount)); } else if (input.up || input.down) { if (input.up) rotAmount = rotDelta; if (input.down) rotAmount = -rotDelta; rotMatrix = XMMatrixRotationAxis(XMLoadFloat4(&right), XMConvertToRadians(rotAmount)); } XMStoreFloat4(&eye, XMVector3Transform(XMLoadFloat4(&eye), rotMatrix)); XMStoreFloat4(&right, XMVector3Normalize(XMVector3Cross(XMLoadFloat4(&up), (XMLoadFloat4(¢er) - XMLoadFloat4(&eye))))); XMMATRIX viewMatrix = XMMatrixLookAtRH(XMLoadFloat4(&eye), XMLoadFloat4(¢er), XMLoadFloat4(&up)); mDeviceContext->UpdateSubresource(viewMatrixBuffer, 0, NULL, &viewMatrix, 0, 0); } }
void BoneAnimation::Interpolate(float t, XMFLOAT4X4& M)const { if( t <= Keyframes.front().TimePos ) { XMVECTOR S = XMLoadFloat3(&Keyframes.front().Scale); XMVECTOR P = XMLoadFloat3(&Keyframes.front().Translation); XMVECTOR Q = XMLoadFloat4(&Keyframes.front().RotationQuat); XMVECTOR zero = XMVectorSet(0.0f, 0.0f, 0.0f, 1.0f); XMStoreFloat4x4(&M, XMMatrixAffineTransformation(S, zero, Q, P)); } else if( t >= Keyframes.back().TimePos ) { XMVECTOR S = XMLoadFloat3(&Keyframes.back().Scale); XMVECTOR P = XMLoadFloat3(&Keyframes.back().Translation); XMVECTOR Q = XMLoadFloat4(&Keyframes.back().RotationQuat); XMVECTOR zero = XMVectorSet(0.0f, 0.0f, 0.0f, 1.0f); XMStoreFloat4x4(&M, XMMatrixAffineTransformation(S, zero, Q, P)); } else { for(UINT i = 0; i < Keyframes.size()-1; ++i) { if( t >= Keyframes[i].TimePos && t <= Keyframes[i+1].TimePos ) { float lerpPercent = (t - Keyframes[i].TimePos) / (Keyframes[i+1].TimePos - Keyframes[i].TimePos); XMVECTOR s0 = XMLoadFloat3(&Keyframes[i].Scale); XMVECTOR s1 = XMLoadFloat3(&Keyframes[i+1].Scale); XMVECTOR p0 = XMLoadFloat3(&Keyframes[i].Translation); XMVECTOR p1 = XMLoadFloat3(&Keyframes[i+1].Translation); XMVECTOR q0 = XMLoadFloat4(&Keyframes[i].RotationQuat); XMVECTOR q1 = XMLoadFloat4(&Keyframes[i+1].RotationQuat); XMVECTOR S = XMVectorLerp(s0, s1, lerpPercent); XMVECTOR P = XMVectorLerp(p0, p1, lerpPercent); XMVECTOR Q = XMQuaternionSlerp(q0, q1, lerpPercent); XMVECTOR zero = XMVectorSet(0.0f, 0.0f, 0.0f, 1.0f); XMStoreFloat4x4(&M, XMMatrixAffineTransformation(S, zero, Q, P)); break; } } } }
bool Frustum::CheckPoint(FLOAT x, FLOAT y, FLOAT z) { // Check if the point is inside all six planes of the view frustum. for (INT i = 0; i < 6; i++) { XMVECTOR vector = XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4(x, y, z, 1.0f))); if (vector.vector4_f32[0] < 0.0f) { return false; } } return true; }
void Renderer::CullLight( SpotLight* light, Transform* pTransform ) { if (m_Mesh) { XNA::OrientedBox objectBox; XNA::Frustum lightFrustum = light->GetFrustum(); for( int i=0; i<m_Mesh->GetNumberOfSubmeshes(); i++ ) { if (m_SubmeshRenderData[i].bVisible) { Submesh* submesh = m_Mesh->GetSubmesh( i ); XMVECTOR extents = XMLoadFloat3( &submesh->GetGeometryChunk()->GetAABB()->Extents ); XMVECTOR scale = XMLoadFloat3( &pTransform->GetScale().intoXMFLOAT3() ); XMVECTOR offset = XMLoadFloat3( &submesh->GetGeometryChunk()->GetAABB()->Center )*scale; XMVECTOR position = XMVector3Rotate( offset, XMLoadFloat4(&pTransform->GetOrientation().intoXMFLOAT4()) ); position += XMLoadFloat3( &pTransform->GetPosition().intoXMFLOAT3() ); XMStoreFloat3( &objectBox.Center, position ); XMStoreFloat3( &objectBox.Extents, extents*scale ); objectBox.Orientation = pTransform->GetOrientation().intoXMFLOAT4(); if( XNA::IntersectOrientedBoxFrustum( &objectBox, &lightFrustum ) > 0 ) m_SubmeshRenderData[i].AffectingSpotLights.push_back( light ); } } } }
void Renderer::Cull( XNA::Frustum* frustum, Transform* pTransform ) { if (m_Mesh) { XNA::OrientedBox objectBox; for( int i=0; i<m_Mesh->GetNumberOfSubmeshes(); i++ ) { Submesh* submesh = m_Mesh->GetSubmesh( i ); XMVECTOR extents = XMLoadFloat3( &submesh->GetGeometryChunk()->GetAABB()->Extents ); XMVECTOR scale = XMLoadFloat3( &pTransform->GetScale().intoXMFLOAT3() ); XMVECTOR offset = XMLoadFloat3( &submesh->GetGeometryChunk()->GetAABB()->Center )*scale; XMVECTOR position = XMVector3Rotate( offset, XMLoadFloat4(&pTransform->GetOrientation().intoXMFLOAT4()) ); position += XMLoadFloat3( &pTransform->GetPosition().intoXMFLOAT3() ); XMStoreFloat3( &objectBox.Center, position ); XMStoreFloat3( &objectBox.Extents, extents*scale ); objectBox.Orientation = pTransform->GetOrientation().intoXMFLOAT4(); if( XNA::IntersectOrientedBoxFrustum( &objectBox, frustum ) > 0 ) m_SubmeshRenderData[i].bVisible = true; else m_SubmeshRenderData[i].bVisible = false; } } }
XMVECTOR BoidManager::findSeek(birds &bird) { birds tempBird = bird; XMVECTOR seek = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f); XMVECTOR tempVectorI; XMVECTOR tempVectorTB = XMLoadFloat4(&tempBird.getPosition()); float distanceBetween; bool seeking = false; int count = 0; for (int i = 0; i < maxBirds; i++) { if (m_birds.at(i)->getID() != tempBird.getID()) { distanceBetween = getDistanceBetween(getVectorBetween(*m_birds.at(i), tempBird)); if (distanceBetween < 15.0f) { tempVectorI = m_birds.at(i)->getVector(); seek = XMVectorAdd(seek, tempVectorI); ++count; } } } if (count > 1) { seek = XMVectorSubtract(seek, tempVectorTB); seek = XMVector4Normalize(seek); seek = seek / (count - 1); seek = XMVectorSubtract(seek, tempBird.getVector()) / 100; } return seek; }
void RenderString::Render(SpriteFont *spriteFontPtr, SpriteBatch *spriteBatchPtr) { spriteFontPtr->DrawString(spriteBatchPtr, text.c_str(), XMLoadFloat3(&position), XMLoadFloat4(&color), rotation, XMLoadFloat3(&origin), XMLoadFloat3(&scale), effects, layerDepth); }
_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))); }
void Direct3D::update(float dt) { static float rotDT = 0.f; rotDT = dt; XMMATRIX rot = XMMatrixRotationAxis(XMVectorSet(0.f, 0.f, 1.f, 0.f), rotDT); for(int i = 0; i < NROFLIGHTS; i++) { XMVECTOR vLightPos = XMLoadFloat4(&m_lightList[i].pos); vLightPos = XMVector4Transform(vLightPos, rot); XMStoreFloat4(&m_lightList[i].pos, vLightPos); } m_pCamera->update(); //m_fps = 1/dt; m_time += dt; static int frameCnt = 0; static float t_base = 0.f; frameCnt++; if(m_time - t_base >= 1.f) { frameCnt /= 1; m_fps = (float)frameCnt; frameCnt = 0; t_base += 1.f; } updateConstantBuffers(); }
// создать финальные матрицы для шейдера void AnimModel::CreateFinalMatricesOldStyle(UINT clipNumber, UINT frameNumber, XMFLOAT4X4* finalMatrices) { // без смешивания клипов по древнему алгоритму (для отладки) // загрузка матриц std::vector<XMFLOAT4X4> reserve(bonesAmount); std::vector<XMFLOAT4X4> reserve2(bonesAmount); for (UINT i(0); i < bonesAmount; i++) { XMFLOAT3 position = clips[clipNumber].bonesPositions[i + bonesAmount * frameNumber]; XMMATRIX T = XMMatrixTranslation(position.x, position.y, position.z); XMFLOAT4 quaternion = clips[clipNumber].bonesQuaternions[i + bonesAmount * frameNumber]; XMMATRIX R = XMMatrixRotationQuaternion(XMLoadFloat4(&quaternion)); XMStoreFloat4x4(&reserve[i], R * T); XMStoreFloat4x4(&reserve2[i], R * T); } // перемножение матриц для получения final for (UINT i(0); i < bonesAmount; i++) { XMMATRIX fin = XMMatrixIdentity(); UINT curMatrix = i; fin = fin * XMLoadFloat4x4(&reserve[curMatrix]); while (curMatrix != -1) { curMatrix = hierarchy[curMatrix]; if (curMatrix == -1) break; fin = fin * XMLoadFloat4x4(&reserve[curMatrix]); } XMMATRIX offSet = XMLoadFloat4x4(&offsetMatrices[i]); XMStoreFloat4x4(&finalMatrices[i], offSet * fin); } }
// 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)))); } }
void RayTraceDataGenerator::GenerateRaytraceResult(int width, int height,float scale, XMFLOAT4 loc, int neardistance, int maxdepth, XMFLOAT4 n, XMFLOAT4 up, void(*CallbackFunc)(int x, int y, const int& TexType, const XMFLOAT4& loc, const XMFLOAT4& n,const float& depth, void* arg), void* arg) { XMVECTOR v_ori = XMLoadFloat4(&loc); XMVECTOR v_center=XMLoadFloat4(&loc); XMVECTOR v_n = XMLoadFloat4(&n); XMVECTOR v_up = XMVector3Normalize(XMLoadFloat4(&up)); v_center = XMVectorAdd(v_center, XMVectorScale(v_n, neardistance)); XMVECTOR v_dir_x = XMVector3Cross(v_n, v_up); XMVECTOR v_dir_y = XMVector3Cross(v_n, v_dir_x); XMVECTOR v_current = XMVectorAdd(v_center, XMVectorScale(v_dir_x, -scale*width*0.5)); XMVECTOR v_ret_n; XMVECTOR v_ret_loc; //XMFLOAT4 v_unpacked; XMFLOAT4 v_ret_unpack_n; XMFLOAT4 v_ret_unpack_loc; XMVECTOR v_corner1; XMVECTOR v_corner2; bool result; float f_ret_depth; v_current = XMVectorAdd(v_current, XMVectorScale(v_dir_y, -scale*height*0.5)); v_corner1 = v_current; v_corner2 = XMVectorAdd(v_current, XMVectorScale(v_dir_y, +scale*height*1.0)); v_corner2 = XMVectorAdd(v_corner2, XMVectorScale(v_dir_x, +scale*width*1.0)); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) {//XMVector3Normalize(XMVectorSubtract(v_current, v_ori)) result = CalcIntersect(v_current, v_n, &v_ret_n, &v_ret_loc, &f_ret_depth); if (result) { XMStoreFloat4(&v_ret_unpack_loc,v_ret_loc); XMStoreFloat4(&v_ret_unpack_n, v_ret_n); CallbackFunc(i, j, GetLocInfo((int)v_ret_unpack_loc.x, (int)v_ret_unpack_loc.y, (int)v_ret_unpack_loc.z), v_ret_unpack_loc, v_ret_unpack_n, f_ret_depth, arg); } else { v_ret_unpack_n.x = v_ret_unpack_n.y = v_ret_unpack_n.z = -1; v_ret_unpack_loc.x = v_ret_unpack_loc.y = v_ret_unpack_loc.z = -1; f_ret_depth = -1; CallbackFunc(i, j, -1, v_ret_unpack_loc, v_ret_unpack_n, f_ret_depth, arg); } v_current = XMVectorAdd(v_current, XMVectorScale(v_dir_y, scale)); } v_current = XMVectorAdd(v_current, XMVectorScale(v_dir_x, scale)); } }
XMFLOAT3 EliteEnemyShip::getPosition() { XMFLOAT4 pos; XMFLOAT4 orig = XMFLOAT4(0,0,0,1); XMFLOAT4X4 mat = *(body->getWorldMatrix()); XMStoreFloat4(&pos, XMVector4Transform(XMLoadFloat4(&orig), XMLoadFloat4x4(&mat))); return (XMFLOAT3(pos.x, pos.y, pos.z)); }