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); }
XMMATRIX ModelLoader::ConvertMatrix( aiMatrix4x4 inMat ) { return XMLoadFloat4x4( &XMFLOAT4X4( inMat.a1, inMat.b1, inMat.c1, inMat.d1, inMat.a2, inMat.b2, inMat.c2, inMat.d2, inMat.a3, inMat.b3, inMat.c3, inMat.d3, inMat.a4, inMat.b4, inMat.c4, inMat.d4 ) ); }
SpotLight &SpotLight::operator=(const SpotLight &rhs) { cBufferData.spotLight.enabled = rhs.cBufferData.spotLight.enabled; cBufferData.spotLight.diffuseColor = rhs.cBufferData.spotLight.diffuseColor; cBufferData.spotLight.ambientColor = rhs.cBufferData.spotLight.ambientColor; cBufferData.spotLight.specularColor = rhs.cBufferData.spotLight.specularColor; cBufferData.spotLight.specularPower = rhs.cBufferData.spotLight.specularPower; cBufferData.spotLight.specularIntensity = rhs.cBufferData.spotLight.specularIntensity; cBufferData.spotLight.attenuation = rhs.cBufferData.spotLight.attenuation; cBufferData.spotLight.range = rhs.cBufferData.spotLight.range; cBufferData.spotLight.cutoff = rhs.cBufferData.spotLight.cutoff; cBufferData.spotLight.exponent = rhs.cBufferData.spotLight.exponent; XMMATRIX mat = XMMatrixScaling( cBufferData.spotLight.range, cBufferData.spotLight.range, cBufferData.spotLight.range); delete renderShape; this->renderShape = new RenderShapeLight; renderShape->Initialize(rhs.renderShape->GetRenderFormHandles(), rhs.renderShape->GetWorldMatrixPtr()); SetWorldMatrixPtr(&XMFLOAT4X4( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)); renderShape->SetLight(this); D3D11_BUFFER_DESC bd; rhs.cBuffer->GetDesc(&bd); cBuffer.Release(); HR(Renderer::theDevicePtr->CreateBuffer(&bd, nullptr, &cBuffer)); return *this; }
CubeDemo::CubeDemo(Game & game, Camera & camera) : DrawableGameComponent(game, camera), mEffect(nullptr), mTechnique(nullptr), mPass(nullptr), mWvpVariable(nullptr), mInputLayout(nullptr), mVertexBuffer(nullptr), mWorldMatrix(XMFLOAT4X4(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f)), mAngle(0.0f) { }
XMMATRIX ModelLoader::ConvertFBXtoDXMatrix( aiMatrix4x4 inMat ) { // aiMatrix is transposed XMMATRIX xmInMat = XMLoadFloat4x4( &XMFLOAT4X4( inMat.a1, inMat.b1, inMat.c1, inMat.d1, inMat.a2, inMat.b2, inMat.c2, inMat.d2, inMat.a3, inMat.b3, inMat.c3, inMat.d3, inMat.a4, inMat.b4, inMat.c4, inMat.d4 ) ); XMVECTOR translate, scale, rotQuat; XMMatrixDecompose( &scale, &rotQuat, &translate, xmInMat ); scale = scale*100; return nullptr; }
Direct3D::Direct3D(HWND p_hwnd) : m_hWnd(p_hwnd), m_SwapChain(nullptr), m_Device(nullptr), m_DeviceContext(nullptr), m_BackBufferUAV(nullptr), m_Timer(nullptr), m_ComputeSys(nullptr), m_ComputeShader(nullptr), m_PrimaryShader(nullptr), m_IntersectionShader(nullptr), m_ColorShader(nullptr), m_FinalColorBuffer(nullptr), m_RayBuffer(nullptr), m_HitDataBuffer(nullptr), m_time(0.f), m_fps(0.f), m_mesh(Mesh()), m_meshBuffer(nullptr), m_cBuffer(nullptr), m_PrimaryCBuffer(nullptr), m_IntersectionCBuffer(nullptr), m_ColorCBuffer(nullptr), m_FirstPassCBuffer(nullptr), m_Height(0), m_Width(0), m_Row(0), m_IVP(XMFLOAT4X4()), m_lightList(), m_meshTexture(nullptr), m_pCamera(nullptr), m_pInput(nullptr), m_sphere(Sphere()), m_triangles(), m_view(XMFLOAT4X4()), m_proj(XMFLOAT4X4()), m_FirstPassStruct() { }
DirectX::XMFLOAT4X4 AnimationController::GetBoneTransform( Bone* bone ) { auto it = finalTransform.find( bone ); if( it==finalTransform.end() ) { fprintf( stderr, "Bone Rotation not found : %s\n", bone->name.c_str() ); return XMFLOAT4X4( 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f ); } else { return it->second; } }
void Graphics::exe_world_curr(uint32_t const _i_zad) { Vec<XMFLOAT4X4> _mac; for(uint32_t _i = 0; _i < phys_par.mtx_world.get_size(); ++_i) { _mac.push_back(XMFLOAT4X4()); XMStoreFloat4x4(&_mac[_i], XMMatrixTranspose( XMLoadFloat4x4(&phys_par.mtx_world[_i]) * XMLoadFloat4x4(&cam.mtx_view) * XMLoadFloat4x4(&cam.mtx_proj) )); } res.update_world(&_mac[0], _mac.get_size()); task.erase(_i_zad); }
void Input::Pick(_Out_ XMVECTOR& rayPos, _Out_ XMVECTOR& rayDir, _In_ XMMATRIX& world, _In_ XMMATRIX& view, _In_ XMMATRIX& proj) { const DXGI_SURFACE_DESC* pd3dsdBackBuffer = DXUTGetDXGIBackBufferSurfaceDesc(); POINT ptcursor = getMousePos(); // Compute the vector of the pick ray in screen space XMFLOAT4X4 mproj = XMFLOAT4X4(); XMStoreFloat4x4(&mproj, proj); XMFLOAT3 v; v.x = (((2.0f * ptcursor.x) / pd3dsdBackBuffer->Width) - 1) / mproj._11; v.y = -(((2.0f * ptcursor.y) / pd3dsdBackBuffer->Height) - 1) / mproj._22; v.z = 1.0f; // Get the inverse view matrix XMMATRIX mWorldView = world * view; //XMVECTOR determin; XMMATRIX mInv = XMMatrixInverse(NULL, mWorldView); XMFLOAT4X4 m = XMFLOAT4X4(); XMStoreFloat4x4(&m, mInv); // Transform the screen space pick ray into 3D space XMFLOAT3 pickRayDir; pickRayDir.x = v.x * m._11 + v.y * m._21 + v.z * m._31; pickRayDir.y = v.x * m._12 + v.y * m._22 + v.z * m._32; pickRayDir.z = v.x * m._13 + v.y * m._23 + v.z * m._33; rayDir = XMLoadFloat3(&pickRayDir); XMFLOAT3 pickRayOrig; pickRayOrig.x = m._41; pickRayOrig.y = m._42; pickRayOrig.z = m._43; rayPos = XMLoadFloat3(&pickRayOrig); }
void InstancingAndCullingApp::BuildInstancedBuffer() { const int n = 5; mInstancedData.resize(n*n*n); float width = 200.0f; float height = 200.0f; float depth = 200.0f; float x = -0.5f*width; float y = -0.5f*height; float z = -0.5f*depth; float dx = width / (n-1); float dy = height / (n-1); float dz = depth / (n-1); for(int k = 0; k < n; ++k) { for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { // Position instanced along a 3D grid. mInstancedData[k*n*n + i*n + j].World = XMFLOAT4X4( 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, x+j*dx, y+i*dy, z+k*dz, 1.0f); // Random color. mInstancedData[k*n*n + i*n + j].Color.x = MathHelper::RandF(0.0f, 1.0f); mInstancedData[k*n*n + i*n + j].Color.y = MathHelper::RandF(0.0f, 1.0f); mInstancedData[k*n*n + i*n + j].Color.z = MathHelper::RandF(0.0f, 1.0f); mInstancedData[k*n*n + i*n + j].Color.w = 1.0f; } } } D3D11_BUFFER_DESC vbd; vbd.Usage = D3D11_USAGE_DYNAMIC; vbd.ByteWidth = sizeof(InstancedData) * mInstancedData.size(); vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER; vbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; vbd.MiscFlags = 0; vbd.StructureByteStride = 0; HR(md3dDevice->CreateBuffer(&vbd, 0, &mInstancedBuffer)); }
void Physics::exe_ob_create(uint32_t const _i_zad) { phys_par.no.wstaw(phys_par.pos.get_size()); phys_par.pos.push_back(XMFLOAT3(0.0f, 0.0f, 0.5f)); phys_par.v.push_back(XMFLOAT3(0.0f, 0.0f, 0.0f)); phys_par.mtx_world.push_back(XMFLOAT4X4()); XMStoreFloat4x4( &phys_par.mtx_world[phys_par.mtx_world.get_size()-1], XMMatrixIdentity() ); XMFLOAT3 _t[] = { XMFLOAT3(-1.0f, -1.0f, -1.0f), XMFLOAT3(-1.0f, 1.0f, -1.0f), XMFLOAT3(1.0f, 1.0f, -1.0f), XMFLOAT3(1.0f, -1.0f, -1.0f), XMFLOAT3(-1.0f, -1.0f, 1.0f), XMFLOAT3(-1.0f, 1.0f, 1.0f), XMFLOAT3(1.0f, 1.0f, 1.0f), XMFLOAT3(1.0f, -1.0f, 1.0f), }; phys_par.bound_box.push_back(_t, 8); }
void AnimationController::Interpolate( float dt ) { timeSinceStart += dt; Anim anim = *anims[currentAnim]; float animCurrentTime = fmod( timeSinceStart, anim.totalTime ); for( Bone* bone:anim.boneSet ) { XMMATRIX rotMat, scaleMat, translateMat; // Interpolate Rotation auto rotSetIt = anim.rotChannels.find( bone ); if( rotSetIt==anim.rotChannels.end() ) { rotMat = XMMatrixIdentity(); } else { keySet_t rotKeySet = rotSetIt->second; auto itLow = rotKeySet.lower_bound( animCurrentTime ); if( itLow==rotKeySet.begin() ) { itLow = rotKeySet.end(); } --itLow; auto itHigh = rotKeySet.upper_bound( animCurrentTime ); if( itHigh==rotKeySet.end() ) { itHigh = rotKeySet.begin(); } float factor = (animCurrentTime-itLow->first)/(itHigh->first-itLow->first); XMVECTOR low = XMLoadFloat4( &itLow->second ); XMVECTOR high = XMLoadFloat4( &itHigh->second ); XMVECTOR interp = XMQuaternionSlerp( low, high, factor ); XMVECTOR normalized = XMQuaternionNormalize( interp ); rotMat = XMMatrixRotationQuaternion( interp ); } // Interpolate Scale auto scaleSetIt = anim.scaleChannels.find( bone ); if( scaleSetIt==anim.scaleChannels.end() ) { scaleMat = XMMatrixIdentity(); } else { keySet_t scaleKeySet = scaleSetIt->second; auto itLow = scaleKeySet.lower_bound( animCurrentTime ); if( itLow==scaleKeySet.begin() ) { itLow = scaleKeySet.end(); } --itLow; auto itHigh = scaleKeySet.upper_bound( animCurrentTime ); if( itHigh==scaleKeySet.end() ) { itHigh = scaleKeySet.begin(); } float factor = (animCurrentTime-itLow->first)/(itHigh->first-itLow->first); XMFLOAT4 lowVec = itLow->second; XMFLOAT4 highVec = itHigh->second; scaleMat = XMMatrixScaling( lowVec.x+factor*(highVec.x-lowVec.x), lowVec.y+factor*(highVec.y-lowVec.y), lowVec.z+factor*(highVec.z-lowVec.z) ); } // Interpolate Position auto posSetIt = anim.posChannels.find( bone ); if( posSetIt==anim.posChannels.end() ) { translateMat = XMMatrixIdentity(); } else { keySet_t posKeySet = posSetIt->second; auto itLow = posKeySet.lower_bound( animCurrentTime ); if( itLow==posKeySet.begin() ) { itLow = posKeySet.end(); } --itLow; auto itHigh = posKeySet.upper_bound( animCurrentTime ); if( itHigh==posKeySet.end() ) { itHigh = posKeySet.begin(); } float factor = (animCurrentTime-itLow->first)/(itHigh->first-itLow->first); XMFLOAT4 lowVec = itLow->second; XMFLOAT4 highVec = itHigh->second; translateMat = XMMatrixTranslation( lowVec.x+factor*(highVec.x-lowVec.x), lowVec.y+factor*(highVec.y-lowVec.y), lowVec.z+factor*(highVec.z-lowVec.z) ); } // Conversion Matrix - this converts imported coords to DirectX XMMATRIX reflectX = XMMatrixReflect( XMLoadFloat3( &XMFLOAT3( 1.f, 0.f, 0.f ) ) ); XMMATRIX reflectY = XMMatrixReflect( XMLoadFloat3( &XMFLOAT3( 0.f, 1.f, 0.f ) ) ); XMMATRIX reflectZ = XMMatrixReflect( XMLoadFloat3( &XMFLOAT3( 0.f, 0.f, 1.f ) ) ); XMMATRIX rotX = XMMatrixRotationX( XM_PIDIV2 ); XMMATRIX rotY = XMMatrixRotationY( XM_PIDIV2 ); XMMATRIX rotZ = XMMatrixRotationZ( XM_PIDIV2 ); int foo = 17; //DELETEME XMMATRIX flip = XMLoadFloat4x4( &XMFLOAT4X4( 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f ) ); XMMATRIX finalMat = scaleMat * rotMat * translateMat; XMFLOAT4X4 transform; XMStoreFloat4x4( &transform, finalMat ); finalTransform[bone] = transform; } }
namespace ModelPipeline { RTTI_DEFINITIONS(SceneNode); const XMFLOAT4X4 SceneNode::IdentityMatrix = XMFLOAT4X4(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); SceneNode::SceneNode(const std::string& name) : mName(name), mParent(nullptr), mChildren(), mTransform(SceneNode::IdentityMatrix) { } SceneNode::SceneNode(const std::string& name, const XMFLOAT4X4& transform) : mName(name), mParent(nullptr), mChildren(), mTransform(transform) { } SceneNode::SceneNode() : mName(), mParent(nullptr), mChildren(), mTransform() { } const std::string& SceneNode::Name() const { return mName; } SceneNode* SceneNode::GetParentNode() { return mParent; } std::vector<SceneNode*>& SceneNode::Children() { return mChildren; } const XMFLOAT4X4& SceneNode::Transform() const { return mTransform; } XMMATRIX SceneNode::TransformMatrix() const { return XMLoadFloat4x4(&mTransform); } void SceneNode::SetParent(SceneNode* parent) { mParent = parent; } void SceneNode::SetTransform(XMFLOAT4X4& transform) { mTransform = transform; } void SceneNode::SetTransform(CXMMATRIX transform) { XMFLOAT4X4 t; XMStoreFloat4x4(&t, transform); SetTransform(t); } }