XMMATRIX Transform::GetTransformMatrix() { XMVECTOR scaleVector(m_Scale.AsXMVECTOR()); XMVECTOR rotationVector(m_Rotation.AsXMVECTOR()); XMVECTOR positionVector(m_Position.AsXMVECTOR()); return XMMatrixScalingFromVector(scaleVector) * XMMatrixRotationQuaternion(rotationVector) * XMMatrixTranslationFromVector(positionVector); }
// スケール、回転、移動行列 XMMATRIX SQTMatrix(const XMVECTOR& scale, const XMVECTOR& quat_rot, const XMVECTOR& trans) { return XMMatrixMultiply( XMMatrixMultiply( XMMatrixScalingFromVector(scale), XMMatrixRotationQuaternion(quat_rot)), XMMatrixTranslationFromVector(trans)); }
XMMATRIX Transform::createWorldMatrix() const { XMMATRIX world = XMMatrixIdentity(); world *= XMMatrixScalingFromVector(XMLoadFloat3(&scale)); world *= XMMatrixRotationQuaternion(XMLoadFloat4(&rotation)); world *= XMMatrixTranslationFromVector(XMLoadFloat3(&position)); if (parent != nullptr) world *= parent->createWorldMatrix(); return world; }
void EFighter::Init(ID3D11Device* device,World* w, XMFLOAT3 startPos, Mesh* m) { mesh=m; pos = XMFLOAT3(startPos.x, startPos.y, startPos.z); scale = XMFLOAT3(.25,.25,.25); active = false; //pos.y + 5; up = XMFLOAT3(0,1,0); right = XMFLOAT3(-1,0,0); #pragma region meshing XMVECTOR scaleVect= XMLoadFloat3(&scale); XMStoreFloat4x4(&mWorldNoTransl,XMMatrixIdentity()*XMMatrixScalingFromVector(scaleVect)); //XMStoreFloat4x4(&mWorldNoTransl,XMMatrixIdentity()); vertNum = mesh->numInd; D3D11_BUFFER_DESC vbd; vbd.Usage = D3D11_USAGE_IMMUTABLE; vbd.ByteWidth = sizeof(Vertex) * mesh->numVerts; vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER; vbd.CPUAccessFlags = 0; vbd.MiscFlags = 0; vbd.StructureByteStride = 0; D3D11_SUBRESOURCE_DATA vinitData; vinitData.pSysMem = mesh->vertices; HR(device->CreateBuffer(&vbd, &vinitData, &vertexBuffer)); D3D11_BUFFER_DESC ibd2; ibd2.Usage = D3D11_USAGE_IMMUTABLE; ibd2.ByteWidth = sizeof(UINT) * mesh->numInd; ibd2.BindFlags = D3D11_BIND_INDEX_BUFFER; ibd2.CPUAccessFlags = 0; ibd2.MiscFlags = 0; ibd2.StructureByteStride = 0; D3D11_SUBRESOURCE_DATA iinitData2; iinitData2.pSysMem = mesh->indices; HR(device->CreateBuffer(&ibd2, &iinitData2, &indexBuffer)); XMMATRIX I = XMMatrixIdentity(); XMStoreFloat4x4(&mWorld, I); mat.Ambient = XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f); mat.Diffuse = XMFLOAT4(0.77f, 0.77f, 1.0f, 1.0f); mat.Specular = XMFLOAT4(0.8f, 0.8f, 0.8f, 16.0f); #pragma endregion worldPTR = w; HR(D3DX11CreateShaderResourceViewFromFile(device,mesh->texturePath,0,0,&mDiffuseSRV,0)); }
void JF::Component::ColisionBox::Render() { // Declear) float blendFactors[] = { 0.0f, 0.0f, 0.0f, 0.0f }; // Get) auto* pTransform = GetOwner()->GetComponent<JF::Component::Transform>(); // Check) RETURN_IF(pTransform == nullptr, ); // Set Layout And Topology gRENDERER->DeviceContext()->IASetInputLayout(InputLayouts::PosColor); gRENDERER->DeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); // Set VertexBuffer And IndexBuffer UINT stride = sizeof(JF::Vertex::PosColor); UINT offset = 0; gRENDERER->DeviceContext()->IASetVertexBuffers(0, 1, &m_VertBuff, &stride, &offset); gRENDERER->DeviceContext()->IASetIndexBuffer(m_IndexBuff, DXGI_FORMAT_R32_UINT, 0); // worldViewProj 행렬을 구한다. XMFLOAT3 rPosition = XMFLOAT3(pTransform->GetPosition().x + m_Center.x, pTransform->GetPosition().y + m_Center.y, pTransform->GetPosition().z + m_Center.z); XMFLOAT3 rScale = XMFLOAT3(pTransform->GetScale().x * m_Size.x, pTransform->GetScale().y * m_Size.y, pTransform->GetScale().z * m_Size.z); XMFLOAT4 rRotation = pTransform->GetRotation(); XMMATRIX scl, rot, tsl; scl = XMMatrixScalingFromVector(XMLoadFloat3(&rScale)); rot = XMMatrixRotationQuaternion(XMLoadFloat4(&rRotation)); tsl = XMMatrixTranslationFromVector(XMLoadFloat3(&rPosition)); XMMATRIX world = scl*rot*tsl; XMMATRIX view = Camera::g_pMainCamera->GetView(); XMMATRIX proj = Camera::g_pMainCamera->GetProj(); XMMATRIX worldViewProj = world * view * proj; Effects::SimpleFX->SetWorldViewProj(worldViewProj); // 노말맵이 있는지에따라 FX Tech 설정 변경. ID3DX11EffectTechnique* Tech; Tech = Effects::SimpleFX->ColorTech; D3DX11_TECHNIQUE_DESC techDesc; Tech->GetDesc(&techDesc); for (UINT p = 0; p < techDesc.Passes; ++p) { Tech->GetPassByIndex(p)->Apply(0, gRENDERER->DeviceContext()); gRENDERER->DeviceContext()->DrawIndexed(m_indexCnt, 0, 0); } // 기본 랜더상태로 복원한다. gRENDERER->DeviceContext()->RSSetState(0); gRENDERER->DeviceContext()->OMSetBlendState(0, blendFactors, 0xffffffff); }
XMFLOAT4X4& ITransform::GetTransformMatrix() { XMMATRIX scl, rot, tsl; scl = XMMatrixScalingFromVector(XMLoadFloat3(&m_vScale)); rot = XMMatrixRotationRollPitchYawFromVector(XMLoadFloat3(&m_vRotation)); tsl = XMMatrixTranslationFromVector(XMLoadFloat3(&m_vPosition)); // worldMat = S*R*T XMStoreFloat4x4(&m_mTransform, (scl*rot*tsl)); return m_mTransform; }
XMFLOAT4X4 Transform::RecalculateWorldMatrix() { //TODO: figure out a better way to handle rotaions if (!GetIsDirty()) return worldMatrix;//Dont know if I want to keep it. XMMATRIX allignedWorldMatrix = XMLoadFloat4x4(&worldMatrix); if (parent == nullptr) { XMMATRIX calculatedWorldMatrix = XMMatrixScalingFromVector(XMLoadFloat3(&scale)) * //XMMatrixRotationRollPitchYawFromVector(XMLoadFloat3(&rotation)) * //XMMatrixRotationX(rotation.x) * XMMatrixRotationY(rotation.y) * XMMatrixRotationZ(rotation.z) * XMMatrixRotationQuaternion(XMQuaternionRotationRollPitchYawFromVector(XMLoadFloat3(&rotation))) * XMMatrixTranslationFromVector(XMLoadFloat3(&position)); XMStoreFloat4x4(&worldMatrix, XMMatrixTranspose(calculatedWorldMatrix)); } else { XMMATRIX calculatedWorldMatrix = XMMatrixScalingFromVector(XMLoadFloat3(&scale)) * //XMMatrixRotationRollPitchYawFromVector(XMLoadFloat3(&rotation)) * XMMatrixRotationQuaternion(XMQuaternionRotationRollPitchYawFromVector(XMLoadFloat3(&rotation))) * XMMatrixTranslationFromVector(XMLoadFloat3(&position)); XMStoreFloat4x4(&worldMatrix, XMMatrixTranspose( XMMatrixMultiply(XMMatrixTranspose(XMLoadFloat4x4(&parent->GetWorldMatrix())), calculatedWorldMatrix))); } return worldMatrix; }
void make_worldmatrix(QuaternionTransform const& qt, XMFLOAT4X4 &mat) { XMVECTOR trans_vec = XMLoadFloat3(&qt.pos); XMMATRIX trans_mat = XMMatrixTranslationFromVector(trans_vec); XMVECTOR scale_vec = XMLoadFloat3(&qt.scale); XMMATRIX scale_mat = XMMatrixScalingFromVector(scale_vec); XMVECTOR rotat_vec = XMLoadFloat4(&qt.quat); XMMATRIX rotat_mat = XMMatrixRotationQuaternion(rotat_vec); XMMATRIX world = scale_mat * rotat_mat * trans_mat; XMStoreFloat4x4(&mat, world); }
BoxApp::BoxApp(HINSTANCE hInstance) : D3DApp(hInstance), mFX(0), mTech(0), mfxWorldViewProj(0), mInputLayout(0), mTheta(1.5f*MathHelper::Pi), mPhi(0.25f*MathHelper::Pi), mRadius(5.0f) { mMainWndCaption = L"Box Demo"; mLastMousePos.x = 0; mLastMousePos.y = 0; XMMATRIX I = XMMatrixIdentity(); XMStoreFloat4x4(&mWorld, XMMatrixScalingFromVector(XMVectorSet(0.3f, 0.3f, 0.3f, 1.0f))); XMStoreFloat4x4(&mView, I); XMStoreFloat4x4(&mProj, I); mEnable4xMsaa = true; }
XMFLOAT4X4 gameObject::CalculateWorldMatrix() { XMMATRIX scale, rot, trans, world; scale = XMMatrixScalingFromVector(XMLoadFloat3(&m_scaleVector)); rot = XMMatrixRotationRollPitchYawFromVector(XMLoadFloat3(&m_rotationVector)); trans = XMMatrixTranslationFromVector(XMLoadFloat3(&m_positionVector)); world = scale* rot* trans; XMStoreFloat4x4(&m_matScale, scale); XMStoreFloat4x4(&m_matRot, rot); XMStoreFloat4x4(&m_matTranslation, trans); XMStoreFloat4x4(&m_matTransform, world); return m_matTransform; }
void Transform::CacheTransform() { XMMATRIX transform; // Scale -> Rotate -> Translate transform = XMMatrixTranslationFromVector(XMLoadFloat3(&m_position))* m_rotation.GetMatrixFormXM() * XMMatrixScalingFromVector(XMLoadFloat3(&m_scale)); if (m_bMirrorX) transform *= XMLoadFloat4x4(&s_mirrorXMat); if (m_bMirrorY) transform *= XMLoadFloat4x4(&s_mirrorYMat); if (m_bMirrorZ) transform *= XMLoadFloat4x4(&s_mirrorZMat); XMStoreFloat4x4(&m_transformMatrix, transform); }
VOID DebugDraw::DrawCubeQuery( const XMFLOAT3& Center, const XMFLOAT3& HalfSize ) { // Index buffer data for a cube (using a quad list). static const WORD pIndexData[] = { 3, 2, 0, 1, 1, 0, 4, 5, 3, 1, 5, 7, 2, 3, 7, 6, 0, 2, 6, 4, 5, 4, 6, 7 }; static const XMFLOAT3 pVertexData[] = { XMFLOAT3( -1, -1, -1 ), XMFLOAT3( 1, -1, -1 ), XMFLOAT3( -1, -1, 1 ), XMFLOAT3( 1, -1, 1 ), XMFLOAT3( -1, 1, -1 ), XMFLOAT3( 1, 1, -1 ), XMFLOAT3( -1, 1, 1 ), XMFLOAT3( 1, 1, 1 ) }; XMMATRIX matTranslate = XMMatrixTranslationFromVector( XMLoadFloat3( &Center ) ); XMMATRIX matScale = XMMatrixScalingFromVector( XMLoadFloat3( &HalfSize ) ); XMMATRIX matTransform = matScale * matTranslate * g_matViewProjection; SimpleShaders::SetDeclPos(); SimpleShaders::BeginShader_Transformed_DepthOnly( matTransform ); g_pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID ); g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); g_pd3dDevice->DrawIndexedPrimitiveUP( D3DPT_QUADLIST, 0, 8, 6, pIndexData, D3DFMT_INDEX16, pVertexData, sizeof( XMFLOAT3 ) ); SimpleShaders::EndShader(); }
static Matrix scaling(const Vector3& v) { return static_cast<Matrix>(XMMatrixScalingFromVector(v)); }
void XM_CALLCONV PrimitveDrawer::DrawCube(FXMVECTOR HalfExtend, FXMMATRIX WorldTransform, GXMVECTOR Color) { XMMATRIX world = XMMatrixScalingFromVector(HalfExtend) * WorldTransform; m_pCube->Draw(world, ViewMatrix, ProjectionMatrix, Color); }