int EScene::BoxQuery(SPickQuery& PQ, const Fbox& bb, u32 flags, CDB::MODEL* model) { PQ.prepare_bq (bb,flags); ETOOLS::box_options (flags); Fvector c,d; bb.getcenter (c); bb.getradius (d); ETOOLS::box_query (model,c,d); for (int r=0; r<ETOOLS::r_count(); r++) PQ.append (ETOOLS::r_begin()+r,0,0); return PQ.r_count(); }
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; }
void dx103DFluidRenderer::CalculateLighting(const dx103DFluidData &FluidData, FogLighting &LightData) { m_lstRenderables.clear_not_free(); LightData.Reset(); const dx103DFluidData::Settings &VolumeSettings = FluidData.GetSettings(); Fvector4 hemi_color = g_pGamePersistent->Environment().CurrentEnv->hemi_color; //hemi_color.mul(0.2f); hemi_color.mul(VolumeSettings.m_fHemi); LightData.m_vLightIntencity.set(hemi_color.x, hemi_color.y, hemi_color.z); LightData.m_vLightIntencity.add(g_pGamePersistent->Environment().CurrentEnv->ambient); const Fmatrix &Transform = FluidData.GetTransform(); Fbox box; box.min = Fvector3().set(-0.5f, -0.5f, -0.5f); box.max = Fvector3().set( 0.5f, 0.5f, 0.5f); box.xform(Transform); Fvector3 center; Fvector3 size; box.getcenter(center); box.getradius(size); // Traverse object database g_SpatialSpace->q_box ( m_lstRenderables, 0, //ISpatial_DB::O_ORDERED, STYPE_LIGHTSOURCE, center, size ); u32 iNumRenderables = m_lstRenderables.size(); // Determine visibility for dynamic part of scene for (u32 i=0; i<iNumRenderables; ++i) { ISpatial* spatial = m_lstRenderables[i]; // Light light* pLight = (light*) spatial->dcast_Light(); VERIFY(pLight); if (pLight->flags.bStatic) continue; float d = pLight->position.distance_to(Transform.c); float R = pLight->range + _max( size.x, _max( size.y, size.z ) ); if ( d >= R ) continue; Fvector3 LightIntencity; LightIntencity.set(pLight->color.r, pLight->color.g, pLight->color.b); //LightIntencity.mul(0.5f); //if (!pLight->flags.bStatic) // LightIntencity.mul(0.5f); float r = pLight->range; float a = clampr(1.f - d/(r+EPS),0.f,1.f)*(pLight->flags.bStatic?1.f:2.f); LightIntencity.mul(a); LightData.m_vLightIntencity.add(LightIntencity); } //LightData.m_vLightIntencity.set( 1.0f, 0.5f, 0.0f); //LightData.m_vLightIntencity.set( 1.0f, 1.0f, 1.0f); }
void xrMU_Model::export_geometry () { // Declarator VDeclarator D; D.set (decl); // RT-check, BOX, low-point, frac-size Fbox BB; BB.invalidate (); for (v_vertices_it vit=m_vertices.begin(); vit!=m_vertices.end(); vit++) BB.modify ((*vit)->P); Fvector frac_low; float frac_Ysize; BB.getcenter (frac_low); frac_low.y = BB.min.y; frac_Ysize = BB.max.y - BB.min.y; // Begin building for (v_subdivs_it it=m_subdivs.begin(); it!=m_subdivs.end(); it++) { // Vertices { g_VB.Begin (D); vecOGF_V& verts = it->ogf->vertices; for (u32 v_it=0; v_it<verts.size(); v_it++) { OGF_Vertex& oV = verts[v_it]; // Position g_VB.Add (&oV.P,3*sizeof(float)); // Normal { base_color_c oV_c; oV.Color._get(oV_c); Fvector N = oV.N; N.add (1.f); N.mul (.5f*255.f); s32 nx = iFloor(N.x); clamp(nx,0,255); s32 ny = iFloor(N.y); clamp(ny,0,255); s32 nz = iFloor(N.z); clamp(nz,0,255); s32 cc = iFloor(oV_c.hemi*255.f); clamp(cc,0,255); u32 uN = color_rgba(nx,ny,nz,cc); g_VB.Add (&uN,4); } // Tangent { u32 uT = color_rgba(oV.T.x,oV.T.y,oV.T.z,0); g_VB.Add (&uT,4); } // Binormal { u32 uB = color_rgba(oV.B.x,oV.B.y,oV.B.z,0); g_VB.Add (&uB,4); } // TC s16 tu,tv,frac,dummy; tu = QC(oV.UV.begin()->x); tv = QC(oV.UV.begin()->y); g_VB.Add (&tu,2); g_VB.Add (&tv,2); // frac float f1 = (oV.P.y - frac_low.y) /frac_Ysize; float f2 = oV.P.distance_to(frac_low)/frac_Ysize; frac = QC((f1+f2)/2.f); dummy = 0; g_VB.Add (&frac, 2); g_VB.Add (&dummy,2); } g_VB.End (&it->vb_id,&it->vb_start); } // Indices g_IB.Register (LPWORD(&*it->ogf->faces.begin()),LPWORD(&*it->ogf->faces.end()),&it->ib_id,&it->ib_start); // SW if (it->ogf->progressive_test()) g_SWI.Register (&it->sw_id,&it->ogf->m_SWI); } }