void CElevatorState::UpdateStClimbingDown() { VERIFY(m_ladder&&m_character); Fvector d; if(ClimbDirection()>0.f&&m_ladder->BeforeLadder(m_character)) SwitchState(clbClimbingUp); float to_ax=m_ladder->DDToAxis(m_character,d); Fvector ca;ca.set(m_character->ControlAccel()); float control_a=to_mag_and_dir(ca); if(!fis_zero(to_ax)&&!fis_zero(control_a)&&abs(-ca.dotproduct(Fvector(m_ladder->Norm()).normalize()))<M_SQRT1_2)SwitchState(clbDepart); if(m_ladder->AxDistToLowerP(m_character)-m_character->FootRadius()<stop_climbing_dist) SwitchState(clbNearDown); UpdateClimbingCommon(d,to_ax,ca,control_a); if(m_ladder->AxDistToUpperP(m_character)<-m_character->FootRadius())SwitchState(clbNoLadder); Fvector vel; m_character->GetVelocity(vel); if(vel.y>EPS_S) { m_character->ApplyForce(0.f,-m_character->Mass()*ph_world->Gravity(),0.f); } //if(to_ax-m_character->FootRadius()>out_dist) // SwitchState((clbNone)); //if(fis_zero(control_a)) // m_character->ApplyForce(d,m_character->Mass()); }
void CDamageManager::load_section(LPCSTR section,CInifile* ini) { string32 buffer; CKinematics *kinematics = smart_cast<CKinematics*>(m_object->Visual()); CInifile::Sect &damages = ini->r_section(section); for (CInifile::SectCIt i=damages.Data.begin(); damages.Data.end() != i; ++i) { if (xr_strcmp(*(*i).first,"default")) { // read all except default line VERIFY (m_object); int bone = kinematics->LL_BoneID(i->first); R_ASSERT2 (BI_NONE != bone, *(*i).first); CBoneInstance &bone_instance = kinematics->LL_GetBoneInstance(u16(bone)); bone_instance.set_param (0,(float)atof(_GetItem(*(*i).second,0,buffer))); bone_instance.set_param (1,(float)atoi(_GetItem(*(*i).second,1,buffer))); bone_instance.set_param (2,(float)atof(_GetItem(*(*i).second,2,buffer))); if (_GetItemCount(*(*i).second) < 4) { bone_instance.set_param (3,(float)atof(_GetItem(*(*i).second,0,buffer))); } else { bone_instance.set_param (3,(float)atof(_GetItem(*(*i).second,3,buffer))); } if(0==bone && (fis_zero(bone_instance.get_param(0)) || fis_zero(bone_instance.get_param(2)) ) ){ string256 error_str; sprintf_s(error_str,"hit_scale and wound_scale for root bone cannot be zero. see section [%s]",section); R_ASSERT2(0,error_str); } } } }
bool CSE_ALifeTraderAbstract::check_inventory_consistency () { int volume = 0; float mass = 0.f; xr_vector<ALife::_OBJECT_ID>::const_iterator I = base()->children.begin(); xr_vector<ALife::_OBJECT_ID>::const_iterator E = base()->children.end(); for ( ; I != E; ++I) { CSE_ALifeDynamicObject *object = ai().alife().objects().object(*I,true); if (!object) continue; CSE_ALifeInventoryItem *item = smart_cast<CSE_ALifeInventoryItem*>(object); if (!item) continue; volume += item->m_iVolume; mass += item->m_fMass; } R_ASSERT2 (fis_zero(m_fCumulativeItemMass - mass,EPS_L),base()->name_replace()); if (!fis_zero(m_fCumulativeItemMass - mass,EPS_L)) return (false); R_ASSERT2 (m_iCumulativeItemVolume == volume,base()->name_replace()); if (m_iCumulativeItemVolume != volume) return (false); #ifdef DEBUG // if (psAI_Flags.test(aiALife)) { // Msg ("[LSS] [%s] inventory is consistent [%f][%d]",base()->name_replace(),mass,volume); // } #endif return (true); }
void calc_cam_diff_rot(Fmatrix item_transform, Fvector diff, Fvector& res) { Fmatrix cam_m; cam_m.i.set (Device.vCameraRight); cam_m.j.set (Device.vCameraTop); cam_m.k.set (Device.vCameraDirection); cam_m.c.set (Device.vCameraPosition); Fmatrix R; R.identity (); if(!fis_zero(diff.x)) { R.rotation(cam_m.i,diff.x); }else if(!fis_zero(diff.y)) { R.rotation(cam_m.j,diff.y); }else if(!fis_zero(diff.z)) { R.rotation(cam_m.k,diff.z); }; Fmatrix item_transform_i; item_transform_i.invert (item_transform); R.mulB_43(item_transform); R.mulA_43(item_transform_i); R.getHPB (res); res.mul (180.0f/PI); }
void CPHMovementControl::CorrectPathDir (const Fvector &real_path_dir,const xr_vector<DetailPathManager::STravelPathPoint> & path,int index,Fvector &corrected_path_dir) { const float epsilon=0.1f; float plane_motion=dXZMag(real_path_dir); if(fis_zero(plane_motion,epsilon)) { if(!fis_zero(plane_motion,EPS)) { corrected_path_dir.set(real_path_dir); corrected_path_dir.y=0.f; corrected_path_dir.mul(1.f/plane_motion); } else if(index!=m_path_size-1) { corrected_path_dir.sub(path[index+1].position,path[index].position); corrected_path_dir.normalize_safe(); CorrectPathDir(corrected_path_dir,path,index+1,corrected_path_dir); } else { corrected_path_dir.set(real_path_dir); } } else { corrected_path_dir.set(real_path_dir); } }
void CStalkerAnimationManager::play_legs () { float speed = 0.f; bool first_time = !legs().animation(); bool result = legs().animation(assign_legs_animation()); if (!first_time && !result && legs().blend()) { float amount = legs().blend()->blendAmount; m_previous_speed = (m_current_speed - m_previous_speed)*amount + m_previous_speed; } legs().play (m_skeleton_animated,legs_play_callback,&object(),!fis_zero(m_current_speed),false); if (result && legs().blend()) { float amount = legs().blend()->blendAmount; speed = (m_current_speed - m_previous_speed)*amount + m_previous_speed; } if (fis_zero(speed)) return; if (!legs().blend()) return; object().movement().setup_speed_from_animation (speed); }
bool CDetailPathManager::valid () const { bool b = true; b = b && !m_path.empty(); if (m_state_patrol_path) b = b && (fis_zero(m_path[m_last_patrol_point].position.distance_to_xz_sqr(m_corrected_dest_position))); else b = b && fis_zero(m_path.back().position.distance_to_xz_sqr(m_corrected_dest_position)); // b = b && fis_zero(m_path.back().position.distance_to_xz_sqr(m_dest_position)); return (b); }
void CSE_ALifeInventoryItem::UPDATE_Write (NET_Packet &tNetPacket) { if (!m_u8NumItems) { tNetPacket.w_u8 (0); return; } mask_num_items num_items; num_items.mask = 0; num_items.num_items = m_u8NumItems; R_ASSERT2 ( num_items.num_items < (u8(1) << 5), make_string("%d",num_items.num_items) ); if (State.enabled) num_items.mask |= inventory_item_state_enabled; if (fis_zero(State.angular_vel.square_magnitude())) num_items.mask |= inventory_item_angular_null; if (fis_zero(State.linear_vel.square_magnitude())) num_items.mask |= inventory_item_linear_null; //if (anim_use) num_items.mask |= animated; tNetPacket.w_u8 (num_items.common); /*if(check(num_items.mask,animated)) { tNetPacket.w_float (m_blend_timeCurrent); }*/ { tNetPacket.w_vec3 (State.force); tNetPacket.w_vec3 (State.torque); tNetPacket.w_vec3 (State.position); tNetPacket.w_float (State.quaternion.x); tNetPacket.w_float (State.quaternion.y); tNetPacket.w_float (State.quaternion.z); tNetPacket.w_float (State.quaternion.w); if (!check(num_items.mask,inventory_item_angular_null)) { tNetPacket.w_float (State.angular_vel.x); tNetPacket.w_float (State.angular_vel.y); tNetPacket.w_float (State.angular_vel.z); } if (!check(num_items.mask,inventory_item_linear_null)) { tNetPacket.w_float (State.linear_vel.x); tNetPacket.w_float (State.linear_vel.y); tNetPacket.w_float (State.linear_vel.z); } } tNetPacket.w_u8(1); // not freezed - doesn't mean anything... };
void CWeaponShotEffector::Initialize(float max_angle, float relax_speed, float max_angle_horz, float step_angle_horz, float angle_frac) { fRelaxSpeed = _abs(relax_speed); VERIFY(!fis_zero(fRelaxSpeed)); fAngleVertMax = _abs(max_angle); VERIFY(!fis_zero(fAngleVertMax)); fAngleVertFrac = _abs(angle_frac); fAngleHorzMax = max_angle_horz; fAngleHorzStep = step_angle_horz; }
void CActor::cam_Lookout ( const Fmatrix &xform, float camera_height ) { if (!fis_zero(r_torso_tgt_roll)) { float w,h; float c = viewport_near(w,h); w/=2.f;h/=2.f; float alpha = r_torso_tgt_roll/2.f; float radius = camera_height*0.5f; // init valid angle float valid_angle = alpha; Fvector bc,bd; Fmatrix33 mat; get_cam_oob( bc, bd, mat, xform, r_torso, alpha, radius, c ); /* xrXRC xrc ; xrc.box_options (0) ; xrc.box_query (Level().ObjectSpace.GetStaticModel(), bc, bd) ; u32 tri_count = xrc.r_count(); */ //if (tri_count) { float da = 0.f; BOOL bIntersect = FALSE; Fvector ext = {w,h,VIEWPORT_NEAR/2}; Fvector pt; calc_gl_point ( pt, xform, radius, alpha ); if ( test_point( pt, mat, ext, this ) ) { da = PI/1000.f; if (!fis_zero(r_torso.roll)) da *= r_torso.roll/_abs(r_torso.roll); for (float angle=0.f; _abs(angle)<_abs(alpha); angle+=da) { Fvector pt; calc_gl_point( pt, xform, radius, angle ); if (test_point( pt, mat,ext, this )) { bIntersect=TRUE; break; } } valid_angle = bIntersect?angle:alpha; } } r_torso.roll = valid_angle*2.f; r_torso_tgt_roll = r_torso.roll; } else { r_torso_tgt_roll = 0.f; r_torso.roll = 0.f; } }
void CHangingLamp::UpdateCL () { inherited::UpdateCL (); if(m_pPhysicsShell) m_pPhysicsShell->InterpolateGlobalTransform(&XFORM()); if (Alive() && light_render->get_active()){ if(Visual()) PKinematics(Visual())->CalculateBones(); // update T&R from light (main) bone Fmatrix xf; if (light_bone!=BI_NONE){ Fmatrix& M = smart_cast<CKinematics*>(Visual())->LL_GetTransform(light_bone); xf.mul (XFORM(),M); VERIFY(!fis_zero(DET(xf))); }else{ xf.set (XFORM()); } light_render->set_rotation (xf.k,xf.i); light_render->set_position (xf.c); if (glow_render)glow_render->set_position (xf.c); // update T&R from ambient bone if (light_ambient){ if (ambient_bone!=light_bone){ if (ambient_bone!=BI_NONE){ Fmatrix& M = smart_cast<CKinematics*>(Visual())->LL_GetTransform(ambient_bone); xf.mul (XFORM(),M); VERIFY(!fis_zero(DET(xf))); }else{ xf.set (XFORM()); } } light_ambient->set_rotation (xf.k,xf.i); light_ambient->set_position (xf.c); } if (lanim){ int frame; u32 clr = lanim->CalculateBGR(Device.fTimeGlobal,frame); // возвращает в формате BGR Fcolor fclr; fclr.set ((float)color_get_B(clr),(float)color_get_G(clr),(float)color_get_R(clr),1.f); fclr.mul_rgb (fBrightness/255.f); light_render->set_color (fclr); if (glow_render) glow_render->set_color (fclr); if (light_ambient) { fclr.mul_rgb (ambient_power); light_ambient->set_color(fclr); } } } }
//------------------------------------------------------------------------------ // IO - routines //------------------------------------------------------------------------------ void SGameMtl::Save(IWriter& fs) { Flags.set (flSlowDown, !fis_zero(1.f-fFlotationFactor,EPS_L)); Flags.set (flShootable, fis_zero(fShootFactor,EPS_L)); Flags.set (flTransparent, fis_zero(fVisTransparencyFactor,EPS_L)); Flags.set (flInjurious, !fis_zero(fInjuriousSpeed,EPS_L)); fs.open_chunk (GAMEMTL_CHUNK_MAIN); fs.w_u32 (ID); fs.w_stringZ (m_Name); fs.close_chunk (); fs.open_chunk (GAMEMTL_CHUNK_DESC); fs.w_stringZ (m_Desc); fs.close_chunk (); fs.open_chunk (GAMEMTL_CHUNK_FLAGS); fs.w_u32 (Flags.get()); fs.close_chunk (); fs.open_chunk (GAMEMTL_CHUNK_PHYSICS); fs.w_float (fPHFriction); fs.w_float (fPHDamping); fs.w_float (fPHSpring); fs.w_float (fPHBounceStartVelocity); fs.w_float (fPHBouncing); fs.close_chunk (); fs.open_chunk (GAMEMTL_CHUNK_FACTORS); fs.w_float (fShootFactor); fs.w_float (fBounceDamageFactor); fs.w_float (fVisTransparencyFactor); fs.w_float (fSndOcclusionFactor); fs.close_chunk (); fs.open_chunk (GAMEMTL_CHUNK_FACTORS_MP); fs.w_float (fShootFactorMP); fs.close_chunk (); fs.open_chunk (GAMEMTL_CHUNK_FLOTATION); fs.w_float (fFlotationFactor); fs.close_chunk (); fs.open_chunk (GAMEMTL_CHUNK_INJURIOUS); fs.w_float (fInjuriousSpeed); fs.close_chunk (); fs.open_chunk (GAMEMTL_CHUNK_DENSITY); fs.w_float (fDensityFactor); fs.close_chunk (); }
void CPHMovementControl::PathDIrPoint(const xr_vector<DetailPathManager::STravelPathPoint> &path, int index, float distance, float precesition, Fvector &dir ) { Fvector to_path_point; Fvector corrected_path_dir;CorrectPathDir(GetPathDir(),path,index,corrected_path_dir); to_path_point.sub(vPathPoint,vPosition); //_new position float mag=to_path_point.magnitude(); if(mag<EPS) //near the point { if(0==index||m_path_size-1==index) //on path eidge { dir.set(corrected_path_dir);//?? return; } dir.sub(path[index].position,path[index-1].position); dir.normalize_safe(); dir.add(corrected_path_dir); dir.normalize_safe(); } to_path_point.mul(1.f/mag); if(m_path_size-1==index)//on_path_edge { dir.set(to_path_point); return; } if(mag<EPS||fis_zero(dXZMag(to_path_point),EPS)) { dir.set(corrected_path_dir); return;//mean dir } Fvector tangent; tangent.crossproduct(Fvector().set(0,1,0),to_path_point); VERIFY(!fis_zero(tangent.magnitude())); tangent.normalize(); if(dir.square_magnitude()>EPS) { if(tangent.dotproduct(dir)<0.f)tangent.invert(); } else { if(tangent.dotproduct(corrected_path_dir)<0.f)tangent.invert(); } if(mag>FootRadius())to_path_point.mul(precesition); else to_path_point.mul(mag*precesition); dir.add(tangent,to_path_point); dir.normalize_safe(); }
////////////////////////////////////////////////////////////////////////// // CMonsterEffector ////////////////////////////////////////////////////////////////////////// CSleepEffectorPP::CSleepEffectorPP(const SPPInfo &ppi, float life_time, float attack_time, float release_time) : CEffectorPP(EEffectorPPType(SLEEP_EFFECTOR_TYPE_ID), life_time) { state = ppi; m_total = life_time; m_attack = ((fis_zero(attack_time)) ? 0.5f : attack_time); m_release = ((fis_zero(release_time)) ? 0.5f : release_time); VERIFY(!fsimilar(m_release, 1.0f)); VERIFY(!fis_zero(m_attack)); m_eSleepState = BEGIN_SLEEP; }
////////////////////////////////////////////////////////////////////////// // CMonsterEffector ////////////////////////////////////////////////////////////////////////// CMonsterEffector::CMonsterEffector(const SPPInfo &ppi, float life_time, float attack_time, float release_time, float spec_factor) : CEffectorPP(EEffectorPPType(eCEHit), life_time) { state = ppi; m_total = life_time; m_attack = ((fis_zero(attack_time)) ? 0.5f : attack_time); m_release = ((fis_zero(release_time)) ? 0.5f : release_time); m_spec_factor = spec_factor; VERIFY(!fsimilar(m_release, 1.0f)); VERIFY(!fis_zero(m_attack)); }
void CWeaponStatMgun::Load(LPCSTR section) { inheritedPH::Load(section); inheritedShooting::Load (section); m_sounds.LoadSound(section,"snd_shoot", "sndShot", false, SOUND_TYPE_WEAPON_SHOOTING); m_Ammo->Load(pSettings->r_string(section, "ammo_class"), 0); camMaxAngle = pSettings->r_float (section,"cam_max_angle" ); camMaxAngle = _abs( deg2rad (camMaxAngle) ); camRelaxSpeed = pSettings->r_float (section,"cam_relax_speed" ); camRelaxSpeed = _abs( deg2rad (camRelaxSpeed) ); VERIFY( !fis_zero(camMaxAngle) ); VERIFY( !fis_zero(camRelaxSpeed) ); }
bool CScriptGameObject::is_body_turning() const { CCustomMonster *monster = smart_cast<CCustomMonster*>(&object()); if (!monster) { ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "CGameObject : cannot access class member is_turning!"); return (false); } CAI_Stalker *stalker = smart_cast<CAI_Stalker*>(monster); if (!stalker) return (!fis_zero(angle_difference(monster->movement().body_orientation().target.yaw, monster->movement().body_orientation().current.yaw))); else return (!fis_zero(angle_difference(stalker->movement().head_orientation().target.yaw, stalker->movement().head_orientation().current.yaw)) || !fis_zero(angle_difference(monster->movement().body_orientation().target.yaw, monster->movement().body_orientation().current.yaw))); }
IC void tri_plane(const Fvector &v0, const Fvector &v1, const Fvector &v2, Fplane &p ) { p.n.mknormal ( v0, v1, v2 ); VERIFY( !fis_zero( p.n.magnitude() ) ); p.n.invert(); p.d = -p.n.dotproduct( v0 ); }
void CWeaponShotEffector::Relax() { float time_to_relax = _abs(m_angle_vert) / m_cam_recoil.RelaxSpeed; float relax_speed_horz = ( fis_zero(time_to_relax) )? 0.0f : _abs(m_angle_horz) / time_to_relax; float dt = Device.fTimeDelta; if ( m_angle_horz >= 0.0f ) // h { m_angle_horz -= relax_speed_horz * dt; } else { m_angle_horz += relax_speed_horz * dt; } if ( m_angle_vert >= 0.0f ) // v { m_angle_vert -= m_cam_recoil.RelaxSpeed * dt; if ( m_angle_vert < 0.0f ) { m_angle_vert = 0.0f; m_actived = false; } } else { m_angle_vert += m_cam_recoil.RelaxSpeed * dt; if ( m_angle_vert > 0.0f ) { m_angle_vert = 0.0f; m_actived = false; } } }
void CParticlesPlayer::StartParticles(const shared_str& particles_name, u16 bone_num, const Fmatrix& xform, u16 sender_id, int life_time, bool auto_stop) { VERIFY(fis_zero(xform.c.magnitude())); R_ASSERT(*particles_name); CObject* object = m_self_object; VERIFY(object); SBoneInfo* pBoneInfo = get_nearest_bone_info(smart_cast<CKinematics*>(object->Visual()),bone_num); if(!pBoneInfo) return; SParticlesInfo &particles_info =*pBoneInfo->AppendParticles(object,particles_name); particles_info.sender_id = sender_id; particles_info.life_time=auto_stop ? life_time : u32(-1); xform.getHPB(particles_info.angles); Fmatrix m; m.setHPB(particles_info.angles.x,particles_info.angles.y,particles_info.angles.z); GetBonePos(object,pBoneInfo->index,pBoneInfo->offset,m.c); particles_info.ps->UpdateParent(m,zero_vel); if(!particles_info.ps->IsPlaying()) particles_info.ps->Play (); m_bActiveBones = true; }
void CBaseMonster::load_effector(LPCSTR section, LPCSTR line, SAttackEffector &effector) { LPCSTR ppi_section = pSettings->r_string(section, line); effector.ppi.duality.h = pSettings->r_float(ppi_section,"duality_h"); effector.ppi.duality.v = pSettings->r_float(ppi_section,"duality_v"); effector.ppi.gray = pSettings->r_float(ppi_section,"gray"); effector.ppi.blur = pSettings->r_float(ppi_section,"blur"); effector.ppi.noise.intensity = pSettings->r_float(ppi_section,"noise_intensity"); effector.ppi.noise.grain = pSettings->r_float(ppi_section,"noise_grain"); effector.ppi.noise.fps = pSettings->r_float(ppi_section,"noise_fps"); VERIFY(!fis_zero(effector.ppi.noise.fps)); sscanf(pSettings->r_string(ppi_section,"color_base"), "%f,%f,%f", &effector.ppi.color_base.r, &effector.ppi.color_base.g, &effector.ppi.color_base.b); sscanf(pSettings->r_string(ppi_section,"color_gray"), "%f,%f,%f", &effector.ppi.color_gray.r, &effector.ppi.color_gray.g, &effector.ppi.color_gray.b); sscanf(pSettings->r_string(ppi_section,"color_add"), "%f,%f,%f", &effector.ppi.color_add.r, &effector.ppi.color_add.g, &effector.ppi.color_add.b); effector.time = pSettings->r_float(ppi_section,"time"); effector.time_attack = pSettings->r_float(ppi_section,"time_attack"); effector.time_release = pSettings->r_float(ppi_section,"time_release"); effector.ce_time = pSettings->r_float(ppi_section,"ce_time"); effector.ce_amplitude = pSettings->r_float(ppi_section,"ce_amplitude"); effector.ce_period_number = pSettings->r_float(ppi_section,"ce_period_number"); effector.ce_power = pSettings->r_float(ppi_section,"ce_power"); }
void CPurchaseList::process (const CGameObject &owner, const shared_str &name, const u32 &count, const float &probability) { VERIFY3 (count,"Invalid count for section in the purchase list",*name); VERIFY3 (!fis_zero(probability,EPS_S),"Invalid probability for section in the purchase list",*name); const Fvector &position = owner.Position(); const u32 &level_vertex_id = owner.ai_location().level_vertex_id(); const ALife::_OBJECT_ID &id = owner.ID(); CRandom random((u32)(CPU::QPC() & u32(-1))); u32 j = 0; for (u32 i=0; i<count; ++i) { if (random.randF() > probability) continue; ++j; Level().spawn_item (*name,position,level_vertex_id,id,false); } DEFICITS::const_iterator I = m_deficits.find(name); VERIFY3 (I == m_deficits.end(),"Duplicate section in the purchase list",*name); m_deficits.insert ( std::make_pair( name, (float)count*probability / _max((float)j,min_deficit_factor) ) ); }
void CCoverEvaluatorBest::evaluate (const CCoverPoint *cover_point, float weight) { if (fis_zero(weight)) return; float enemy_distance = m_enemy_position.distance_to(cover_point->position()); if ((enemy_distance <= m_min_distance) && (m_current_distance > enemy_distance)) return; if((enemy_distance >= m_max_distance) && (m_current_distance < enemy_distance)) return; Fvector direction; float y,p; direction.sub (m_enemy_position,cover_point->position()); direction.getHP (y,p); float cover_value = ai().level_graph().cover_in_direction(y,cover_point->level_vertex_id()); float value = cover_value; if (ai().level_graph().neighbour_in_direction(direction,cover_point->level_vertex_id())) value += 10.f; value /= weight; if ((value > m_best_value) || ((value == m_best_value) && (cover_point > m_selected))) return; m_selected = cover_point; m_best_value = value; }
bool EDetail::Load(IReader& F) { // check version R_ASSERT (F.find_chunk(DETOBJ_CHUNK_VERSION)); u32 version = F.r_u32(); if (version!=DETOBJ_VERSION){ ELog.Msg(mtError,"EDetail: unsupported version."); return false; } // references string256 buf; R_ASSERT (F.find_chunk(DETOBJ_CHUNK_REFERENCE)); F.r_stringZ (buf,sizeof(buf)); // scale R_ASSERT (F.find_chunk(DETOBJ_CHUNK_SCALE_LIMITS)); m_fMinScale = F.r_float(); if (fis_zero(m_fMinScale)) m_fMinScale = 0.1f; m_fMaxScale = F.r_float(); if (m_fMaxScale<m_fMinScale) m_fMaxScale = m_fMinScale; // density factor if (F.find_chunk(DETOBJ_CHUNK_DENSITY_FACTOR)) m_fDensityFactor= F.r_float(); if (F.find_chunk(DETOBJ_CHUNK_FLAGS)) m_Flags.assign (F.r_u32()); // update object return Update(buf); }
void CSoundRender_Emitter::start(ref_sound* _owner, BOOL _loop, float delay) { starting_delay = delay; VERIFY (_owner); owner_data = _owner->_p; VERIFY(owner_data); // source = (CSoundRender_Source*)owner_data->handle; p_source.position.set (0,0,0); p_source.min_distance = source()->m_fMinDist; // DS3D_DEFAULTMINDISTANCE; p_source.max_distance = source()->m_fMaxDist; // 300.f; p_source.base_volume = source()->m_fBaseVolume;// 1.f p_source.volume = 1.f; // 1.f p_source.freq = 1.f; p_source.max_ai_distance= source()->m_fMaxAIDist; // 300.f; if (fis_zero(delay,EPS_L)) { m_current_state = _loop?stStartingLooped:stStarting; }else{ m_current_state = _loop?stStartingLoopedDelayed:stStartingDelayed; fTimeToPropagade = SoundRender->Timer.GetElapsed_sec(); } bStopping = FALSE; bRewind = FALSE; }
bool CIKFoot::make_shift( Fmatrix &xm,const Fvector &cl_point, bool collide, const Fplane &p, const Fvector &pick_dir )const { Fvector shift = pick_dir; //Fvector toe; ToePosition( toe ); xm.transform_tiny( toe ); Fvector point; xm.transform_tiny( point, cl_point ); float dot = p.n.dotproduct( shift ); if( _abs( dot ) < min_dot ) { shift.add( Fvector( ).mul( p.n, min_dot - _abs( dot ) ) ); dot = p.n.dotproduct( shift ); } VERIFY( !fis_zero( dot ) ); float shift_m = ( -p.d - p.n.dotproduct( point ) )/dot; if(collide && shift_m > 0.f ) return false; clamp( shift_m, -collide_dist, collide_dist ); shift.mul( shift_m ); xm.c.add( shift ); #if 0 if(shift_m > 0.f) { DBG_OpenCashedDraw(); DBG_DrawLine( toe, Fvector().add( toe, shift ), D3DCOLOR_XRGB( 255, 255, 255 ) ); DBG_ClosedCashedDraw( 1000 ); } #endif return true; }
void CControlAnimationBase::ValidateAnimation() { SAnimItem *item_it = m_anim_storage[cur_anim_info().get_motion()]; bool is_moving_anim = !fis_zero(item_it->velocity.velocity.linear); bool is_moving_on_path = m_object->control().path_builder().is_moving_on_path(); if (is_moving_on_path && is_moving_anim) { m_object->dir().use_path_direction(cur_anim_info().get_motion() == eAnimDragCorpse); return; } if (!is_moving_on_path && is_moving_anim) { cur_anim_info().set_motion(eAnimStandIdle); m_object->move().stop (); return; } if (is_moving_on_path && !is_moving_anim) { m_object->move().stop (); return; } if (!m_object->control().direction().is_turning() && ((cur_anim_info().get_motion() == eAnimStandTurnLeft) || (cur_anim_info().get_motion() == eAnimStandTurnRight))) { cur_anim_info().set_motion(eAnimStandIdle); return; } }
void CCoverEvaluatorBestByTime::evaluate (const CCoverPoint *cover_point, float weight) { if (fis_zero(weight)) return; float enemy_distance = m_enemy_position.distance_to(cover_point->position()); float value = 0.f; if (enemy_distance <= m_min_distance) value += 100 + m_min_distance - enemy_distance; if (enemy_distance >= m_max_distance) value += 100.f + enemy_distance - m_max_distance; Fvector direction; // float y,p; direction.sub (m_enemy_position,cover_point->position()); if (ai().level_graph().neighbour_in_direction(direction,cover_point->level_vertex_id())) value += 10.f; value /= weight; if (value >= m_best_value) return; m_selected = cover_point; m_best_value = value; }
void CPHCollisionDamageReceiver::CollisionCallback(bool& do_colide,bool bo1,dContact& c,SGameMtl* material_1,SGameMtl* material_2) { if(material_1->Flags.test(SGameMtl::flPassable)||material_2->Flags.test(SGameMtl::flPassable))return; dBodyID b1 = dGeomGetBody(c.geom.g1) ; dBodyID b2 = dGeomGetBody(c.geom.g2) ; dxGeomUserData *ud_self = bo1 ? retrieveGeomUserData(c.geom.g1):retrieveGeomUserData(c.geom.g2); dxGeomUserData *ud_damager = bo1 ? retrieveGeomUserData(c.geom.g2):retrieveGeomUserData(c.geom.g1); SGameMtl *material_self = bo1 ? material_1:material_2; SGameMtl *material_damager = bo1 ? material_2:material_1; VERIFY (ud_self); CPhysicsShellHolder *o_self = ud_self->ph_ref_object; CPhysicsShellHolder *o_damager = NULL;if(ud_damager)o_damager=ud_damager->ph_ref_object; u16 source_id = o_damager ? o_damager->ID():u16(-1); CPHCollisionDamageReceiver *dr =o_self->PHCollisionDamageReceiver(); VERIFY2(dr,"wrong callback"); float damager_material_factor=material_damager->fBounceDamageFactor; if(ud_damager&&ud_damager->ph_object&&ud_damager->ph_object->CastType()==CPHObject::tpCharacter) { CCharacterPhysicsSupport* phs=o_damager->character_physics_support(); if(phs->IsSpecificDamager())damager_material_factor=phs->BonceDamageFactor(); } float dfs=(material_self->fBounceDamageFactor+damager_material_factor); if(fis_zero(dfs)) return; Fvector dir;dir.set(*(Fvector*)c.geom.normal); Fvector pos; pos.sub(*(Fvector*)c.geom.pos,*(Fvector*)dGeomGetPosition(bo1 ? c.geom.g1:c.geom.g2));//it is not true pos in bone space dr->Hit(source_id,ud_self->bone_id,E_NL(b1,b2,c.geom.normal)*damager_material_factor/dfs,dir,pos); }
void CCustomZone::OnMove() { if(m_dwLastTimeMoved == 0) { m_dwLastTimeMoved = Device.dwTimeGlobal; m_vPrevPos.set(Position()); } else { float time_delta = float(Device.dwTimeGlobal - m_dwLastTimeMoved)/1000.f; m_dwLastTimeMoved = Device.dwTimeGlobal; Fvector vel; if(fis_zero(time_delta)) vel = zero_vel; else { vel.sub(Position(), m_vPrevPos); vel.div(time_delta); } if (m_pIdleParticles) m_pIdleParticles->UpdateParent(XFORM(), vel); if(m_pLight && m_pLight->get_active()) m_pLight->set_position(Position()); if(m_pIdleLight && m_pIdleLight->get_active()) m_pIdleLight->set_position(Position()); } }