Exemplo n.º 1
0
CPHCallOnStepCondition::CPHCallOnStepCondition()
{
	if(physics_world())
		set_step(physics_world()->StepsNum());
	else		
		set_step(0);
}
void CDestroyablePhysicsObject::Destroy()
{
	VERIFY(!physics_world()->Processing());
	const CGameObject *who_object = smart_cast<const CGameObject*>(FatalHit().initiator());
	callback(GameObject::eDeath)(lua_game_object(),who_object  ? who_object : 0);
	CPHDestroyable::Destroy(ID(),"physic_destroyable_object");
	if(m_destroy_sound._handle())
	{
		m_destroy_sound.play_at_pos(this,Position());
	}
	if(*m_destroy_particles)
	{		
			//Fvector dir;dir.set(0,1,0);
		Fmatrix m;m.identity();
		/////////////////////////////////////////////////
		m.j.set(0,1.f,0);
		///////////////////////////////////////////////

		Fvector hdir;hdir.set(CPHDestroyable::FatalHit().direction());

		if(fsimilar(_abs(m.j.dotproduct(hdir)),1.f,EPS_L))
		{
			do {
				hdir.random_dir();
			} while(fsimilar(_abs(m.j.dotproduct(hdir)),1.f,EPS_L));
		}
		m.i.crossproduct(m.j,hdir);m.i.normalize();
		m.k.crossproduct(m.i,m.j);
			StartParticles(m_destroy_particles,m,ID());
	}
	SheduleRegister();
}
Exemplo n.º 3
0
void CBlackGraviArtefact::UpdateCLChild() 
{
	VERIFY(!physics_world()->Processing());
	inherited::UpdateCLChild	();

	if (getVisible() && m_pPhysicsShell) {
		if (m_bStrike) {
			Fvector	P; 
			P.set(Position());
			feel_touch_update(P,m_fRadius);

			GraviStrike();

			CParticlesObject* pStaticPG;
			pStaticPG = CParticlesObject::Create(*m_sParticleName,TRUE);
			Fmatrix pos; 
			pos.set(XFORM()); 
			Fvector vel; 
			//vel.sub(Position(),ps_Element(0).vPosition); 
			//vel.div((Level().timeServer()-ps_Element(0).dwTime)/1000.f);
			vel.set(0,0,0);
			pStaticPG->UpdateParent(pos, vel); 
			pStaticPG->Play(false);

			m_bStrike = false;
		}
	}else if(H_Parent()) XFORM().set(H_Parent()->XFORM());
}
Exemplo n.º 4
0
void CArtefact::UpdateWorkload		(u32 dt) 
{

	VERIFY(!physics_world()->Processing());
	// particles - velocity
	Fvector vel = {0, 0, 0};
	if (H_Parent()) 
	{
		CPhysicsShellHolder* pPhysicsShellHolder = smart_cast<CPhysicsShellHolder*>(H_Parent());
		if(pPhysicsShellHolder) pPhysicsShellHolder->PHGetLinearVell(vel);
	}
	CParticlesPlayer::SetParentVel	(vel);

	// 
	UpdateLights					();
	if(m_activationObj && m_activationObj->IsInProgress())	{
		CPHUpdateObject::Activate			();
		m_activationObj->UpdateActivation	();
		return;
	}

	// custom-logic
	if(!CAttachableItem::enabled())
		UpdateCLChild					();
	
}
void CtaArtefactActivation::UpdateActivation()
{
	if (!IsInProgress())
		return;

	VERIFY(!physics_world()->Processing());
	m_cur_state_time				+=	Device.fTimeDelta;
	if(m_cur_state_time				>=	m_activation_states[int(m_cur_activation_state)].m_time){
		m_cur_activation_state		=	(EActivationStates)(int)(m_cur_activation_state+1);
		
		if(m_cur_activation_state == eMax){
			m_cur_activation_state = eNone;
			//m_af->processing_deactivate			();
			//m_af->DestroyObject();
		}

		m_cur_state_time	= 0.0f;
		ChangeEffects				();


	if(m_cur_activation_state==eSpawnZone && OnServer())
		SpawnAnomaly	();

	}
	UpdateEffects				();
}
Exemplo n.º 6
0
void CExplosive::StopLight		()
{
	if	(m_pLight){
		VERIFY						(!physics_world()->Processing());
		m_pLight->set_active		(false);
		LightDestroy				();
	}
}
Exemplo n.º 7
0
void CArtefact::OnH_B_Independent(bool just_before_destroy) 
{
	VERIFY(!physics_world()->Processing());
	inherited::OnH_B_Independent(just_before_destroy);

	StartLights();
	SwitchAfParticles	(true);
}
Exemplo n.º 8
0
void CArtefact::StopLights()
{
	VERIFY(!physics_world()->Processing());
	if(!m_bLightsEnabled || !m_pTrailLight) 
		return;

	m_pTrailLight->set_active	(false);
	m_pTrailLight.destroy		();
}
Exemplo n.º 9
0
void  CScenePhyscs::CreateWorld			()
{


    VERIFY(!physics_world());
    set_mtl_lib(&GMLib);


    CRenderDeviceBase *rd = &EDevice  ;
    VERIFY(m_object_space);
	create_physics_world( false, m_object_space,    0, rd );
}
Exemplo n.º 10
0
void CExplosive::UpdateCL() 
{
	//VERIFY(!this->getDestroy());
	VERIFY(!physics_world()->Processing());
	if(!m_explosion_flags.test(flExploding)) return;// !m_bExploding
	if(m_explosion_flags.test(flExploded))
	{
		CGameObject* go=cast_game_object();
		go->processing_deactivate();
		m_explosion_flags.set(flExploding,FALSE);//m_bExploding = false;
		OnAfterExplosion();
		return;
	}
	//время вышло, убираем объект взрывчатки
	if(m_fExplodeDuration < 0.f&&m_blasted_objects.empty()) 
	{
		m_explosion_flags.set(flExploded,TRUE);
		
		
		StopLight();
		

//		Msg("---------CExplosive OnAfterExplosion [%d] frame[%d]",cast_game_object()->ID(), Device.dwFrame);

	} 
	else
	{		
		m_fExplodeDuration -= Device.fTimeDelta;
		if (!m_bHideInExplosion && !m_bAlreadyHidden)
		{
			if (m_fExplodeHideDurationMax <= (m_fExplodeDurationMax - m_fExplodeDuration))
			{
				HideExplosive();
			}
		}
		UpdateExplosionPos();
		UpdateExplosionParticles();
		ExplodeWaveProcess();
		//обновить подсветку взрыва
		if(m_pLight && m_pLight->get_active() && m_fLightTime>0)
		{
			if(m_fExplodeDuration > (m_fExplodeDurationMax - m_fLightTime))
			{
				float scale = (m_fExplodeDuration - (m_fExplodeDurationMax - m_fLightTime))/m_fLightTime;
				m_pLight->set_color(m_LightColor.r*scale, m_LightColor.g*scale, m_LightColor.b*scale);
				m_pLight->set_range(m_fLightRange*scale);
			} 
			else
				StopLight();
		}		
	}
}
Exemplo n.º 11
0
    virtual void run() override
    {
        auto clock = std::make_shared<SteppableClock>(3E-3f);
        ClockFactory::get(clock);

        std::unique_ptr<MultiRotorParams> params = MultiRotorParamsFactory::createConfig("SimpleFlight");
        MultiRotor vehicle;
        std::unique_ptr<Environment> environment;
        vehicle.initialize(params.get(), Pose(), 
            GeoPoint(), environment);

        std::vector<UpdatableObject*> vehicles = { &vehicle };
        std::unique_ptr<PhysicsEngineBase> physics_engine(new FastPhysicsEngine());
        PhysicsWorld physics_world(physics_engine.get(), vehicles, 
            static_cast<uint64_t>(clock->getStepSize() * 1E9));

        DroneControllerBase* controller = params->getController();
        testAssert(controller != nullptr, "Controller was null");
        std::string message;
        testAssert(controller->isAvailable(message), message);

        clock->sleep_for(0.04f);
        
        Utils::getSetMinLogLevel(true, 100);

        DirectCancelableBase cancellable(controller, &vehicle);
        controller->enableApiControl(true);
        controller->armDisarm(true, cancellable);
        controller->takeoff(10, cancellable);

        clock->sleep_for(2.0f);

        Utils::getSetMinLogLevel(true);

        controller->moveToPosition(-5, -5, -5, 5, DrivetrainType::MaxDegreeOfFreedom, YawMode(true, 0), -1, 0, cancellable);

        clock->sleep_for(2.0f);


        while (true) {
            clock->sleep_for(0.1f);
            controller->getStatusMessages(messages_);
            for (const auto& status_message : messages_) {
                std::cout << status_message << std::endl;
            }
            messages_.clear();
        }
    }
Exemplo n.º 12
0
void CExplosive::StartLight	()
{

	VERIFY(!physics_world()->Processing());
	if(m_fLightTime>0)
	{
		
//		VERIFY					(!m_pLight);
		LightCreate				();

		m_pLight->set_color		(m_LightColor.r, m_LightColor.g, m_LightColor.b);
		m_pLight->set_range		(m_fLightRange);
		m_pLight->set_position	(m_vExplodePos); 
		m_pLight->set_active	(true);
	}
}
Exemplo n.º 13
0
void CArtefact::StartLights()
{
	VERIFY(!physics_world()->Processing());
	if(!m_bLightsEnabled)		return;

	VERIFY						(m_pTrailLight == NULL);
	m_pTrailLight				= ::Render->light_create();
	bool const b_light_shadow	= !!pSettings->r_bool(cNameSect(), "idle_light_shadow");

	m_pTrailLight->set_shadow	(b_light_shadow);

	m_pTrailLight->set_color	(m_TrailLightColor); 
	m_pTrailLight->set_range	(m_fTrailLightRange);
	m_pTrailLight->set_position	(Position()); 
	m_pTrailLight->set_active	(true);
}
Exemplo n.º 14
0
void	CCar::cam_Update			(float dt, float fov)
{
	VERIFY(!physics_world()->Processing());
	Fvector							P,Da;
	Da.set							(0,0,0);
	//bool							owner = !!Owner();

	XFORM().transform_tiny			(P,m_camera_position);

	switch(active_camera->tag) {
	case ectFirst:
		// rotate head
		if(OwnerActor()) OwnerActor()->Orientation().yaw	= -active_camera->yaw;
		if(OwnerActor()) OwnerActor()->Orientation().pitch	= -active_camera->pitch;
		break;
	case ectChase:						break;
	case ectFree:						break;
	}
	active_camera->f_fov				= fov;
	active_camera->Update				(P,Da);
	Level().Cameras().UpdateFromCamera	(active_camera);
}
Exemplo n.º 15
0
void CNoGravityZone::switchGravity(SZoneObjectInfo& io, bool val)
{
	if(io.object->getDestroy()) return;
	CPhysicsShellHolder* sh= smart_cast<CPhysicsShellHolder*>(io.object);
	if(!sh)return;
	CPhysicsShell* shell=sh->PPhysicsShell();
	if(shell&&shell->isActive())
	{
		shell->set_ApplyByGravity(val);
		if(!val&&shell->get_ApplyByGravity())
		{
			CPhysicsElement* e=shell->get_ElementByStoreOrder(u16(Random.randI(0,shell->get_ElementsNumber())));
			if(e->isActive()){
				e->applyImpulseTrace(Fvector().random_point(e->getRadius()),Fvector().random_dir(),shell->getMass()*physics_world()->Gravity()*fixed_step,e->m_SelfID);

			}

		}
		//shell->SetAirResistance(0.f,0.f);
		//shell->set_DynamicScales(1.f);
		return;
	}
	if(!io.nonalive_object)
	{
		CEntityAlive* ea=smart_cast<CEntityAlive*>(io.object);
		CPHMovementControl*mc=ea->character_physics_support()->movement();
		mc->SetApplyGravity(BOOL(val));
		mc->SetForcedPhysicsControl(!val);
		if(!val&&mc->Environment()==CPHMovementControl::peOnGround)
		{
			Fvector gn;
			mc->GroundNormal(gn);
			mc->ApplyImpulse(gn,mc->GetMass()*physics_world()->Gravity()*fixed_step);
			
		}
	}
}
Exemplo n.º 16
0
float CCar::AntiGravityAccel()
{
	return physics_world()->Gravity()-EffectiveGravity();
}
Exemplo n.º 17
0
void CArtefact::UpdateLights()
{
	VERIFY(!physics_world()->Processing());
	if(!m_bLightsEnabled || !m_pTrailLight ||!m_pTrailLight->get_active()) return;
	m_pTrailLight->set_position(Position());
}
Exemplo n.º 18
0
IC bool CPHCallOnStepCondition::time_out() const
{
	return physics_world()->StepsNum()>m_step;
}
Exemplo n.º 19
0
void CPHCallOnStepCondition::set_steps_interval(u64 steps)
{
	set_step(physics_world()->StepsNum()+steps);
}
Exemplo n.º 20
0
void CPHCallOnStepCondition::set_global_time(float time)
{
	float time_interval=Device.fTimeGlobal-time;
	if(time_interval<0.f)set_step(physics_world()->StepsNum());
	set_time_interval(time_interval);
}
Exemplo n.º 21
0
 void  CScenePhyscs::DestroyWorld			()
 {
	if(physics_world())
    	destroy_physics_world();

  }
Exemplo n.º 22
0
bool	CScenePhyscs ::Simulating			()
{
	return !!physics_world();
}
Exemplo n.º 23
0
void CExplosive::Explode()
{
	VERIFY(0xffff != Initiator());
	VERIFY(m_explosion_flags.test(flReadyToExplode));//m_bReadyToExplode
	VERIFY(!physics_world()->Processing());
	//m_bExploding = true;
	m_explosion_flags.set(flExploding,TRUE);
	cast_game_object()->processing_activate();

	Fvector& pos = m_vExplodePos;
	Fvector& dir = m_vExplodeDir;
#ifdef DEBUG
	if(ph_dbg_draw_mask.test(phDbgDrawExplosions))
	{
		DBG_OpenCashedDraw();
		DBG_DrawPoint(pos,0.3f,D3DCOLOR_XRGB(255,0,0));
	}
#endif
//	Msg("---------CExplosive Explode [%d] frame[%d]",cast_game_object()->ID(), Device.dwFrame);
	OnBeforeExplosion();
	//играем звук взрыва
	Sound->play_at_pos(sndExplode, 0, pos, false);
	
	//показываем эффекты

	m_wallmark_manager.PlaceWallmarks		(pos);

	Fvector									vel;
	smart_cast<CPhysicsShellHolder*>(cast_game_object())->PHGetLinearVell(vel);

	Fmatrix explode_matrix;
	explode_matrix.identity();
	explode_matrix.j.set(dir);
	Fvector::generate_orthonormal_basis(explode_matrix.j, explode_matrix.i, explode_matrix.k);
	explode_matrix.c.set(pos);

	CParticlesObject* pStaticPG; 
	pStaticPG = CParticlesObject::Create(*m_sExplodeParticles,!m_bDynamicParticles); 
	if (m_bDynamicParticles) m_pExpParticle = pStaticPG;
	pStaticPG->UpdateParent(explode_matrix,vel);
	pStaticPG->Play(false);

	//включаем подсветку от взрыва
	StartLight();

	//trace frags
	Fvector frag_dir; 
	
	//////////////////////////////
	//осколки
	//////////////////////////////
	//-------------------------------------
	bool SendHits = false;
	if (OnServer()) SendHits = true;
	else SendHits = false;


	for(int i = 0; i < m_iFragsNum; ++i){
		frag_dir.random_dir	();
		frag_dir.normalize	();
		
		CCartridge cartridge;
		cartridge.param_s.kDist				= 1.f;
		cartridge.param_s.kHit				= 1.f;
//.		cartridge.param_s.kCritical			= 1.f;
		cartridge.param_s.kImpulse			= 1.f;
		cartridge.param_s.kAP				= 1.f;
		cartridge.param_s.fWallmarkSize		= fWallmarkSize;
		cartridge.bullet_material_idx		= GMLib.GetMaterialIdx(WEAPON_MATERIAL_NAME);
		cartridge.m_flags.set				(CCartridge::cfTracer,FALSE);

		Level().BulletManager().AddBullet(	pos, frag_dir, m_fFragmentSpeed,
											m_fFragHit, m_fFragHitImpulse, Initiator(),
											cast_game_object()->ID(), m_eHitTypeFrag, m_fFragsRadius, 
											cartridge, 1.f, SendHits );
	}	

	if (cast_game_object()->Remote()) return;
	
	/////////////////////////////////
	//взрывная волна
	////////////////////////////////
	//---------------------------------------------------------------------
	xr_vector<ISpatial*>	ISpatialResult;
	g_SpatialSpace->q_sphere(ISpatialResult,0,STYPE_COLLIDEABLE,pos,m_fBlastRadius);

	m_blasted_objects.clear	();
	for (u32 o_it=0; o_it<ISpatialResult.size(); o_it++)
	{
		ISpatial*		spatial	= ISpatialResult[o_it];
		//		feel_touch_new(spatial->dcast_CObject());

		CPhysicsShellHolder	*pGameObject = smart_cast<CPhysicsShellHolder*>(spatial->dcast_CObject());
		if(pGameObject && cast_game_object()->ID() != pGameObject->ID()) 
			m_blasted_objects.push_back(pGameObject);
	}

	GetExplosionBox(m_vExplodeSize);
START_PROFILE("explosive/activate explosion box")
	ActivateExplosionBox(m_vExplodeSize,m_vExplodePos);
STOP_PROFILE
	//---------------------------------------------------------------------
#ifdef DEBUG
	if(ph_dbg_draw_mask.test(phDbgDrawExplosions))
	{
		DBG_ClosedCashedDraw(100000);
		
	}
#endif
	//////////////////////////////////////////////////////////////////////////
	// Explode Effector	//////////////
	CGameObject* GO = smart_cast<CGameObject*>(Level().CurrentEntity());
	CActor* pActor = smart_cast<CActor*>(GO);
	if(pActor)
	{
		float dist_to_actor = pActor->Position().distance_to(pos);
		float max_dist		= EFFECTOR_RADIUS;
		if (dist_to_actor < max_dist)
			AddEffector	(pActor, effExplodeHit, effector.effect_sect_name, (max_dist - dist_to_actor) / max_dist );
	}
}
Exemplo n.º 24
0
float CCar::EffectiveGravity()
{
	float g= physics_world()->Gravity();
	if(CPHUpdateObject::IsActive())g*=0.5f;
	return g;
}
Exemplo n.º 25
0
float CCar::GravityFactorImpulse()
{
	return _sqrt(EffectiveGravity()/physics_world()->Gravity());
}