// Builds and writes constant buffers from scratch to the proper slots for // this frame resource. void FrameResource::WriteConstantBuffers(D3D12_VIEWPORT* pViewport, Camera* pSceneCamera, Camera lightCams[NumLights], LightState lights[NumLights]) { ConstantBuffer sceneConsts = {}; ConstantBuffer shadowConsts = {}; // Scale down the world a bit. ::XMStoreFloat4x4(&sceneConsts.model, XMMatrixScaling(0.1f, 0.1f, 0.1f)); ::XMStoreFloat4x4(&shadowConsts.model, XMMatrixScaling(0.1f, 0.1f, 0.1f)); // The scene pass is drawn from the camera. pSceneCamera->Get3DViewProjMatrices(&sceneConsts.view, &sceneConsts.projection, 90.0f, pViewport->Width, pViewport->Height); // The light pass is drawn from the first light. lightCams[0].Get3DViewProjMatrices(&shadowConsts.view, &shadowConsts.projection, 90.0f, pViewport->Width, pViewport->Height); for (int i = 0; i < NumLights; i++) { memcpy(&sceneConsts.lights[i], &lights[i], sizeof(LightState)); memcpy(&shadowConsts.lights[i], &lights[i], sizeof(LightState)); } // The shadow pass won't sample the shadow map, but rather write to it. shadowConsts.sampleShadowMap = FALSE; // The scene pass samples the shadow map. sceneConsts.sampleShadowMap = TRUE; shadowConsts.ambientColor = sceneConsts.ambientColor = { 0.1f, 0.2f, 0.3f, 1.0f }; memcpy(mp_sceneConstantBufferWO, &sceneConsts, sizeof(ConstantBuffer)); memcpy(mp_shadowConstantBufferWO, &shadowConsts, sizeof(ConstantBuffer)); }
void Entity::Draw2D(ID3DX11EffectTechnique* activeTech, ID3D11DeviceContext* context, UINT pass, const Camera& camera, XMMATRIX& ortho) { XMMATRIX world = XMLoadFloat4x4(&mWorld); XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world); XMMATRIX worldViewProj = world*ortho; Effects::BasicFX->SetWorld(world); Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose); Effects::BasicFX->SetWorldViewProj(worldViewProj); if (!useTexTrans){ Effects::BasicFX->SetTexTransform(XMMatrixScaling(origTexScale.x, origTexScale.y, origTexScale.z)); } if (mBasicTexTrans) { XMMATRIX Scale; mFlipTexture ? Scale = XMMatrixScaling(-origTexScale.x, origTexScale.y, origTexScale.z) : Scale = XMMatrixScaling(origTexScale.x, origTexScale.y, origTexScale.z); Effects::BasicFX->SetTexTransform(XMMatrixTranslation(texTrans.x, texTrans.y, texTrans.z)*Scale); } if (mUseAnimation) { XMMATRIX Scale; mAnim->Flipped() ? Scale = XMMatrixScaling(-origTexScale.x, origTexScale.y, origTexScale.z) : Scale = XMMatrixScaling(origTexScale.x, origTexScale.y, origTexScale.z); Effects::BasicFX->SetTexTransform(XMMatrixTranslation(mAnim->GetX(), mAnim->GetY(), texTrans.z)*Scale); } Effects::BasicFX->SetMaterial(mMat); Effects::BasicFX->SetDiffuseMap(mTexSRV); activeTech->GetPassByIndex(pass)->Apply(0, context); context->DrawIndexed(mIndexCount, mIndexOffset, mVertexOffset); }
void Game::UpdateScene() { floorWorld = XMMatrixIdentity(); scale = XMMatrixScaling(250.0f, 1.0f, 250.0f); translation = XMMatrixTranslation(0.0f, 0.0f, 0.0f); floorWorld = scale*translation; //Keep the cubes rotating rotSpeed += .0005f; if (rotSpeed > 6.26f) rotSpeed = 0.0f; //When used, these matrices will rotate objects rotateAboutX = XMMatrixRotationAxis(rotXAxis, -rotSpeed); rotateAboutY = XMMatrixRotationAxis(rotYAxis, -rotSpeed); rotateAboutZ = XMMatrixRotationAxis(rotZAxis, -rotSpeed); scale = XMMatrixScaling(2, scaleY, 2); //Reset cubes locations cube1World = XMMatrixIdentity(); cube2World = XMMatrixIdentity(); //When used, these matrices will set an objects position translation = XMMatrixTranslation(-5.0f, 2.0f, 0.0f); //Set cube1's world space using the transformations cube1World = rotateAboutX * translation * scale; //When used, these matrices will set an objects position translation = XMMatrixTranslation(5.0f, 2.0f, 0.0f); //Set cube2's world space matrix cube2World = rotateAboutY * translation * scale; meshWorld = XMMatrixIdentity(); travelSpeed += 0.0003f; //Setting meshes scale, translation and rotation scale = XMMatrixScaling(0.2f,0.2f,0.2f); translation = XMMatrixTranslation(-travelSpeed, 0.0f, 0.0f); rotation = XMMatrixRotationRollPitchYaw(0, XMConvertToRadians(180), 0); meshWorld = translation * rotation * scale; //Reset sphereWorld sphereWorld = XMMatrixIdentity(); //Define sphereWorld's world space matrix scale = XMMatrixScaling(5.0f, 5.0f, 5.0f); //Make sure the sphere is always centered around camera translation = XMMatrixTranslation(XMVectorGetX(camPosition), XMVectorGetY(camPosition), XMVectorGetZ(camPosition)); //Set sphereWorld's world space using the transformations sphereWorld = scale * translation; }
void TextureWave::BuildParamaters() { m_constBufferPerObj.Create(m_d3dDevice, VertexShaer, 0); m_constMaterial.Create(m_d3dDevice, PixelShader, 0); m_constBufferPerFrame.Create(m_d3dDevice, PixelShader, 1); m_constPixelParam.Create(m_d3dDevice, PixelShader, 2); m_landMat.Ambient = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f); m_landMat.Diffuse = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f); m_landMat.Specular = XMFLOAT4(0.2f, 0.2f, 0.2f, 16.0f); m_waveMat.Ambient = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f); m_waveMat.Diffuse = XMFLOAT4(1.0f, 1.0f, 1.0f, 0.5f); m_waveMat.Specular = XMFLOAT4(0.8f, 0.8f, 0.8f, 32.0f); m_boxMat.Ambient = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f); m_boxMat.Diffuse = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f); m_boxMat.Specular = XMFLOAT4(0.4f, 0.4f, 0.4f, 16.0f); for (UINT i = 0; i < 4; ++i) { m_blendFactor[i] = 0.0f; } m_waveSpeed = 0.0002f; m_grassTextureMatrix = XMMatrixScaling(5.0f, 5.0f, 1.0f); texCoords[0] = { 0.0f, 0.0f }; texCoords[1] = { 1.0f, 0.0f }; texCoords[2] = { 0.0f, 1.0f }; texCoords[3] = { 1.0f, 1.0f }; m_constBufferPerFrameReflect.GlobalLight[0].Ambient = XMFLOAT4(0.2f, 0.2f, 0.2f, 1.0f); m_constBufferPerFrameReflect.GlobalLight[0].Diffuse = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f); m_constBufferPerFrameReflect.GlobalLight[0].Specular = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f); m_constBufferPerFrameReflect.GlobalLight[0].Direction = XMFLOAT3(0.57735f, -0.57735f, 0.57735f); m_constBufferPerFrameReflect.GlobalLight[1].Ambient = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f); m_constBufferPerFrameReflect.GlobalLight[1].Diffuse = XMFLOAT4(0.20f, 0.20f, 0.20f, 1.0f); m_constBufferPerFrameReflect.GlobalLight[1].Specular = XMFLOAT4(0.25f, 0.25f, 0.25f, 1.0f); m_constBufferPerFrameReflect.GlobalLight[1].Direction = XMFLOAT3(-0.57735f, -0.57735f, 0.57735f); m_constBufferPerFrameReflect.GlobalLight[2].Ambient = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f); m_constBufferPerFrameReflect.GlobalLight[2].Diffuse = XMFLOAT4(0.2f, 0.2f, 0.2f, 1.0f); m_constBufferPerFrameReflect.GlobalLight[2].Specular = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f); m_constBufferPerFrameReflect.GlobalLight[2].Direction = XMFLOAT3(0.0f, -0.707f, -0.707f); m_boxWorldMatrix = XMMatrixScaling(5.0f, 5.0f, 5.0f); }
void Entity::Draw(ID3DX11EffectTechnique* activeTech, ID3D11DeviceContext* context, UINT pass, const Camera& camera, float dt) { XMMATRIX world = XMLoadFloat4x4(&mWorld); XMMATRIX shad = XMLoadFloat4x4(&mShadowTrans); XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world); XMMATRIX worldViewProj = world*camera.View()*camera.Proj(); Effects::BasicFX->SetWorld(world); Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose); Effects::BasicFX->SetWorldViewProj(worldViewProj); Effects::BasicFX->SetShadowTransform(world*shad); if (!useTexTrans){ Effects::BasicFX->SetTexTransform(XMMatrixScaling(origTexScale.x, origTexScale.y, origTexScale.z)); } if (useTexTrans) { Effects::BasicFX->SetTexTransform(XMMatrixTranslation(texTrans.x, texTrans.y, texTrans.z)*XMMatrixScaling(origTexScale.x, origTexScale.y, origTexScale.z)); texTrans.x += dt*texTransMult.x; texTrans.y += dt*texTransMult.y; texTrans.z += dt*texTransMult.z; } if (mBasicTexTrans) { XMMATRIX Scale; mFlipTexture ? Scale = XMMatrixScaling(-origTexScale.x, origTexScale.y, origTexScale.z) : Scale = XMMatrixScaling(origTexScale.x, origTexScale.y, origTexScale.z); Effects::BasicFX->SetTexTransform(XMMatrixTranslation(texTrans.x, texTrans.y, texTrans.z)*Scale); } if (mUseAnimation) { XMMATRIX Scale; mAnim->Flipped() ? Scale = XMMatrixScaling(-origTexScale.x, origTexScale.y, origTexScale.z) : Scale = XMMatrixScaling(origTexScale.x, origTexScale.y, origTexScale.z); Effects::BasicFX->SetTexTransform(XMMatrixTranslation(mAnim->GetX(), mAnim->GetY(), texTrans.z)*Scale); } Effects::BasicFX->SetMaterial(mMat); Effects::BasicFX->SetDiffuseMap(mTexSRV); if (mExplode) { ID3DX11EffectTechnique* ExploadTech; ExploadTech = Effects::BasicFX->ExplosionTech; Effects::BasicFX->SetDT(explosionDist); ExploadTech->GetPassByIndex(pass)->Apply(0, context); } else { activeTech->GetPassByIndex(pass)->Apply(0, context); } mBackFaceCull ? context->RSSetState(0) : context->RSSetState(RenderStates::NoCullRS); context->DrawIndexed(mIndexCount, mIndexOffset, mVertexOffset); }
BlendApp::BlendApp(HINSTANCE hInstance) : D3DApp(hInstance), mLandVB(0), mLandIB(0), mWavesVB(0), mWavesIB(0), mBoxVB(0), mBoxIB(0), mGrassMapSRV(0), mWavesMapSRV(0), mBoxMapSRV(0), mWaterTexOffset(0.0f, 0.0f), mEyePosW(0.0f, 0.0f, 0.0f), mLandIndexCount(0), mRenderOptions(RenderOptions::TexturesAndFog), mTheta(1.3f*MathHelper::Pi), mPhi(0.4f*MathHelper::Pi), mRadius(80.0f) { mMainWndCaption = L"Blend Demo"; mEnable4xMsaa = false; mLastMousePos.x = 0; mLastMousePos.y = 0; XMMATRIX I = XMMatrixIdentity(); XMStoreFloat4x4(&mLandWorld, I); XMStoreFloat4x4(&mWavesWorld, I); XMStoreFloat4x4(&mView, I); XMStoreFloat4x4(&mProj, I); XMMATRIX boxScale = XMMatrixScaling(15.0f, 15.0f, 15.0f); XMMATRIX boxOffset = XMMatrixTranslation(8.0f, 5.0f, -15.0f); XMStoreFloat4x4(&mBoxWorld, boxScale*boxOffset); XMMATRIX grassTexScale = XMMatrixScaling(5.0f, 5.0f, 0.0f); XMStoreFloat4x4(&mGrassTexTransform, grassTexScale); mDirLights.Ambient = XMFLOAT4(0.2f, 0.2f, 0.2f, 1.0f); mDirLights.Diffuse = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f); mDirLights.Specular = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f); mDirLights.Direction = XMFLOAT3(0.57735f, -0.57735f, 0.57735f); mLandMat.Ambient = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f); mLandMat.Diffuse = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f); mLandMat.Specular = XMFLOAT4(0.2f, 0.2f, 0.2f, 16.0f); mWavesMat.Ambient = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f); mWavesMat.Diffuse = XMFLOAT4(1.0f, 1.0f, 1.0f, 0.5f); mWavesMat.Specular = XMFLOAT4(0.8f, 0.8f, 0.8f, 32.0f); mBoxMat.Ambient = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f); mBoxMat.Diffuse = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f); mBoxMat.Specular = XMFLOAT4(0.4f, 0.4f, 0.4f, 16.0f); mConstStruct.gDirLights = mDirLights; mConstStruct.gFogColor = XMFLOAT4(0.75f, 0.75f, 0.75f, 1.0f); mConstStruct.gFogStart = 15.0f; mConstStruct.gFogRange = 175.0f; mConstStruct.gMaterial = mBoxMat; }
void Application::Update(double time) { // Update our time static float t = 0.0f; if (_driverType == D3D_DRIVER_TYPE_REFERENCE) { t += (float)XM_PI * 0.0125f; } else { static DWORD dwTimeStart = 0; DWORD dwTimeCur = GetTickCount(); if (dwTimeStart == 0) dwTimeStart = dwTimeCur; t = (dwTimeCur - dwTimeStart) / 1000.0f; } //XMStoreFloat4x4(&_view, XMMatrixLookAtLH(Eye, At, Up)); // update the camera XMStoreFloat4x4(&_view, XMMatrixLookAtLH(_cam.getEyeVector(), _cam.getAtVector(), _cam.getUpVector())); // Animate the cube XMMATRIX _rotation1, _rotation2, _scale1, _scale2, _translation1, _translation2, _final1, _final2; _rotation1 = XMMatrixRotationY(-t); _rotation2 = XMMatrixRotationY(t); _translation1 = XMMatrixTranslation(0.0f, 0.0f, 0.0f); _translation2 = XMMatrixTranslation(5.0f, 0.0f, 0.0f); _scale1 = XMMatrixScaling(1, 1, 1); _scale2 = XMMatrixScaling(.5, .5, .5); _final1 = _rotation1 * _translation1 * _scale1; _final2 = _translation2 * _rotation2 * _scale2; XMStoreFloat4x4(&_cube1, _final1); XMStoreFloat4x4(&_cube2, _final2); _cubbe1.SetRotation(t, t, t); _cubbe1.SetScale(1, 1, 1); _cubbe1.SetTranslation(.0f, .0f, .0f); _cubbe2.SetRotation(t, t, t); _cubbe2.SetScale(0.5f, 0.5f, 1); _cubbe2.SetTranslation(.0f, 2.0f, 2.0f); _cubbe1.Update(t); _cubbe2.Update(-t); }
void RenderingGame::update_stencil_material() { MaterialDeferredStencil* m = m_stencil_material->As<MaterialDeferredStencil>(); LightPoint* l = m_point_light->As<LightPoint>(); float r = l->radius(); XMMATRIX world = XMMatrixScaling(r, r, r) * XMMatrixTranslationFromVector(l->positionv()); m->WVP() << world * m_camera->view_projection(); }
///////////////**************new**************//////////////////// void UpdateScene() { //Keep the cubes rotating rot += .0005f; if(rot > 6.26f) rot = 0.0f; //Reset cube1World cube1World = XMMatrixIdentity(); //Define cube1's world space matrix //Exercise 1. Orbit the first cube around a different axis. XMVECTOR rotaxis = XMVectorSet(1.0f, 0.5f, 0.0f, 0.0f); Rotation = XMMatrixRotationAxis( rotaxis, rot); Translation = XMMatrixTranslation( 4.0f, 0.0f, 0.0f ); //Set cube1's world space using the transformations cube1World = Translation* Rotation; //Reset cube2World cube2World = XMMatrixIdentity(); //Define cube2's world space matrix Rotation = XMMatrixRotationAxis( rotaxis, -rot); Scale = XMMatrixScaling( 1.3f, 1.3f, 1.3f ); //Set cube2's world space matrix cube2World = Rotation * Scale; //Exercise 2.Play with the different transformations, and try to order them differently when multiplying them together, // to see different effects. //cube2World = Scale*Rotation; }
void DXBox::DrawBox(ID3D11DeviceContext* md3dImmediateContext, ID3DX11EffectTechnique* activeTech, DX11Camera mCam) { //Perform matrix operations for stored scale and position XMMATRIX mBoxRotation = XMMatrixRotationRollPitchYaw(mRotation.GetZ(), mRotation.GetY(), mRotation.GetX()); XMMATRIX mBoxScale = XMMatrixScaling(mScale.GetX(), mScale.GetY(), mScale.GetZ()); XMMATRIX mBoxPosition = XMMatrixTranslation(mPosition.GetX(), mPosition.GetY(), mPosition.GetZ()); XMStoreFloat4x4(&mBoxWorld, XMMatrixMultiply(XMMatrixMultiply(mBoxRotation,mBoxScale), mBoxPosition)); UINT stride = sizeof(Vertex::Basic32); UINT offset = 0; md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset); md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0); // Draw the box. XMMATRIX world = XMLoadFloat4x4(&mBoxWorld); XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world); XMMATRIX worldViewProj = world * mCam.View() * mCam.Proj(); Effects::BasicFX->SetWorld(world); Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose); Effects::BasicFX->SetWorldViewProj(worldViewProj); Effects::BasicFX->SetTexTransform(XMLoadFloat4x4(&mTexTransform)); Effects::BasicFX->SetMaterial(mBoxMat); Effects::BasicFX->SetDiffuseMap(boxDiffuseTexture); activeTech->GetPassByIndex(0)->Apply(0, md3dImmediateContext); md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset); }
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; }
void glScalef (GLfloat x, GLfloat y, GLfloat z) { XMMATRIX mat = XMMatrixScaling(x, y, z); current_matrix->stack[current_matrix->stackdepth] = mat * current_matrix->stack[current_matrix->stackdepth]; // dirty the matrix current_matrix->dirty = 1; }
void Transform::UpdateCBuffer() { //updatesubresource med den nya transformData XMMATRIX tempWorld = XMMatrixIdentity(); XMMATRIX tempScale = XMMatrixIdentity(); XMMATRIX tempRotation = XMMatrixIdentity(); XMMATRIX tempPosition = XMMatrixIdentity(); tempScale = XMMatrixScaling(transformData.scale.x, transformData.scale.y, transformData.scale.z); //XMMatrixRotationQuaternion använd en quaternion istället! cool stuff, sen bör det funka //transformData.pos.z = transformData.pos.z * -1.0f; //transformData.rot.x = transformData.rot.x * -1.0f; //transformData.rot.y = transformData.rot.y * -1.0f; XMVECTOR rotationQuat = XMVectorSet(transformData.rot.x, transformData.rot.y, transformData.rot.z, transformData.rot.w); tempRotation = XMMatrixRotationQuaternion(rotationQuat); tempPosition = XMMatrixTranslation(transformData.pos.x, transformData.pos.y, transformData.pos.z); tempWorld = tempRotation * tempScale * tempPosition; if (parent != nullptr) { parent->UpdateCBuffer(); XMMATRIX parentWorld = XMLoadFloat4x4(&parent->transformCBufferData.world); tempWorld = tempWorld /** parentWorld*/; } XMStoreFloat4x4(&transformCBufferData.world, XMMatrixTranspose(tempWorld)); //transformdata ligger på plats 0, material på 1, osv gDeviceContext->UpdateSubresource(transformCBuffer, 0, NULL, &transformCBufferData.world, 0, 0); //skapa en separat struct för transformdata som ska in i shadern, world osv gDeviceContext->VSSetConstantBuffers(0, 1, &transformCBuffer); }
void Entity::ScaleZ(float scale) { //Progress gets offset on the X depending on the currProgress XMMATRIX trans = XMMatrixTranslation(mWorld.m[3][0], mWorld.m[3][1], mWorld.m[3][2] - (mDepth / 2 - (mDepth / 2 * currProgress))); // ORIGINAL TRANSLATION XMMATRIX scaling = XMMatrixScaling(1.0f, 1.0f, scale); XMStoreFloat4x4(&mWorld, scaling * trans); //Scaled Then sent Back To Original Position; }
void SpotLight::Initialize(const char *fileName, const DirectX::XMFLOAT3 *_diffuseColor, const DirectX::XMFLOAT3 *_ambientColor, const DirectX::XMFLOAT3 *_specularColor, float _specularPower, float _specularIntensisty, float _cutoff, float _exponent, const DirectX::XMFLOAT3 *_attenuation, float _radius, bool _isEnabled) { cBufferData.spotLight.enabled = _isEnabled; cBufferData.spotLight.diffuseColor = *_diffuseColor; cBufferData.spotLight.ambientColor = *_ambientColor; cBufferData.spotLight.specularColor = *_specularColor; cBufferData.spotLight.specularPower = _specularPower; cBufferData.spotLight.specularIntensity = _specularIntensisty; cBufferData.spotLight.exponent = _exponent; cBufferData.spotLight.cutoff = _cutoff; LoadModel(fileName); cBufferData.spotLight.attenuation = *_attenuation; float adjacent = cBufferData.spotLight.range = _radius; float radAngle = acos(cBufferData.spotLight.cutoff); float tanr = tan(radAngle); float opposite = tanr * adjacent; XMMATRIX mat = XMMatrixScaling( opposite, opposite, adjacent); renderShape->SetWorldMatrix(((XMFLOAT4X4 *)&mat)); cBuffer.Release(); D3D11_BUFFER_DESC bd; ZeroMemory( &bd, sizeof(bd) ); bd.Usage = D3D11_USAGE_DYNAMIC; bd.ByteWidth = sizeof(cBufferData); bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; HR(Renderer::theDevicePtr->CreateBuffer(&bd, nullptr, &cBuffer)); }
bool IcePatchViewModel::RenderEntity(ID3D11DeviceContext* deviceContext, XMFLOAT4X4 viewMatrix, XMFLOAT4X4 projectionMatrix, ColorShader* colorShader, TextureShader* textureShader, IcePatchObstacle* entity) { //writeTextToConsole(L"IcePatchViewModel::RenderEntity"); if(!textureShader) return false; //we were not provided with a shader XMFLOAT3 positionVector = entity->getPosition(); positionVector.z += 0.01f; positionVector.x -= 1.5f; XMFLOAT4X4 worldMatrix; XMStoreFloat4x4(&worldMatrix, XMLoadFloat4x4( &GetOrientation())); //SNOWFIELD MODEL RENDER XMFLOAT4X4 snowFieldMatrix; XMStoreFloat4x4(&snowFieldMatrix, XMLoadFloat4x4( &worldMatrix) * XMMatrixScaling(3.0f, entity->getLength(), 0.0f) * XMMatrixTranslationFromVector( XMLoadFloat3( &positionVector ))); icePatchVertexModel->Render(deviceContext); bool result = textureShader->Render(deviceContext, icePatchVertexModel->GetIndexCount(), snowFieldMatrix, viewMatrix, projectionMatrix, icePatchTexture->GetTexture()); //get the texture to render return result; }
void SceneNode::execute(XMMATRIX *world, XMMATRIX* view, XMMATRIX* projection) { // the local_world matrix will be used to calc the local transformations for this node XMMATRIX local_world = XMMatrixIdentity(); local_world = XMMatrixRotationX(XMConvertToRadians(m_xangle)); local_world *= XMMatrixRotationY(XMConvertToRadians(m_yangle)); local_world *= XMMatrixRotationZ(XMConvertToRadians(m_zangle)); local_world *= XMMatrixScaling(m_scale, m_scale, m_scale); local_world *= XMMatrixTranslation(m_x, m_y, m_z); // the local matrix is multiplied by the passed in world matrix that contains the concatenated // transformations of all parent nodes so that this nodes transformations are relative to those local_world *= *world; // only draw if there is a model attached if (m_p_model) m_p_model->draw(world, view, projection); // traverse all child nodes, passing in the concatenated world matrix for (int i = 0; i< m_children.size(); i++) { m_children[i]->execute(&local_world, view, projection); } }
HRESULT CALLBACK OnD3D11DeviceCreated(_In_ ID3D11Device* pd3dDevice, _In_ const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, _In_opt_ void* pUserContext) { HRESULT hr = S_OK; // 초기화 코드 작성... CompileShader::Create(&g_shader, L"Shaders\\lightShader.fx"); hr = g_shader->CreateTextureFromFile(L"Textures\\grass.jpg"); LoaderObj loader; //g_mesh = loader.BuildCube(); g_mesh = loader.BuildMeshFromFile(L"Models\\ground.obj"); g_meshLight = loader.BuildMeshFromFile(L"Models\\ground.obj"); XMMATRIX mscale = XMMatrixScaling(1.0f, 1.0f, 1.0f); XMMATRIX mtrans = XMMatrixTranslation(0.0f, 0.0f, 0.0f); XMMATRIX world = mscale * mtrans; XMFLOAT4X4 fworld; //1. XMMATRIX -> FLOAT4X4 XMStoreFloat4x4(&fworld, world); //2. FLOAT4X4 -> XMMATRIX //world = XMLoadFloat4x4(&fworld); g_mesh->setWorld(fworld); return S_OK; }
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); }
void ModelLightingClass::ModelMatrix(XMMATRIX& p_out) { XMMATRIX trans = XMMatrixTranslation(Position.x, Position.y, Position.z); XMMATRIX rot = XMMatrixRotationRollPitchYaw(Rotation.x, Rotation.y, Rotation.z ); XMMATRIX scale = XMMatrixScaling(Scale.x, Scale.y, Scale.z); p_out = scale * rot * trans; }
void Enemies::createEnemy(int model, FLOAT x1, FLOAT y1, FLOAT z1, FLOAT x2, FLOAT y2, FLOAT z2, FLOAT x3, FLOAT y3, FLOAT z3, FLOAT x4, FLOAT y4, FLOAT z4, FLOAT scale, int speed, int collisionstype) { Enemy* newEnemy; newEnemy = new Enemy(); XMMATRIX modelScale = XMMatrixScaling(scale, scale, -scale); XMMATRIX modelRot = XMMatrixRotationY(0); XMMATRIX modelOffset = XMMatrixTranslation(x1, y1, z1); newEnemy->setModelScale(modelScale); newEnemy->setModelRot(modelRot); newEnemy->setModelOffset(modelOffset); newEnemy->SetPositionOne(x1, y1, z1); newEnemy->SetPositionTwo(x2, y2, z2); newEnemy->SetPositionThree(x3, y3, z3); newEnemy->SetPositionFour(x4, y4, z4); if (model == simpleEnemy) { anEnemy = mSimpleEnemy; } else if (model == tractor) { anEnemy = mTractor; } newEnemy->setModel(anEnemy); newEnemy->setScale(scale); newEnemy->setSpeed(speed); newEnemy->setcollisiontype(collisionstype); BasicModelInstance oneEnemy; theEnemy.Model = anEnemy; XMStoreFloat4x4(&theEnemy.World, modelScale*modelRot*modelOffset); newEnemy->setBasicMInstance(theEnemy); oneEnemy = newEnemy->getBasicMInstance(); addEnemy(theEnemy); enemyclass.push_back(newEnemy); LevelCollisions.push_back(EnemyBox); newEnemy->setWorld(theEnemy.World); }
bool ObjLoaderDemo::init() { if(RenderCore::init() == false) { return false; } // // Must init Effects first since InputLayouts depend on shader signatures. // EffectMgr::initAll(md3dDevice); InputLayoutMgr::initAll(md3dDevice); RenderStateMgr::initAll(md3dDevice); TextureMgr::initAll(md3dDevice); TextureMgr::addPath(std::wstring(L"../Models/")); TextureMgr::addPath(std::wstring(L"../Textures/")); mpModel = new Model(md3dDevice, md3dImmediateContext); //mpModel->loadObj(L"../Models/cup.obj"); mpModel->loadObj(L"../Models/clock_triangulate.obj", true); //mpModel->loadObj(L"../Models/PM3D_Cylinder3D.obj"); XMFLOAT4X4 world, texTransform; XMMATRIX scale = XMMatrixScaling(1.f, 1.f, 1.f); XMMATRIX translation = XMMatrixTranslation(0.f, 0.f, 0.f); XMStoreFloat4x4(&world, XMMatrixMultiply(scale, translation)); XMStoreFloat4x4(&texTransform, XMMatrixIdentity()); mpModel->update(world, texTransform); return true; }
Player::Player(ID3D11Device* device) { XMMATRIX I = XMMatrixIdentity(); XMStoreFloat4x4(&mPlayerWorld, I); XMStoreFloat4x4(&mTexTransform, I); XMStoreFloat4x4(&mView, I); XMStoreFloat4x4(&mProj, I); XMMATRIX PlayerScale = XMMatrixScaling(3.0f, 1.0f, 3.0f); XMMATRIX PlayerOffset = XMMatrixTranslation(0.0f, 5.0f, 0.0f); XMStoreFloat4x4(&mPlayerWorld, XMMatrixMultiply(PlayerScale, PlayerOffset)); mPlayerMat.Ambient = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f); mPlayerMat.Diffuse = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f); mPlayerMat.Specular = XMFLOAT4(0.6f, 0.6f, 0.6f, 16.0f); HR(D3DX11CreateShaderResourceViewFromFile(device, L"Textures/WoodCrate02.dds", 0, 0, &mDiffuseMapSRV, 0)); pdevice = device; buildBuffers(); }
void DemoApp::RenderMiniWindow() { //Set Buffers, Layout, Topology and Render States UINT stride = sizeof(Vertex::VertexPNT); UINT offset = 0; md3dImmediateContext->IASetVertexBuffers(0, 1, &m_pScreenQuadVB, &stride, &offset); md3dImmediateContext->IASetIndexBuffer(m_pScreenQuadIB, DXGI_FORMAT_R32_UINT, 0); md3dImmediateContext->IASetInputLayout(InputLayouts::VertexPNT); md3dImmediateContext->RSSetState(RenderStates::NoCullRS); //Resize mini window and translate to upper left corner XMMATRIX scale = XMMatrixScaling(1.0f / AspectRatio(), 1.0f, 1.0f); XMMATRIX world = XMMATRIX( 0.25f, 0.0f, 0.0f, 0.0f, 0.0f, 0.25f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.25 / AspectRatio() - 1, 0.75f, 0.0f, 1.0f); CBPerFrameScreenQuad cbScreenQuadPerFrame; cbScreenQuadPerFrame.wvp = XMMatrixTranspose(scale * world); md3dImmediateContext->UpdateSubresource(m_pCBPerFrameScreenQuad, 0, NULL, &cbScreenQuadPerFrame, 0, 0); md3dImmediateContext->VSSetShader(m_pDebugTextureVS, NULL, 0); md3dImmediateContext->VSSetConstantBuffers(0, 1, &m_pCBPerFrameScreenQuad); md3dImmediateContext->PSSetShader(m_pDebugTexturePS, NULL, 0); md3dImmediateContext->PSSetShaderResources(0, 1, &m_pDepthSRV); md3dImmediateContext->PSSetSamplers(0, 1, &m_pSampleLinear); md3dImmediateContext->DrawIndexed(6, 0, 0); }
/*------------------------------------ ------ UpdateScene() Funktion ------ Hier wird die Scene verändert ------------------------------------*/ void UpdateScene() { // Rotation der Würfel: rot += 0.00005f; if (rot > 6.28f) rot = 0.0f; // Setze die cube1World Matrix wieder auf die Identität zurück cube1World = XMMatrixIdentity(); XMVECTOR rotaxis1 = XMVectorSet(1.0f, 1.0f, 0.0f, 0.0f); Rotation = XMMatrixRotationAxis(rotaxis1, rot); Translation = XMMatrixTranslation(0.0f, 0.0f, 4.0f); // Bestimme die worldmatrix für würfel1 cube1World = Translation*Rotation; //Jetzt cube2 cube2World = XMMatrixIdentity(); XMVECTOR rotaxis2 = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); Rotation = XMMatrixRotationAxis(rotaxis2, -rot); Scale = XMMatrixScaling(1.3f, 1.3f, 1.3f); cube2World = Scale*Rotation; }
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); }
void RenderSystem::v_Render() { BeginScene(); static float t = 0.0f; static ULONGLONG timeStart = 0; ULONGLONG timeCur = GetTickCount64(); if (timeStart==0) timeStart = timeCur; t = (timeCur-timeStart)/1000.0f; // Light XMMATRIX mSpin = XMMatrixRotationZ(-t); XMMATRIX mOrbit = XMMatrixRotationY(-t * 2.0f); XMMATRIX mTranslate = XMMatrixTranslation(-3.0f, 0.0f, 0.0f); XMMATRIX mScale = XMMatrixScaling(0.3f, 0.3f, 0.3f); XMMATRIX worldCube = mScale * mSpin * mTranslate * mOrbit; XMStoreFloat4x4(&m_Matrix.model, XMMatrixTranspose(worldCube)); m_Cube.Render(m_pD3D11DeviceContext, m_Matrix, XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f) ); XMFLOAT4 lightPos = XMFLOAT4(m_Matrix.model._14, m_Matrix.model._24, m_Matrix.model._34, 0.0f); //Object XMMATRIX rotMat = XMMatrixRotationY(t/10.0f); XMStoreFloat4x4(&m_Matrix.model, XMMatrixTranspose(rotMat)); m_Cube.Render(m_pD3D11DeviceContext, m_Matrix, lightPos); EndScene(); }
bool ModelsDemo::DrawGameObject( GameObject * game_object ) { ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // THESE OPERATIONS ARE NOT ENCAPSULATED YET !!! // activate the vertex layout on the graphics card d3dContext_->IASetInputLayout( inputLayout_ ); // activate the vertex shader on the graphics card d3dContext_->VSSetShader( textureMapVS_, 0, 0 ); // activate the pixel shader on the graphics card d3dContext_->PSSetShader( textureMapPS_, 0, 0 ); // activate the texture sampler on the graphics card d3dContext_->PSSetSamplers( 0, 1, &colorMapSampler_ ); ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // get the display object from the game object DisplayObject * display_object = game_object->GetDisplayObject(); // activate the GameObject's vertex buffer on the graphics card display_object->GetModel()->Render( d3dContext_ ); // activate the GameObject's texture buffer on the graphics card display_object->GetTexture()->Render( d3dContext_ ); // create matrices to create a single world matrix for the GameObject's transform XMMATRIX scale_mat = XMMatrixScaling(game_object->getSX(), game_object->getSY(), game_object->getSZ()); XMMATRIX rotation_mat = XMMatrixRotationRollPitchYaw(game_object->getRX(), game_object->getRY(), game_object->getRZ()); XMMATRIX position_mat = XMMatrixTranslation(game_object->getX(), game_object->getY(), game_object->getZ()); // 1) scale // 2) rotate // 3) position XMMATRIX world_mat = XMMatrixTranspose( scale_mat * rotation_mat * position_mat ); ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // THESE OPERATIONS ARE NOT ENCAPSULATED YET !!! // update the world matrix on the graphics card d3dContext_->UpdateSubresource( worldCB_, 0, 0, &world_mat, 0, 0 ); // set the world matrix on the vertex shader d3dContext_->VSSetConstantBuffers( 0, 1, &worldCB_ ); ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// d3dContext_->Draw( display_object->GetModel()->GetVertexCount(), 0 ); return true; }
void BatchRenderer::DrawAABB( const rxAABB& box, const FColor& color ) { XMMATRIX matWorld = XMMatrixScaling( box.Extents.x, box.Extents.y, box.Extents.z ); XMVECTOR position = XMLoadFloat3( &box.Center ); matWorld.r[3] = XMVectorSelect( matWorld.r[3], position, XMVectorSelectControl( 1, 1, 1, 0 ) ); DrawCube( matWorld, color ); }
void Engine::Model::genMatModel(void) const { *_modelMatrix = XMMatrixScaling(_scale->x, _scale->y, _scale->z) * XMMatrixRotationZ(_rotation->z) * XMMatrixRotationY(_rotation->y) * XMMatrixRotationX(_rotation->x) * XMMatrixTranslation(_position->x, _position->y, _position->z); }