示例#1
0
IC void BoxQuery(Fbox& BB, bool exact)
{
	if (exact) 		XRC.box_options	(CDB::OPT_FULL_TEST);
	else			XRC.box_options	(0);
	Fvector			C,D;
	BB.get_CD		(C,D);
	XRC.box_query	(&Level,C,D);
}
示例#2
0
IC void get_cam_oob( Fvector	&bc, Fvector &bd, Fmatrix33	&mat, const Fmatrix &xform, const SRotation &r_torso, float alpha, float radius, float c )
{
	get_box_mat ( mat, alpha, r_torso );
	Fbox				xf;
	get_q_box( xf, c, alpha, radius );
	xf.xform			( Fbox().set(xf), xform )	;
	// query
	xf.get_CD			(bc,bd)		;
}
示例#3
0
void			ISpatial_DB::initialize(Fbox& BB)
{
	if (0==m_root)			
	{
		// initialize
		Fvector bbc,bbd;
		BB.get_CD				(bbc,bbd);

		bbc.set					(0,0,0);			// generic
		bbd.set					(1024,1024,1024);	// generic

		allocator_pool.reserve	(128);
		m_center.set			(bbc);
		m_bounds				= _max(_max(bbd.x,bbd.y),bbd.z);
		rt_insert_object		= NULL;
		if (0==m_root)	m_root	= _node_create();
		m_root->_init			(NULL);
	}
}
示例#4
0
bool CCharacterPhysicsSupport::CollisionCorrectObjPos(const Fvector& start_from,bool	character_create/*=false*/)
{
	//Fvector shift;shift.sub( start_from, m_EntityAlife.Position() );
	Fvector shift;shift.set(0,0,0);
	Fbox box;
	if(character_create)
		box.set( movement()->Box() );
	else
	{
		if(m_pPhysicsShell)
		{
			VERIFY(m_pPhysicsShell->isFullActive());
			Fvector sz,c;
			get_box( m_pPhysicsShell, mXFORM, sz, c );
			box.setb( Fvector().sub( c, m_EntityAlife.Position() ), Fvector(sz).mul(0.5f) );
			m_pPhysicsShell->DisableCollision();
		}else
			box.set( m_EntityAlife.BoundingBox() );
	}

	Fvector vbox;Fvector activation_pos;
	box.get_CD(activation_pos,vbox);
	shift.add(activation_pos);
	vbox.mul(2.f);
	activation_pos.add(shift,m_EntityAlife.Position());

	CPHActivationShape activation_shape;
	activation_shape.Create(activation_pos,vbox,&m_EntityAlife);
	if( !DoCharacterShellCollide() && !character_create )
	{
		CPHCollideValidator::SetCharacterClassNotCollide(activation_shape);
	}
	if( !character_create )
			activation_shape.set_rotation( mXFORM );
	bool ret = activation_shape.Activate(vbox,1,1.f,M_PI/8.f);
	m_EntityAlife.Position().sub(activation_shape.Position(),shift);

	activation_shape.Destroy();
	if(m_pPhysicsShell)
		m_pPhysicsShell->EnableCollision();
	return ret;
}
void CCharacterPhysicsSupport::CollisionCorrectObjPos(const Fvector& start_from,bool	character_create/*=false*/)
{
	Fvector shift;shift.sub(start_from,m_EntityAlife.Position());

	Fbox box;
	if(character_create)box.set(movement()->Box());
	else	box.set(m_EntityAlife.BoundingBox());
	Fvector vbox;Fvector activation_pos;
	box.get_CD(activation_pos,vbox);shift.add(activation_pos);vbox.mul(2.f);
	activation_pos.add(shift,m_EntityAlife.Position());
	CPHActivationShape activation_shape;
	activation_shape.Create(activation_pos,vbox,&m_EntityAlife);
	if(!DoCharacterShellCollide()&&!character_create)
	{
		CPHCollideValidator::SetCharacterClassNotCollide(activation_shape);
	}
	activation_shape.Activate(vbox,1,1.f,M_PI/8.f);
	m_EntityAlife.Position().sub(activation_shape.Position(),shift);
	activation_shape.Destroy();
}
示例#6
0
void CActor::cam_Update(float dt, float fFOV)
{
	if(m_holder)		return;

	if(mstate_real & mcClimb&&cam_active!=eacFreeLook)
		camUpdateLadder(dt);

	Fvector point={0,CameraHeight(),0}, dangle={0,0,0};
	

	Fmatrix				xform,xformR;
	xform.setXYZ		(0,r_torso.yaw,0);
	xform.translate_over(XFORM().c);

	// lookout
	if (this == Level().CurrentControlEntity())
	{
		if (!fis_zero(r_torso_tgt_roll)){
			Fvector src_pt,tgt_pt;
			float radius		= point.y*0.5f;
			float alpha			= r_torso_tgt_roll/2.f;
			float dZ			= ((PI_DIV_2-((PI+alpha)/2)));
			calc_point			(tgt_pt,radius,0,alpha);
			src_pt.set			(0,tgt_pt.y,0);
			// init valid angle
			float valid_angle	= alpha;
			// xform with roll
			xformR.setXYZ		(-r_torso.pitch,r_torso.yaw,-dZ);
			Fmatrix33			mat; 
			mat.i				= xformR.i;
			mat.j				= xformR.j;
			mat.k				= xformR.k;
			// get viewport params
			float w,h;
			float c				= viewport_near(w,h); w/=2.f;h/=2.f;
			// find tris
			Fbox box;
			box.invalidate		();
			box.modify			(src_pt);
			box.modify			(tgt_pt);
			box.grow			(c);

			// query
			Fvector				bc,bd		;
			Fbox				xf			; 
			xf.xform			(box,xform)	;
			xf.get_CD			(bc,bd)		;

			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};
				if (test_point(xrc,xform,mat,ext,radius,alpha)){
					da			= PI/1000.f;
					if (!fis_zero(r_torso.roll))
						da		*= r_torso.roll/_abs(r_torso.roll);
					float angle = 0.f;
					for (; _abs(angle)<_abs(alpha); angle+=da)
						if (test_point(xrc,xform,mat,ext,radius,angle)) { 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;
		}
	}
	if (!fis_zero(r_torso.roll))
	{
		float radius		= point.y*0.5f;
		float valid_angle	= r_torso.roll/2.f;
		calc_point			(point,radius,0,valid_angle);
		dangle.z			= (PI_DIV_2-((PI+valid_angle)/2));
	}

	float flCurrentPlayerY	= xform.c.y;

	// Smooth out stair step ups
	if ((character_physics_support()->movement()->Environment()==peOnGround) && (flCurrentPlayerY-fPrevCamPos>0)){
		fPrevCamPos			+= dt*1.5f;
		if (fPrevCamPos > flCurrentPlayerY)
			fPrevCamPos		= flCurrentPlayerY;
		if (flCurrentPlayerY-fPrevCamPos>0.2f)
			fPrevCamPos		= flCurrentPlayerY-0.2f;
		point.y				+= fPrevCamPos-flCurrentPlayerY;
	}else{
		fPrevCamPos			= flCurrentPlayerY;
	}
	float _viewport_near			= VIEWPORT_NEAR;
	// calc point
	xform.transform_tiny			(point);

	CCameraBase* C					= cam_Active();

	if(eacFirstEye == cam_active)
	{
//		CCameraBase* C				= cameras[eacFirstEye];
	
		xrXRC						xrc			;
		xrc.box_options				(0)			;
		xrc.box_query				(Level().ObjectSpace.GetStaticModel(), point, Fvector().set(VIEWPORT_NEAR,VIEWPORT_NEAR,VIEWPORT_NEAR) );
		u32 tri_count				= xrc.r_count();
		if (tri_count)
		{
			_viewport_near			= 0.01f;
		}
		else
		{
			xr_vector<ISpatial*> ISpatialResult;
			g_SpatialSpacePhysic->q_box(ISpatialResult, 0, STYPE_PHYSIC, point, Fvector().set(VIEWPORT_NEAR,VIEWPORT_NEAR,VIEWPORT_NEAR));
			for (u32 o_it=0; o_it<ISpatialResult.size(); o_it++)
			{
				CPHShell*		pCPHS= smart_cast<CPHShell*>(ISpatialResult[o_it]);
				if (pCPHS)
				{
					_viewport_near			= 0.01f;
					break;
				}
			}
		}
	}
/*
	{
		CCameraBase* C				= cameras[eacFirstEye];
		float oobox_size			= 2*VIEWPORT_NEAR;


		Fmatrix						_rot;
		_rot.k						= C->vDirection;
		_rot.c						= C->vPosition;
		_rot.i.crossproduct			(C->vNormal,	_rot.k);
		_rot.j.crossproduct			(_rot.k,		_rot.i);

		
		Fvector						vbox; 
		vbox.set					(oobox_size, oobox_size, oobox_size);


		Level().debug_renderer().draw_aabb  (C->vPosition, 0.05f, 0.051f, 0.05f, D3DCOLOR_XRGB(0,255,0));
		Level().debug_renderer().draw_obb  (_rot, Fvector().div(vbox,2.0f), D3DCOLOR_XRGB(255,0,0));

		dMatrix3					d_rot;
		PHDynamicData::FMXtoDMX		(_rot, d_rot);

		CPHActivationShape			activation_shape;
		activation_shape.Create		(point, vbox, this);

		dBodySetRotation			(activation_shape.ODEBody(), d_rot);

		CPHCollideValidator::SetDynamicNotCollide(activation_shape);
		activation_shape.Activate	(vbox,1,1.f,0.0F);

		point.set					(activation_shape.Position());
		
		activation_shape.Destroy	();
	}
*/
	C->Update						(point,dangle);
	C->f_fov						= fFOV;
	if(eacFirstEye != cam_active)
	{
		cameras[eacFirstEye]->Update	(point,dangle);
		cameras[eacFirstEye]->f_fov		= fFOV;
	}
	
	if( psActorFlags.test(AF_PSP) )
	{
		Cameras().Update			(C);
	}else
	{
		Cameras().Update			(cameras[eacFirstEye]);
	}

	fCurAVelocity			= vPrevCamDir.sub(cameras[eacFirstEye]->vDirection).magnitude()/Device.fTimeDelta;
	vPrevCamDir				= cameras[eacFirstEye]->vDirection;

	if (Level().CurrentEntity() == this)
	{
		Level().Cameras().Update	(C);
		if(eacFirstEye == cam_active && !Level().Cameras().GetCamEffector(cefDemo)){
			Cameras().ApplyDevice	(_viewport_near);
		}
	}
}