float CBaseMonster::get_screen_space_coverage_diagonal() { Fbox b = Visual()->getVisData().box; Fmatrix xform; xform.mul (Device.mFullTransform,XFORM()); Fvector2 mn ={flt_max,flt_max},mx={flt_min,flt_min}; for (u32 k=0; k<8; ++k) { Fvector p; b.getpoint (k,p); xform.transform (p); mn.x = _min(mn.x,p.x); mn.y = _min(mn.y,p.y); mx.x = _max(mx.x,p.x); mx.y = _max(mx.y,p.y); } float const width = mx.x - mn.x; float const height = mx.y - mn.y; float const average_diagonal = _sqrt(width * height); return average_diagonal; }
void CEditableObject::UpdateBox(){ VERIFY(!m_Meshes.empty()); EditMeshIt m = m_Meshes.begin(); m_Box.invalidate(); for(;m!=m_Meshes.end();m++){ Fbox meshbox; (*m)->GetBox(meshbox); for(int i=0; i<8; i++){ Fvector pt; meshbox.getpoint(i, pt); m_Box.modify(pt); } } }
void CDrawUtilities::OnDeviceCreate() { Device.seqRender.Add (this,REG_PRIORITY_LOW-1000); m_SolidBox.CreateFromData (D3DPT_TRIANGLELIST,DU_BOX_NUMFACES, D3DFVF_XYZ|D3DFVF_DIFFUSE,du_box_vertices, DU_BOX_NUMVERTEX, du_box_faces, DU_BOX_NUMFACES*3); m_SolidCone.CreateFromData (D3DPT_TRIANGLELIST,DU_CONE_NUMFACES, D3DFVF_XYZ|D3DFVF_DIFFUSE,du_cone_vertices, DU_CONE_NUMVERTEX, du_cone_faces, DU_CONE_NUMFACES*3); m_SolidSphere.CreateFromData (D3DPT_TRIANGLELIST,DU_SPHERE_NUMFACES, D3DFVF_XYZ|D3DFVF_DIFFUSE,du_sphere_vertices, DU_SPHERE_NUMVERTEX, du_sphere_faces, DU_SPHERE_NUMFACES*3); m_SolidSpherePart.CreateFromData(D3DPT_TRIANGLELIST,DU_SPHERE_PART_NUMFACES,D3DFVF_XYZ|D3DFVF_DIFFUSE,du_sphere_part_vertices, DU_SPHERE_PART_NUMVERTEX, du_sphere_part_faces, DU_SPHERE_PART_NUMFACES*3); m_SolidCylinder.CreateFromData (D3DPT_TRIANGLELIST,DU_CYLINDER_NUMFACES, D3DFVF_XYZ|D3DFVF_DIFFUSE,du_cylinder_vertices, DU_CYLINDER_NUMVERTEX, du_cylinder_faces, DU_CYLINDER_NUMFACES*3); m_WireBox.CreateFromData (D3DPT_LINELIST, DU_BOX_NUMLINES, D3DFVF_XYZ|D3DFVF_DIFFUSE,du_box_vertices, DU_BOX_NUMVERTEX, du_box_lines, DU_BOX_NUMLINES*2); m_WireCone.CreateFromData (D3DPT_LINELIST, DU_CONE_NUMLINES, D3DFVF_XYZ|D3DFVF_DIFFUSE,du_cone_vertices, DU_CONE_NUMVERTEX, du_cone_lines, DU_CONE_NUMLINES*2); m_WireSphere.CreateFromData (D3DPT_LINELIST, DU_SPHERE_NUMLINES, D3DFVF_XYZ|D3DFVF_DIFFUSE,du_sphere_verticesl, DU_SPHERE_NUMVERTEXL, du_sphere_lines, DU_SPHERE_NUMLINES*2); m_WireSpherePart.CreateFromData (D3DPT_LINELIST, DU_SPHERE_PART_NUMLINES,D3DFVF_XYZ|D3DFVF_DIFFUSE,du_sphere_part_vertices, DU_SPHERE_PART_NUMVERTEX, du_sphere_part_lines, DU_SPHERE_PART_NUMLINES*2); m_WireCylinder.CreateFromData (D3DPT_LINELIST, DU_CYLINDER_NUMLINES, D3DFVF_XYZ|D3DFVF_DIFFUSE,du_cylinder_vertices, DU_CYLINDER_NUMVERTEX, du_cylinder_lines, DU_CYLINDER_NUMLINES*2); for(int i=0;i<LINE_DIVISION;i++){ float angle = M_PI * 2.f * (i / (float)LINE_DIVISION); float _sa=_sin(angle), _ca=_cos(angle); circledef1[i].x = _ca; circledef1[i].y = _sa; circledef1[i].z = 0; circledef2[i].x = 0; circledef2[i].y = _ca; circledef2[i].z = _sa; circledef3[i].x = _sa; circledef3[i].y = 0; circledef3[i].z = _ca; } // initialize identity box Fbox bb; bb.set(-0.505f,-0.505f,-0.505f, 0.505f,0.505f,0.505f); for (i=0; i<8; i++){ Fvector S; Fvector p; bb.getpoint(i,p); S.set((float)SIGN(p.x),(float)SIGN(p.y),(float)SIGN(p.z)); boxvert[i*6+0].set(p); boxvert[i*6+1].set(p.x-S.x*0.25f,p.y,p.z); boxvert[i*6+2].set(p); boxvert[i*6+3].set(p.x,p.y-S.y*0.25f,p.z); boxvert[i*6+4].set(p); boxvert[i*6+5].set(p.x,p.y,p.z-S.z*0.25f); } // create render stream vs_L.create (FVF::F_L,RCache.Vertex.Buffer(),RCache.Index.Buffer()); vs_TL.create (FVF::F_TL,RCache.Vertex.Buffer(),RCache.Index.Buffer()); vs_LIT.create (FVF::F_LIT,RCache.Vertex.Buffer(),RCache.Index.Buffer()); m_Font = new CGameFont("stat_font"); }
bool CLevelTool::GetSelectionPosition(Fmatrix& result) { if(pCurTool) { Fvector center; Fbox BB; BB.invalidate (); // pCurTool->GetBBox (BB, true); const CCustomObject* object = pCurTool->LastSelected(); if(!object) return false; object->GetBox (BB); BB.getcenter (center); center.y = BB.max.y; Fvector2 pt_ss; pt_ss.set (10000,-10000); Fvector pt_ss_3d; BB.setb (center, Fvector().set(1.0f,1.0f,1.0f)); for(int k=0;k<8;++k) { Fvector pt; BB.getpoint(k,pt); EDevice.mFullTransform.transform(pt_ss_3d, pt); pt_ss.x = _min(pt_ss.x, pt_ss_3d.y); pt_ss.y = _max(pt_ss.y, pt_ss_3d.y); } float r_bb_ss = pt_ss.y - pt_ss.x; clamp(r_bb_ss, 0.0f,0.10f); float des_radius = 0.2f; float csale = des_radius/r_bb_ss; result.scale (csale,csale,csale); result.c = center; return true; }else return false; }