void CameraControllerThirdPerson::onMouseMove( u16 x,u16 y ) { if(m_bLButtonDown) { float angleX = (float)(x - m_ptOrigin.x) * 0.1f; float angleY = (float)(y - m_ptOrigin.y) * 0.1f; Quaternion qy(angleX, Vec3::UNIT_Y); Mat4 mtxWorld(qy); m_mtxWorld = m_mtxWorld * mtxWorld; Mat4 mi = m_mtxWorld.inverse(); Vec3 v = m_pCamera->getRight(); v = mi * v; Quaternion q; q.FromAngleAxis(angleY, v); m_mtxWorld = m_mtxWorld * q; } else if(m_bMButtonDown) { m_pCamera->moveRelative(Vec3((-x + m_ptOrigin.x) / 4.0f,0,0)); m_pCamera->moveRelative(Vec3(0,(y - m_ptOrigin.y) / 4.0f,0)); } m_ptOrigin.x = x; m_ptOrigin.y = y; }
XMFLOAT4X4 Tree::getSubsetMatrix(UINT subset) const { return mtxWorld(); }
void Tree::draw(const Camera& camera, const vector<Light*>& lights) { ID3DX11EffectScalarVariable* fx_time = getFX()->GetVariableByName("border")->AsScalar(); fx_time->SetFloat(counter); if (bLeaves) _leaves.draw(camera, lights); // Material Mesh::setMaterial(getFX()); context()->IASetInputLayout(getInputLayout()); // World Matrix XMMATRIX mWorld = XMLoadFloat4x4(&(mtxWorld())); fx_m_World->SetMatrix((float*)&mWorld); fx_m_WorldViewProj->SetMatrix((float*)&(mWorld * camera.getViewMatrix() * camera.getProjectionMatrix())); fx_pEye->SetFloatVector((float*)&(camera.getPosVector3())); // Light // mView, shadow_map, light params for (unsigned int i=0; i<lights.size(); ++i) { fx_m_L_ViewProj = getFX()->GetVariableByName("m_L_ViewProj")->GetElement(i)->AsMatrix(); fx_lights = getFX()->GetVariableByName("lights")->GetElement(i); fx_tex_shadow_map = getFX()->GetVariableByName("tex_shadow_map")->GetElement(i)->AsShaderResource(); fx_m_L_ViewProj->SetMatrix( (float*)&(lights[i]->getViewProjMatrix()) ); fx_tex_shadow_map->SetResource( lights[i]->getShadowMapSRV()) ; fx_lights->SetRawValue( (void*)&(lights[i]->getLightStructure()), 0, sizeof(Light_Params) ); } ID3DX11EffectScalarVariable* fx_shadow_size = getFX()->GetVariableByName("shadow_size")->AsScalar(); fx_shadow_size->SetInt(lights[0]->getShadowMapSize()); fx_num_lights->SetInt(lights.size()); fx_bShadowed->SetBool(isShadowReceiver()); fx_bUsePCSS->SetBool(PCSS()); ID3DX11EffectScalarVariable* fx_bLit = getFX()->GetVariableByName("bLit")->AsScalar(); fx_bLit->SetBool(isLit()); if (render_mode == Tree::NonTexturedNonLitWireframe) Mesh::draw(0, getFX(), "Tree_NonTexturedNonLitWireframe"); else if (render_mode == Tree::NonTexturedFlatShaded) Mesh::draw(0, getFX(), "Tree_NonTexturedFlatShaded"); else if (render_mode == Tree::NonTexturedSmoothShaded) Mesh::draw(0, getFX(), "Tree_NonTexturedSmoothShaded"); else if (render_mode == Tree::TexturedSmoothShaded) Mesh::draw(0, getFX(), "Tree"); else { ID3DX11EffectShaderResourceVariable* fx_tex_heightmap = getFX()->GetVariableByName("tex_heightmap")->AsShaderResource(); fx_tex_heightmap->SetResource(srv_heightmap); Mesh::draw(0, getFX(), "Tree_DisplacementMapping"); } for (unsigned int i=0; i<lights.size(); ++i) { fx_tex_shadow_map = getFX()->GetVariableByName("tex_shadow_map")->GetElement(i)->AsShaderResource(); fx_tex_shadow_map->SetResource(0); } ID3DX11EffectTechnique* tech = getFX()->GetTechniqueByName("Tree"); tech->GetPassByIndex(0)->Apply(0, context()); }