コード例 #1
0
ファイル: Car.cpp プロジェクト: AntonioModer/xray-16
bool CCar::attach_Actor(CGameObject* actor)
{
	if(Owner()||CPHDestroyable::Destroyed()) return false;
	CHolderCustom::attach_Actor(actor);

	IKinematics* K	= smart_cast<IKinematics*>(Visual());
	CInifile* ini	= K->LL_UserData();
	int id;
	if(ini->line_exist("car_definition","driver_place"))
		id=K->LL_BoneID(ini->r_string("car_definition","driver_place"));
	else
	{	
		Owner()->setVisible(0);
		id=K->LL_GetBoneRoot();
	}
	CBoneInstance& instance=K->LL_GetBoneInstance				(u16(id));
	m_sits_transforms.push_back(instance.mTransform);
	OnCameraChange(ectFirst);
	PPhysicsShell()->Enable();
	PPhysicsShell()->add_ObjectContactCallback(ActorObstacleCallback);
//	VisualUpdate();
	processing_activate();
	ReleaseHandBreak();
//	CurrentGameUI()->UIMainIngameWnd->CarPanel().Show(true);
//	CurrentGameUI()->UIMainIngameWnd->CarPanel().SetCarHealth(fEntityHealth/100.f);
	//CurrentGameUI()->UIMainIngameWnd.ShowBattery(true);
	//CBoneData&	bone_data=K->LL_GetData(id);
	//Fmatrix driver_pos_tranform;
	//driver_pos_tranform.setHPB(bone_data.bind_hpb.x,bone_data.bind_hpb.y,bone_data.bind_hpb.z);
	//driver_pos_tranform.c.set(bone_data.bind_translate);
	//m_sits_transforms.push_back(driver_pos_tranform);
	//H_SetParent(actor);

	return true;
}
コード例 #2
0
ファイル: PhysicsShellHolder.cpp プロジェクト: 2asoft/xray
void CPhysicsShellHolder::PHSaveState(NET_Packet &P)
{

	//CPhysicsShell* pPhysicsShell=PPhysicsShell();
	IKinematics* K	=smart_cast<IKinematics*>(Visual());
	//Flags8 lflags;
	//if(pPhysicsShell&&pPhysicsShell->isActive())			lflags.set(CSE_PHSkeleton::flActive,pPhysicsShell->isEnabled());

//	P.w_u8 (lflags.get());
	if(K)
	{
		P.w_u64(K->LL_GetBonesVisible());
		P.w_u16(K->LL_GetBoneRoot());
	}
	else
	{
		P.w_u64(u64(-1));
		P.w_u16(0);
	}
	/////////////////////////////
	Fvector min,max;

	min.set(flt_max,flt_max,flt_max);
	max.set(-flt_max,-flt_max,-flt_max);
	/////////////////////////////////////

	u16 bones_number=PHGetSyncItemsNumber();
	for(u16 i=0;i<bones_number;i++)
	{
		SPHNetState state;
		PHGetSyncItem(i)->get_State(state);
		Fvector& p=state.position;
		if(p.x<min.x)min.x=p.x;
		if(p.y<min.y)min.y=p.y;
		if(p.z<min.z)min.z=p.z;

		if(p.x>max.x)max.x=p.x;
		if(p.y>max.y)max.y=p.y;
		if(p.z>max.z)max.z=p.z;
	}

	min.sub(2.f*EPS_L);
	max.add(2.f*EPS_L);

	VERIFY(!min.similar(max));
	P.w_vec3(min);
	P.w_vec3(max);

	P.w_u16(bones_number);

	for(u16 i=0;i<bones_number;i++)
	{
		SPHNetState state;
		PHGetSyncItem(i)->get_State(state);
		state.net_Save(P,min,max);
	}
}
コード例 #3
0
ファイル: PHSkeleton.cpp プロジェクト: 2asoft/xray
void CPHSkeleton::SaveNetState(NET_Packet& P)
{

	CPhysicsShellHolder* obj=PPhysicsShellHolder();
	CPhysicsShell* pPhysicsShell=obj->PPhysicsShell();
	IKinematics* K	=smart_cast<IKinematics*>(obj->Visual());
	if(pPhysicsShell&&pPhysicsShell->isActive())			m_flags.set(CSE_PHSkeleton::flActive,pPhysicsShell->isEnabled());

	P.w_u8 (m_flags.get());
	if(K)
	{
		P.w_u64(K->LL_GetBonesVisible());
		P.w_u16(K->LL_GetBoneRoot());
	}
	else
	{
		P.w_u64(u64(-1));
		P.w_u16(0);
	}
	/////////////////////////////
	Fvector min,max;

	min.set(F_MAX,F_MAX,F_MAX);
	max.set(-F_MAX,-F_MAX,-F_MAX);
	/////////////////////////////////////

	u16 bones_number=obj->PHGetSyncItemsNumber();
	for(u16 i=0;i<bones_number;i++)
	{
		SPHNetState state;
		obj->PHGetSyncItem(i)->get_State(state);
		Fvector& p=state.position;
		if(p.x<min.x)min.x=p.x;
		if(p.y<min.y)min.y=p.y;
		if(p.z<min.z)min.z=p.z;

		if(p.x>max.x)max.x=p.x;
		if(p.y>max.y)max.y=p.y;
		if(p.z>max.z)max.z=p.z;
	}

	min.sub(2.f*EPS_L);
	max.add(2.f*EPS_L);

	P.w_vec3(min);
	P.w_vec3(max);

	P.w_u16(bones_number);

	for(u16 i=0;i<bones_number;i++)
	{
		SPHNetState state;
		obj->PHGetSyncItem(i)->get_State(state);
		state.net_Save(P,min,max);
	}
}
コード例 #4
0
BOOL CWeaponStatMgun::net_Spawn(CSE_Abstract* DC)
{
	if(!inheritedPH::net_Spawn	(DC)) return FALSE;



	IKinematics* K			= smart_cast<IKinematics*>(Visual());
	CInifile* pUserData		= K->LL_UserData(); 

	R_ASSERT2				(pUserData,"Empty WeaponStatMgun user data!");

	m_rotate_x_bone			= K->LL_BoneID	(pUserData->r_string("mounted_weapon_definition","rotate_x_bone"));
	m_rotate_y_bone			= K->LL_BoneID	(pUserData->r_string("mounted_weapon_definition","rotate_y_bone"));
	m_fire_bone				= K->LL_BoneID	(pUserData->r_string("mounted_weapon_definition","fire_bone"));
	m_camera_bone			= K->LL_BoneID	(pUserData->r_string("mounted_weapon_definition","camera_bone"));

	U16Vec fixed_bones;
	fixed_bones.push_back	(K->LL_GetBoneRoot());
	PPhysicsShell()			= P_build_Shell(this,false,fixed_bones);

	CBoneData& bdX			= K->LL_GetData(m_rotate_x_bone); VERIFY(bdX.IK_data.type==jtJoint);
	m_lim_x_rot.set			(bdX.IK_data.limits[0].limit.x,bdX.IK_data.limits[0].limit.y);
	CBoneData& bdY			= K->LL_GetData(m_rotate_y_bone); VERIFY(bdY.IK_data.type==jtJoint);
	m_lim_y_rot.set			(bdY.IK_data.limits[1].limit.x,bdY.IK_data.limits[1].limit.y);
	

	xr_vector<Fmatrix> matrices;
	K->LL_GetBindTransform	(matrices);
	m_i_bind_x_xform.invert	(matrices[m_rotate_x_bone]);
	m_i_bind_y_xform.invert	(matrices[m_rotate_y_bone]);
	m_bind_x_rot			= matrices[m_rotate_x_bone].k.getP();
	m_bind_y_rot			= matrices[m_rotate_y_bone].k.getH();
	m_bind_x.set			(matrices[m_rotate_x_bone].c);
	m_bind_y.set			(matrices[m_rotate_y_bone].c);

	m_cur_x_rot				= m_bind_x_rot;
	m_cur_y_rot				= m_bind_y_rot;
	m_destEnemyDir.setHP	(m_bind_y_rot,m_bind_x_rot);
	XFORM().transform_dir	(m_destEnemyDir);

	inheritedShooting::Light_Create();

	processing_activate		();
	setVisible				(TRUE);
	setEnabled				(TRUE);
	return					TRUE;
}
コード例 #5
0
void reset_root_bone_start_pose( CPhysicsShell& shell )
{
	VERIFY( &shell );
	CPhysicsElement * physics_root_element = shell.get_ElementByStoreOrder( 0 );
	VERIFY( physics_root_element );

	IKinematics * K = shell.PKinematics();
	VERIFY( K );
	
	u16	animation_root_bone_id = K->LL_GetBoneRoot();

	CODEGeom	*physics_root_bone_geom = physics_root_element->geometry( 0 );
	VERIFY( physics_root_bone_geom );

	u16 physics_root_bone_id = physics_root_bone_geom->bone_id();
	VERIFY( physics_root_bone_id != BI_NONE );

	if( animation_root_bone_id == physics_root_bone_id )
		return ;

	//u16 anim_bones_number = K->LL_BoneCount();

	//buffer_vector<u32>	anim_bones_bind_positions( _alloca(anim_bones_number*sizeof(u32)),
	//												anim_bones_number
	//											);
#pragma todo("LL_GetBindTransform shoud use buffer_vector")

	xr_vector<Fmatrix> anim_bones_bind_positions;
	K->LL_GetBindTransform( anim_bones_bind_positions );


	const Fmatrix physics_root_to_anim_root_bind_transformation 
		= Fmatrix().mul_43( Fmatrix().invert( anim_bones_bind_positions[ physics_root_bone_id ] ), 
											  anim_bones_bind_positions[ animation_root_bone_id ] );

	const Fmatrix &physics_root_bone_anim_transform = K->LL_GetTransform( physics_root_bone_id );

	const Fmatrix physics_root_bone_corrected_pos = Fmatrix().mul_43( physics_root_bone_anim_transform ,
																	  physics_root_to_anim_root_bind_transformation
																	  );

	physics_root_element->SetTransform( Fmatrix().mul_43( shell.mXFORM, physics_root_bone_corrected_pos ) );

	//physics_root_element->TransformPosition( Fmatrix().mul_43( Fmatrix().invert( K->LL_GetTransform( animation_root_bone_id ) ), physics_root_bone_corrected_pos ) );
}
コード例 #6
0
 void imotion_position::force_calculate_bones( IKinematicsAnimated& KA )
{
	IKinematics *K = shell->PKinematics();
	VERIFY( K );
	VERIFY( K == smart_cast<IKinematics *>( &KA ) );
	disable_bone_calculation( *K, false );

	K->Bone_Calculate( &K->LL_GetData(0), &Fidentity );

	if( saved_visual_callback )
	{
		u16 sv_root = K->LL_GetBoneRoot();
		K->LL_SetBoneRoot( 0 );
		saved_visual_callback( K );
		K->LL_SetBoneRoot( sv_root );
	}
	disable_bone_calculation( *K, true );
}
コード例 #7
0
void CCharacterPhysicsSupport::bone_chain_disable(u16 bone, u16 r_bone, IKinematics &K)
{
	VERIFY(&K);
	u16 bid					= bone;
	//K.LL_GetBoneInstance( bid ).set_callback( bctCustom, 0, 0, TRUE );

	while( bid!=r_bone && bid !=  K.LL_GetBoneRoot() )
	{
		CBoneData	&bd =	K.LL_GetData( bid );
		if( K.LL_GetBoneInstance( bid ).callback() != anim_bone_fix::callback )
		{
			m_weapon_bone_fixes.push_back( new anim_bone_fix() );
			m_weapon_bone_fixes.back()->fix( bid, K );
		}
		bid =	bd.GetParentID();
		
		
	

		//K.LL_GetBoneInstance( bid ).set_callback( bctCustom, 0, 0, TRUE );
	}
	
}
コード例 #8
0
void CIKLimbsController::Calculate( )
{
	update_blend( m_legs_blend );

	Fmatrix &obj = m_object->XFORM( );
#ifdef	DEBUG
	if( ph_dbg_draw_mask1.test( phDbgDrawIKSHiftObject ) )
		_object_shift.dbg_draw( obj, _pose_extrapolation, Fvector().set( 0,2.5f,0));
#endif

	SCalculateData cd[max_size];



	xr_vector<CIKLimb>::iterator i, b = _bone_chains.begin(), e = _bone_chains.end();
	for( i = b ; e != i; ++i )
	{
		cd[i-b] = SCalculateData ( *i, obj );
		LimbCalculate( cd[i-b] );
	}

	IKinematics *K = m_object->Visual()->dcast_PKinematics( );
	u16 root = K->LL_GetBoneRoot( ) ;
	CBoneInstance &root_bi = K->LL_GetBoneInstance(root);

	BOOL sv_root_cb_ovwr = root_bi.callback_overwrite();
	BoneCallback sv_root_cb =		root_bi.callback();

	root_bi.set_callback( root_bi.callback_type(), 0, root_bi.callback_param(), TRUE );


	if( ik_shift_object  )//&& ! m_object->animation_movement_controlled( )
	{

			ShiftObject( cd );
	}

	const u16 sz =(u16)_bone_chains.size();
	for(u16 j = 0; sz > j; ++j )
		cd[j].m_limb->SetGoal( cd[j] );

	for(u16 j = 0; sz > j; ++j )
	{
		
		cd[j].m_limb->SolveBones( cd[j] );

#ifdef	DEBUG
	if( ph_dbg_draw_mask1.test( phDbgDrawIKPredict ) )
	{
		//IKinematics *K = m_object->Visual()->dcast_PKinematics( );
		u16 ref_bone_id = cd[j].m_limb->dbg_ref_bone_id();
		Fmatrix m =Fmatrix().mul( obj, K->LL_GetTransform( ref_bone_id ) );
		Fvector toe;
		cd[j].m_limb->dbg_ik_foot().ToePosition( toe );
		m.transform_tiny( toe );
		DBG_DrawLine( toe, Fvector().add( toe, Fvector().set( 0, -_object_shift.shift(), 0 ) ), D3DCOLOR_XRGB( 255, 0, 0 )  );
	}
#endif
	}
	ObjectShift( 0, cd );
	


	root_bi.set_callback( root_bi.callback_type(), sv_root_cb, root_bi.callback_param(), sv_root_cb_ovwr );

}
コード例 #9
0
void	imotion_position::state_end( )
{
	VERIFY( shell );
	inherited::state_end( );
	
	CPhysicsShellHolder *obj= static_cast<CPhysicsShellHolder*>( shell->get_ElementByStoreOrder( 0 )->PhysicsRefObject() );
	VERIFY( obj );
	obj->processing_deactivate();
	shell->Enable();
	shell->setForce( Fvector().set( 0.f, 0.f, 0.f ) );
	shell->setTorque( Fvector().set( 0.f, 0.f, 0.f ) );

	shell->AnimToVelocityState( end_delta, default_l_limit * 10, default_w_limit * 10 );
#ifdef	DEBUG
	dbg_draw_state_end( shell );
#endif
	shell->remove_ObjectContactCallback( get_depth );
	IKinematics *K = shell->PKinematics();
	disable_update( false );
	disable_bone_calculation( *K, false );
	K->SetUpdateCallback( saved_visual_callback );
	deinit_bones();

	save_fixes( K );
	
	shell->EnabledCallbacks( TRUE );

	restore_fixes( );

	VERIFY( K );

	IKinematicsAnimated	*KA = smart_cast<IKinematicsAnimated*>( shell->PKinematics() );
	VERIFY( KA );
	update_callback.motion = 0;
	KA->SetUpdateTracksCalback( 0 );

#if 0

			DBG_OpenCashedDraw();
			shell->dbg_draw_geometry( 0.02, D3DCOLOR_ARGB( 255, 0, 255, 0 )  );
			DBG_DrawBones( *shell->get_ElementByStoreOrder( 0 )->PhysicsRefObject() );
			DBG_ClosedCashedDraw( 50000 );

#endif

	u16 root = K->LL_GetBoneRoot();
	if( root!=0 )
	{
		K->LL_GetTransform( 0 ).set( Fidentity );
		K->LL_SetBoneVisible( 0, FALSE, FALSE );
		u16 bip01 = K->LL_BoneID( "bip01" );
		if( bip01 != BI_NONE && bip01 != root )
		{
			K->LL_GetTransform( bip01 ).set( Fidentity );
			K->LL_SetBoneVisible( bip01, FALSE, FALSE );
		}
	}

	K->CalculateBones_Invalidate();
	K->CalculateBones( true );

#if 0 

			DBG_OpenCashedDraw();
			shell->dbg_draw_geometry( 0.02, D3DCOLOR_ARGB( 255, 0, 0, 255 )  );
			DBG_DrawBones( *shell->get_ElementByStoreOrder( 0 )->PhysicsRefObject() );
			DBG_ClosedCashedDraw( 50000 );

#endif
}