コード例 #1
0
ファイル: PHFracture.cpp プロジェクト: AntonioModer/xray-16
element_fracture CPHFracturesHolder::SplitFromEnd(CPHElement* element,u16 fracture)
{
	FRACTURE_I fract_i		=m_fractures.begin()+fracture;
	u16 geom_num			=fract_i->m_start_geom_num;
	u16 end_geom_num		=fract_i->m_end_geom_num;
	SubFractureMass			(fracture);

	CPHElement* new_element	=cast_PHElement(P_create_Element());
	new_element->m_SelfID=fract_i->m_bone_id;
	new_element->mXFORM.set(element->mXFORM);
	element->PassEndGeoms(geom_num,end_geom_num,new_element);
	/////////////////////////////////////////////
	IKinematics* pKinematics= element->m_shell->PKinematics();
	const CBoneInstance& new_bi=pKinematics->LL_GetBoneInstance(new_element->m_SelfID);
	const CBoneInstance& old_bi=pKinematics->LL_GetBoneInstance(element->m_SelfID);



	Fmatrix shift_pivot;
	shift_pivot.set		(new_bi.mTransform);
	shift_pivot.invert	();
	shift_pivot.mulB_43	(old_bi.mTransform);
	/////////////////////////////////////////////
	float density=element->getDensity();
	new_element->SetShell(element->PHShell());
	Fmatrix current_transtform;
	element->GetGlobalTransformDynamic(&current_transtform);
	InitNewElement(new_element,shift_pivot,density);
	Fmatrix shell_form;
	element->PHShell()->GetGlobalTransformDynamic(&shell_form);
	current_transtform.mulA_43	(shell_form);
	new_element->SetTransform	(current_transtform, mh_unspecified );


	//dBodyID new_element_body=new_element->get_body();
	//dBodyAddForce(new_element_body,fract_i->m_pos_in_element[0],
	//									  fract_i->m_pos_in_element[1],
	//									  fract_i->m_pos_in_element[2]);
	ApplyImpactsToElement(new_element);
	
	//dBodyAddTorque(new_element->get_body(),fract_i->m_break_force,
	//									   fract_i->m_break_torque,
	//									   fract_i->m_add_torque_z);
	//BodyCutForce(new_element_body,default_l_limit,default_w_limit);
	element_fracture ret	=mk_pair(new_element,(CShellSplitInfo)(*fract_i));

	if(m_fractures.size()-fracture>0) 
	{	
		if(new_element->m_fratures_holder==NULL)//create fractures holder if it was not created before
		{
			new_element->m_fratures_holder=xr_new<CPHFracturesHolder>();
		}
		PassEndFractures(fracture,new_element);
	}
	
	return ret;
}
コード例 #2
0
ファイル: PhysicsShell.cpp プロジェクト: OLR-xray/OLR-3.0
CPhysicsShell*	P_build_SimpleShell(CGameObject* obj,float mass,bool not_active_state)
{
	CPhysicsShell* pPhysicsShell		= P_create_Shell();
#ifdef DEBUG
	pPhysicsShell->dbg_obj=smart_cast<CPhysicsShellHolder*>(obj);
#endif
	Fobb obb; obj->Visual()->vis.box.get_CD(obb.m_translate,obb.m_halfsize); obb.m_rotate.identity();
	CPhysicsElement* E = P_create_Element(); R_ASSERT(E); E->add_Box(obb);
	pPhysicsShell->add_Element(E);
	pPhysicsShell->setMass(mass);
	pPhysicsShell->set_PhysicsRefObject(smart_cast<CPhysicsShellHolder*>(obj));
	if(!obj->H_Parent())
		pPhysicsShell->Activate(obj->XFORM(),0,obj->XFORM(),not_active_state);
	return pPhysicsShell;
}
コード例 #3
0
ファイル: physic_item.cpp プロジェクト: OLR-xray/OLR-3.0
void CPhysicItem::create_box_physic_shell	()
{
	// Physics (Box)
	Fobb obb; 
	Visual()->vis.box.get_CD(obb.m_translate,obb.m_halfsize); 
	obb.m_rotate.identity();
	
	// Physics (Elements)
	CPhysicsElement* E = P_create_Element(); 
	R_ASSERT(E); 
	E->add_Box(obb);
	// Physics (Shell)
	m_pPhysicsShell = P_create_Shell(); 
	R_ASSERT(m_pPhysicsShell);
	m_pPhysicsShell->add_Element(E);
	m_pPhysicsShell->setDensity(2000.f);
	

}
コード例 #4
0
ファイル: PhysicObject.cpp プロジェクト: AntonioModer/xray-16
void CPhysicObject::AddElement(CPhysicsElement* root_e, int id)
{
	IKinematics* K		= smart_cast<IKinematics*>(Visual());

	CPhysicsElement* E	= P_create_Element();
	CBoneInstance& B	= K->LL_GetBoneInstance(u16(id));
	E->mXFORM.set		(K->LL_GetTransform(u16(id)));
	Fobb bb			= K->LL_GetBox(u16(id));


	if(bb.m_halfsize.magnitude()<0.05f)
	{
		bb.m_halfsize.add(0.05f);

	}
	E->add_Box			(bb);
	E->setMass			(10.f);
	E->set_ParentElement(root_e);
	B.set_callback		(bctPhysics,m_pPhysicsShell->GetBonesCallback(),E);
	m_pPhysicsShell->add_Element	(E);
	if( !(m_type==epotFreeChain && root_e==0) )
	{		
		CPhysicsJoint* J= P_create_Joint(CPhysicsJoint::full_control,root_e,E);
		J->SetAnchorVsSecondElement	(0,0,0);
		J->SetAxisDirVsSecondElement	(1,0,0,0);
		J->SetAxisDirVsSecondElement	(0,1,0,2);
		J->SetLimits				(-M_PI/2,M_PI/2,0);
		J->SetLimits				(-M_PI/2,M_PI/2,1);
		J->SetLimits				(-M_PI/2,M_PI/2,2);
		m_pPhysicsShell->add_Joint	(J);	
	}

	CBoneData& BD		= K->LL_GetData(u16(id));
	for (vecBonesIt it=BD.children.begin(); BD.children.end() != it; ++it){
		AddElement		(E,(*it)->GetSelfID());
	}
}
コード例 #5
0
ファイル: physic_item.cpp プロジェクト: OLR-xray/OLR-3.0
void CPhysicItem::create_box2sphere_physic_shell()
{
	// Physics (Box)
	Fobb								obb;
	Visual()->vis.box.get_CD			(obb.m_translate,obb.m_halfsize);
	obb.m_rotate.identity				();

	// Physics (Elements)
	CPhysicsElement						*E = P_create_Element	();
	R_ASSERT							(E);

	Fvector								ax;
	float								radius;
	CHOOSE_MAX(
		obb.m_halfsize.x,ax.set(obb.m_rotate.i) ; ax.mul(obb.m_halfsize.x); radius=_min(obb.m_halfsize.y,obb.m_halfsize.z) ;obb.m_halfsize.y/=2.f;obb.m_halfsize.z/=2.f,
		obb.m_halfsize.y,ax.set(obb.m_rotate.j) ; ax.mul(obb.m_halfsize.y); radius=_min(obb.m_halfsize.x,obb.m_halfsize.z) ;obb.m_halfsize.x/=2.f;obb.m_halfsize.z/=2.f,
		obb.m_halfsize.z,ax.set(obb.m_rotate.k) ; ax.mul(obb.m_halfsize.z); radius=_min(obb.m_halfsize.y,obb.m_halfsize.x) ;obb.m_halfsize.y/=2.f;obb.m_halfsize.x/=2.f
	)
		//radius*=1.4142f;
	Fsphere								sphere1,sphere2;
	sphere1.P.add						(obb.m_translate,ax);
	sphere1.R							=radius*1.4142f;

	sphere2.P.sub						(obb.m_translate,ax);
	sphere2.R							=radius/2.f;

	E->add_Box							(obb);
	E->add_Sphere						(sphere1);
	E->add_Sphere						(sphere2);

	// Physics (Shell)
	m_pPhysicsShell						= P_create_Shell	();
	R_ASSERT							(m_pPhysicsShell);
	m_pPhysicsShell->add_Element		(E);
	m_pPhysicsShell->setDensity			(2000.f);
	m_pPhysicsShell->SetAirResistance();
}