void CScriptParticles::MoveTo (const Fvector &pos, const Fvector& vel) { VERIFY (m_particles); Fmatrix XF; XF.translate (pos); m_particles->UpdateParent (XF,vel); }
void occRasterizer::on_dbg_render() { #if DEBUG if( !ps_r2_ls_flags_ext.is(R_FLAGEXT_HOM_DEPTH_DRAW) ) { dbg_HOM_draw_initialized = false; return; } for ( int i = 0; i< occ_dim_0; ++i) { for ( int j = 0; j< occ_dim_0; ++j) { if( bDebug ) { Fvector quad,left_top,right_bottom,box_center,box_r; quad.set( (float)j-occ_dim_0/2.f, -((float)i-occ_dim_0/2.f), (float)bufDepth_0[i][j]/occQ_s32); Device.mProject; float z = -Device.mProject._43/(float)(Device.mProject._33-quad.z); left_top.set ( quad.x*z/Device.mProject._11/(occ_dim_0/2.f), quad.y*z/Device.mProject._22/(occ_dim_0/2.f), z); right_bottom.set ( (quad.x+1)*z/Device.mProject._11/(occ_dim_0/2.f), (quad.y+1)*z/Device.mProject._22/(occ_dim_0/2.f), z); box_center.set ((right_bottom.x + left_top.x)/2, (right_bottom.y + left_top.y)/2, z); box_r = right_bottom; box_r.sub(box_center); Fmatrix inv; inv.invert(Device.mView); inv.transform( box_center ); inv.transform_dir( box_r ); pixel_box& tmp = dbg_pixel_boxes[ i*occ_dim_0+j]; tmp.center = box_center; tmp.radius = box_r; tmp.z = quad.z; dbg_HOM_draw_initialized = true; } if( !dbg_HOM_draw_initialized ) return; pixel_box& tmp = dbg_pixel_boxes[ i*occ_dim_0+j]; Fmatrix Transform; Transform.identity(); Transform.translate(tmp.center); // draw wire Device.SetNearer(TRUE); RCache.set_Shader (dxRenderDeviceRender::Instance().m_SelectionShader); RCache.dbg_DrawOBB( Transform, tmp.radius, D3DCOLOR_XRGB(u32(255*pow(tmp.z,20.f)),u32(255*(1-pow(tmp.z,20.f))),0) ); Device.SetNearer(FALSE); } } #endif }
void CArtefact::MoveTo(Fvector const & position) { if (!PPhysicsShell()) return; Fmatrix M = XFORM(); M.translate(position); ForceTransform(M); //m_bInInterpolation = false; }
void CParticlesObject::play_at_pos(const Fvector& pos, BOOL xform) { if(g_dedicated_server) return; IParticleCustom* V = smart_cast<IParticleCustom*>(renderable.visual); VERIFY(V); Fmatrix m; m.translate (pos); V->UpdateParent (m,zero_vel,xform); V->Play (); dwLastTime = Device.dwTimeGlobal-33ul; mt_dt = 0; PerformAllTheWork (0); m_bStopping = false; }
void game_cl_Deathmatch::PlayParticleEffect(LPCSTR EffName, Fvector& pos) { if (!EffName) return; // вычислить позицию и направленность партикла Fmatrix M; M.translate(pos); // CParticlesPlayer::MakeXFORM(pObj,0,Fvector().set(0.f,1.f,0.f),Fvector().set(0.f,0.f,0.f),pos); // установить particles CParticlesObject* ps = NULL; ps = CParticlesObject::Create(EffName,TRUE); ps->UpdateParent(M,Fvector().set(0.f,0.f,0.f)); GamePersistent().ps_needtoplay.push_back(ps); }
void CActor::MoveActor (Fvector NewPos, Fvector NewDir) { Fmatrix M = XFORM(); M.translate(NewPos); r_model_yaw = NewDir.y; r_torso.yaw = NewDir.y; r_torso.pitch = -NewDir.x; unaffected_r_torso.yaw = r_torso.yaw; unaffected_r_torso.pitch= r_torso.pitch; unaffected_r_torso.roll = 0;//r_torso.roll; r_torso_tgt_roll = 0; cam_Active()->Set (-unaffected_r_torso.yaw,unaffected_r_torso.pitch,unaffected_r_torso.roll); ForceTransform(M); m_bInInterpolation = false; }
void CParticleManager::Transform(int alist_id, const Fmatrix& full, const Fvector& vel) { // Execute the specified action list. ParticleActions* pa = GetActionListPtr(alist_id); if(pa == NULL) return; // ERROR Fmatrix mT; mT.translate(full.c); // Step through all the actions in the action list. for(PAVecIt it=pa->begin(); it!=pa->end(); it++){ BOOL r = (*it)->m_Flags.is(ParticleAction::ALLOW_ROTATE); const Fmatrix& m = r?full:mT; (*it)->Transform(m); switch((*it)->type) { case PASourceID: static_cast<PASource*>(*it)->parent_vel = pVector(vel.x,vel.y,vel.z)*static_cast<PASource*>(*it)->parent_motion; break; } } }
void CLightProjector::calculate () { #ifdef _GPA_ENABLED TAL_SCOPED_TASK_NAMED( "CLightProjector::calculate()" ); #endif // _GPA_ENABLED if (receivers.empty()) return; // perform validate / markup for (u32 r_it=0; r_it<receivers.size(); r_it++) { // validate BOOL bValid = TRUE; IRenderable* O = receivers[r_it]; CROS_impl* LT = (CROS_impl*)O->renderable_ROS(); int slot = LT->shadow_recv_slot; if (slot<0 || slot>=P_o_count) bValid = FALSE; // invalid slot else if (cache[slot].O!=O) bValid = FALSE; // not the same object else { // seems to be valid Fbox bb; bb.xform (O->renderable.visual->getVisData().box,O->renderable.xform); if (cache[slot].BB.contains(bb)) { // inside, but maybe timelimit exceeded? if (Device.dwTimeGlobal > cache[slot].dwTimeValid) bValid = FALSE; // timeout } else bValid = FALSE; // out of bounds } // if (bValid) { // Ok, use cached version cache[slot].dwFrame = Device.dwFrame; } else { taskid.push_back (r_it); } } if (taskid.empty()) return; // Begin Device.Statistic->RenderDUMP_Pcalc.Begin (); RCache.set_RT (RT->pRT); RCache.set_ZB (RImplementation.Target->pTempZB); CHK_DX(HW.pDevice->Clear (0,0, D3DCLEAR_ZBUFFER | (HW.Caps.bStencil?D3DCLEAR_STENCIL:0), 0,1,0 )); RCache.set_xform_world (Fidentity); // reallocate/reassociate structures + perform all the work for (u32 c_it=0; c_it<cache.size(); c_it++) { if (taskid.empty()) break; if (Device.dwFrame==cache[c_it].dwFrame) continue; // found not used slot int tid = taskid.back(); taskid.pop_back(); recv& R = cache [c_it]; IRenderable* O = receivers [tid]; const vis_data& vis = O->renderable.visual->getVisData(); CROS_impl* LT = (CROS_impl*)O->renderable_ROS(); VERIFY2 (_valid(O->renderable.xform),"Invalid object transformation"); VERIFY2 (_valid(vis.sphere.P),"Invalid object's visual sphere"); Fvector C; O->renderable.xform.transform_tiny (C,vis.sphere.P); R.O = O; R.C = C; R.C.y += vis.sphere.R*0.1f; //. YURA: 0.1 can be more R.BB.xform (vis.box,O->renderable.xform).scale(0.1f); R.dwTimeValid = Device.dwTimeGlobal + ::Random.randI(time_min,time_max); LT->shadow_recv_slot = c_it; // Msg ("[%f,%f,%f]-%f",C.C.x,C.C.y,C.C.z,C.O->renderable.visual->vis.sphere.R); // calculate projection-matrix Fmatrix mProject; float p_R = R.O->renderable.visual->getVisData().sphere.R * 1.1f; //VERIFY2 (p_R>EPS_L,"Object has no physical size"); VERIFY3 (p_R>EPS_L,"Object has no physical size", R.O->renderable.visual->getDebugName().c_str()); float p_hat = p_R/P_cam_dist; float p_asp = 1.f; float p_near = P_cam_dist-EPS_L; float p_far = P_cam_dist+p_R+P_cam_range; mProject.build_projection_HAT (p_hat,p_asp,p_near,p_far); RCache.set_xform_project (mProject); // calculate view-matrix Fmatrix mView; Fvector v_C, v_Cs, v_N; v_C.set (R.C); v_Cs = v_C; v_C.y += P_cam_dist; v_N.set (0,0,1); VERIFY (_valid(v_C) && _valid(v_Cs) && _valid(v_N)); // validate Fvector v; v.sub (v_Cs,v_C);; #ifdef DEBUG if ((v.x*v.x+v.y*v.y+v.z*v.z)<=flt_zero) { CObject* OO = dynamic_cast<CObject*>(R.O); Msg("Object[%s] Visual[%s] has invalid position. ",*OO->cName(),*OO->cNameVisual()); Fvector cc; OO->Center(cc); Log("center=",cc); Log("visual_center=",OO->Visual()->getVisData().sphere.P); Log("full_matrix=",OO->XFORM()); Log ("v_N",v_N); Log ("v_C",v_C); Log ("v_Cs",v_Cs); Log("all bones transform:--------"); CKinematics* K = dynamic_cast<CKinematics*>(OO->Visual()); for(u16 ii=0; ii<K->LL_BoneCount();++ii){ Fmatrix tr; tr = K->LL_GetTransform(ii); Log("bone ",K->LL_BoneName_dbg(ii)); Log("bone_matrix",tr); } Log("end-------"); } #endif // handle invalid object-bug if ((v.x*v.x+v.y*v.y+v.z*v.z)<=flt_zero) { // invalidate record, so that object will be unshadowed, but doesn't crash R.dwTimeValid = Device.dwTimeGlobal; LT->shadow_recv_frame = Device.dwFrame-1; LT->shadow_recv_slot = -1; continue ; } mView.build_camera (v_C,v_Cs,v_N); RCache.set_xform_view (mView); // Select slot, set viewport int s_x = c_it%P_o_line; int s_y = c_it/P_o_line; D3DVIEWPORT9 VP = {s_x*P_o_size,s_y*P_o_size,P_o_size,P_o_size,0,1 }; CHK_DX (HW.pDevice->SetViewport(&VP)); // Clear color to ambience Fvector& cap = LT->get_approximate(); CHK_DX (HW.pDevice->Clear(0,0, D3DCLEAR_TARGET, color_rgba_f(cap.x,cap.y,cap.z, (cap.x+cap.y+cap.z)/4.f), 1, 0 )); // calculate uv-gen matrix and clamper Fmatrix mCombine; mCombine.mul (mProject,mView); Fmatrix mTemp; float fSlotSize = float(P_o_size)/float(P_rt_size); float fSlotX = float(s_x*P_o_size)/float(P_rt_size); float fSlotY = float(s_y*P_o_size)/float(P_rt_size); float fTexelOffs = (.5f / P_rt_size); Fmatrix m_TexelAdjust = { 0.5f/*x-scale*/, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f/*y-scale*/, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f/*z-range*/, 0.0f, 0.5f/*x-bias*/, 0.5f + fTexelOffs/*y-bias*/, 0.0f/*z-bias*/, 1.0f }; R.UVgen.mul (m_TexelAdjust,mCombine); mTemp.scale (fSlotSize,fSlotSize,1); R.UVgen.mulA_44 (mTemp); mTemp.translate (fSlotX+fTexelOffs,fSlotY+fTexelOffs,0); R.UVgen.mulA_44 (mTemp); // Build bbox and render Fvector min,max; Fbox BB; min.set (R.C.x-p_R, R.C.y-(p_R+P_cam_range), R.C.z-p_R); max.set (R.C.x+p_R, R.C.y+0, R.C.z+p_R); BB.set (min,max); R.UVclamp_min.set (min).add (.05f); // shrink a little R.UVclamp_max.set (max).sub (.05f); // shrink a little ISpatial* spatial = dynamic_cast<ISpatial*> (O); if (spatial) { spatial->spatial_updatesector (); if (spatial->spatial.sector) RImplementation.r_dsgraph_render_R1_box (spatial->spatial.sector,BB,SE_R1_LMODELS); } //if (spatial) RImplementation.r_dsgraph_render_subspace (spatial->spatial.sector,mCombine,v_C,FALSE); } // Blur /* { // Fill vertex buffer u32 Offset; FVF::TL4uv* pv = (FVF::TL4uv*) RCache.Vertex.Lock (4,geom_Blur.stride(),Offset); RImplementation.ApplyBlur4 (pv,P_rt_size,P_rt_size,P_blur_kernel); RCache.Vertex.Unlock (4,geom_Blur.stride()); // Actual rendering (pass0, temp2real) RCache.set_RT (RT->pRT); RCache.set_ZB (NULL); RCache.set_Shader (sh_BlurTR ); RCache.set_Geometry (geom_Blur ); RCache.Render (D3DPT_TRIANGLELIST,Offset,0,4,0,2); } */ // Finita la comedia Device.Statistic->RenderDUMP_Pcalc.End (); RCache.set_xform_project (Device.mProject); RCache.set_xform_view (Device.mView); }
void CParticleGroup::SItem::OnFrame(u32 u_dt, const CPGDef::SEffect& def, Fbox& box, bool& bPlaying) { CParticleEffect* E = static_cast<CParticleEffect*>(_effect); if (E){ E->OnFrame (u_dt); if (E->IsPlaying()){ bPlaying = true; if (E->vis.box.is_valid()) box.merge (E->vis.box); if (def.m_Flags.is(CPGDef::SEffect::flOnPlayChild)&&def.m_OnPlayChildName.size()){ PAPI::Particle* particles; u32 p_cnt; PAPI::ParticleManager()->GetParticles(E->GetHandleEffect(),particles,p_cnt); VERIFY(p_cnt==_children_related.size()); if (p_cnt){ for(u32 i = 0; i < p_cnt; i++){ PAPI::Particle &m = particles[i]; CParticleEffect* C = static_cast<CParticleEffect*>(_children_related[i]); Fmatrix M; M.translate(m.pos); Fvector vel; vel.sub(m.pos,m.posB); vel.div(fDT_STEP); C->UpdateParent (M,vel,FALSE); } } } } } VisualVecIt it; if (!_children_related.empty()){ for (it=_children_related.begin(); it!=_children_related.end(); it++){ CParticleEffect* E = static_cast<CParticleEffect*>(*it); if (E){ E->OnFrame (u_dt); if (E->IsPlaying()){ bPlaying = true; if (E->vis.box.is_valid()) box.merge (E->vis.box); }else{ if (def.m_Flags.is(CPGDef::SEffect::flOnPlayChildRewind)){ E->Play (); } } } } } if (!_children_free.empty()){ u32 rem_cnt = 0; for (it=_children_free.begin(); it!=_children_free.end(); it++){ CParticleEffect* E = static_cast<CParticleEffect*>(*it); if (E){ E->OnFrame (u_dt); if (E->IsPlaying()){ bPlaying = true; if (E->vis.box.is_valid()) box.merge (E->vis.box); }else{ rem_cnt++ ; ::Render->model_Delete(*it); } } } // remove if stopped if (rem_cnt){ VisualVecIt new_end=std::remove_if(_children_free.begin(),_children_free.end(),zero_vis_pred()); _children_free.erase(new_end,_children_free.end()); } } // Msg("C: %d CS: %d",_children.size(),_children_stopped.size()); }