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); }
void ZombieForce::CreateSphere() { DXSphere* newSphere = new DXSphere(md3dDevice, L"../Assets/Textures/stone2.jpg"); newSphere->SetPosition(Vector3(mCam.GetPosition().x,mCam.GetPosition().y,mCam.GetPosition().z)); newSphere->SetScale(Vector3(2,2,2)); spheres.push_back(newSphere); }
void ZombieForce::CreateBox() { DXBox *newBox = new DXBox(md3dDevice, L"../Assets/Textures/brick.dds"); newBox->SetPosition(Vector3(mCam.GetPosition().x,mCam.GetPosition().y,mCam.GetPosition().z)); newBox->SetScale(Vector3(2,2,2)); boxes.push_back(newBox); }
void ZombieForce::DrawScene() { md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Blue)); md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0); md3dImmediateContext->IASetInputLayout(InputLayouts::Basic32); md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); UINT stride = sizeof(Vertex::Basic32); UINT offset = 0; mCam.UpdateViewMatrix(); XMMATRIX view = mCam.View(); XMMATRIX proj = mCam.Proj(); XMMATRIX viewProj = mCam.ViewProj(); // Set per frame constants. Effects::BillboardFX->SetDirLights(mDirLights); Effects::BillboardFX->SetEyePosW(mCam.GetPosition()); Effects::BillboardFX->SetCubeMap(mSky->CubeMapSRV()); //ID3DX11EffectTechnique* activeTech = Effects::BasicFX->Light2TexTech; ID3DX11EffectTechnique* activeTech = Effects::BillboardFX->Light2TexTech; D3DX11_TECHNIQUE_DESC techDesc; activeTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { pyramid->DrawPyramid(md3dImmediateContext,activeTech, mCam); //myFirstSphere->DrawSphere(md3dImmediateContext,activeTech, mCam); myFirstPlane->DrawPlane(md3dImmediateContext,activeTech, mCam); //myFirstGeoSphere->DrawGeoSphere(md3dImmediateContext,activeTech, mCam); //myFirstCylinder->DrawCylinder(md3dImmediateContext,activeTech, mCam); for(unsigned int i = 0; i < spheres.size(); ++i) { spheres[i]->DrawSphere(md3dImmediateContext,activeTech, mCam); } for(unsigned int i = 0; i < boxes.size(); ++i) { boxes[i]->DrawBox(md3dImmediateContext,activeTech, mCam); } CMESHMANAGER->Render(md3dImmediateContext, activeTech, mCam); } mSky->Draw(md3dImmediateContext, mCam); // restore default states, as the SkyFX changes them in the effect file. md3dImmediateContext->RSSetState(0); md3dImmediateContext->OMSetDepthStencilState(0, 0); HR(mSwapChain->Present(0, 0)); }
void ZombieForce::OnMouseMove(WPARAM btnState, int x, int y) { if( (btnState & MK_LBUTTON) != 0 ) { // Make each pixel correspond to a quarter of a degree. float dx = XMConvertToRadians(0.25f*static_cast<float>(x - mLastMousePos.x)); float dy = XMConvertToRadians(0.25f*static_cast<float>(y - mLastMousePos.y)); mCam.Pitch(dy); mCam.RotateY(dx); } mLastMousePos.x = x; mLastMousePos.y = y; }
bool Application::OnUpdate() { //System Update m_pMouse->Update(); m_pKeyboard->Update(); m_pCamera->Update(); m_pGameTime->Update(); //m_fRot += PI * GameTime::GetTimeElapsed(); //m_pScene->SetRotateY(m_fRot); m_pScene->Update(); if(m_pKeyboard->IsKeyPressed(KEY_1)) { m_pParent->DetachChild(m_pChild); } else if(m_pKeyboard->IsKeyPressed(KEY_2)) { m_pParent->AttachChild(m_pChild); } m_pChild->Update(); DX11Camera::FreeLookCamera(m_pCamera,10.0f); //m_pCamera->LookAt(D3DXVECTOR3(0,0,0)); //Window Update return m_pWindow->Tick(); }
void Application::OnDestroy() { if(m_pShaderProp) delete m_pShaderProp; if(m_pScene) delete m_pScene; m_pGameTime->Release(); m_pCamera->Release(); m_pRenderer->Release(); m_pWindow->Release(); m_pMouse->Release(); m_pKeyboard->Release(); }
void ZombieForce::UpdateScene(float dt) { ColladaMesh* mesh = CMESHMANAGER->GetMesh(0); float MoveMultiplier = 1; if( GetAsyncKeyState(VK_LSHIFT) & 0x8000 ) MoveMultiplier = 10; // Control the camera. if( GetAsyncKeyState('W') & 0x8000 ) mCam.Walk(10.0f*dt*MoveMultiplier); if( GetAsyncKeyState('S') & 0x8000 ) mCam.Walk(-10.0f*dt*MoveMultiplier); if( GetAsyncKeyState('A') & 0x8000 ) mCam.Strafe(-10.0f*dt*MoveMultiplier); if( GetAsyncKeyState('D') & 0x8000 ) mCam.Strafe(10.0f*dt*MoveMultiplier); if( GetAsyncKeyState('T') & 0x8000 ) mesh->SetScale(mesh->GetScale() + (Vector3(.01f,.01f,-.01f))); if( GetAsyncKeyState('Q') & 0x8000 ) mesh->SetScale(mesh->GetScale() + (Vector3(-.01f,-.01f,.01f))); if( GetAsyncKeyState(VK_UP) & 0x8000 ) mesh->SetPosition(mesh->GetPosition() + (Vector3(0,10,0)*dt)); if( GetAsyncKeyState(VK_RIGHT) & 0x8000 ) mesh->SetPosition(mesh->GetPosition() + (Vector3(10,0,0)*dt)); if( GetAsyncKeyState(VK_DOWN) & 0x8000 ) mesh->SetPosition(mesh->GetPosition() + (Vector3(0,-10,0)*dt)); if( GetAsyncKeyState(VK_LEFT) & 0x8000 ) mesh->SetPosition(mesh->GetPosition() + (Vector3(-10,0,0)*dt)); if( GetAsyncKeyState(VK_NUMPAD8) & 0x8000 ) mesh->SetRotation(mesh->GetRotation() + (Vector3(-1,0,0)*dt)); if( GetAsyncKeyState(VK_NUMPAD5) & 0x8000 ) mesh->SetRotation(mesh->GetRotation() + (Vector3(1,0,0)*dt)); if( GetAsyncKeyState(VK_NUMPAD7) & 0x8000 ) mesh->SetRotation(mesh->GetRotation() + (Vector3(0,0,-1)*dt)); if( GetAsyncKeyState(VK_NUMPAD9) & 0x8000 ) mesh->SetRotation(mesh->GetRotation() + (Vector3(0,0,1)*dt)); if( GetAsyncKeyState(VK_NUMPAD4) & 0x8000 ) mesh->SetRotation(mesh->GetRotation() + (Vector3(0,-1,0)*dt)); if( GetAsyncKeyState(VK_NUMPAD6) & 0x8000 ) { mesh->SetRotation(mesh->GetRotation() + (Vector3(0,1,0)*dt)); } if( GetAsyncKeyState('I') & 0x8000 ) { mesh->SetPosition(mesh->GetPosition() + (Vector3(0,0,10)*dt)); } if( GetAsyncKeyState('K') & 0x8000 ) { //ColladaMesh* mesh = CMESHMANAGER->GetMesh(0); mesh->SetPosition(mesh->GetPosition() + (Vector3(0,0,-10)*dt)); } if( GetAsyncKeyState('L') & 0x8000 ) { //ColladaMesh* mesh = CMESHMANAGER->GetMesh(0); mesh->SetPosition(mesh->GetPosition() + (Vector3(0,0,30)*dt)); } if( GetAsyncKeyState('J') & 0x8000 ) { //ColladaMesh* mesh = CMESHMANAGER->GetMesh(0); mesh->SetPosition(mesh->GetPosition() + (Vector3(0,0,-30)*dt)); } if( GetAsyncKeyState(VK_LCONTROL) & 0x8000 ) { CreateSphere(); } if( GetAsyncKeyState(VK_SPACE) & 0x8000 ) { CreateBox(); } CMESHMANAGER->Update(dt); myFirstSphere->SetRotation(myFirstSphere->GetRotation() + (Vector3(0,2,0)*dt)); //myFirstPlane->SetRotation(myFirstSphere->GetRotation() + (Vector3(1,0,0)*dt)); //myFirstGeoSphere->SetRotation(myFirstSphere->GetRotation() + (Vector3(0,2,0)*dt)); //myFirstCylinder->SetRotation(myFirstSphere->GetRotation() + (Vector3(0,0,1)*dt)); }
void ZombieForce::OnResize() { DX11App::OnResize(); mCam.SetLens(0.25f*MathHelper::Pi, AspectRatio(), .20f, 1000.0f); }
bool Application::OnCreate(const char* a_sCmdLine) { Utilities::ConsoleShow(true); //System m_pWindow = Window::Create("Ichor Window",1024,768); m_pRenderer = DX11Renderer::Create(m_pWindow); m_pGameTime = GameTime::Create(); //Input m_pKeyboard = Keyboard::Create(); m_pMouse = Mouse::Create(); m_pWindow->AttachMouse(m_pMouse); //Camera DX11Frustrum oFustrum; oFustrum.m_fFieldOfView = ((F32)PI_HALF / 2.0f); oFustrum.m_fScreenAspect = ((F32)m_pWindow->GetWidth() / (F32)m_pWindow->GetHeight()); oFustrum.m_fNear = 0.01f; oFustrum.m_fFar = 100.0f; m_pCamera = DX11Camera::Create(oFustrum); m_pCamera->SetTranslate(0.0f,0.0f,-10.0f); struct sData { char cInitial; int iVal; float fVal; double dVal; long long llVal; char cVal; }; sData* fDelta = new sData; //Shaders m_pShaderProp = ShaderProperty::Create("./Data/Shaders/Base.hlsl"); m_pShaderProp->AddCBuffer("Matrix",fDelta,sizeof(sData),0); //OBJECTS //Scene m_pScene = new Node("Scene"); //Cube m_pParent = dynamic_cast<Mesh*>(CreateCube()); m_pParent->AttachProperty(m_pShaderProp); m_pParent->SetTranslate(1,0,0); m_pChild = dynamic_cast<Mesh*>(m_pParent->Clone()); m_pChild->SetTranslate(-5,0,0); m_pParent->Update(); m_pChild->Update(); //Parenting m_pScene->AttachChild(m_pParent); m_pParent->AttachChild(m_pChild); m_fRot = 0.0f; return true; }