Exemplo n.º 1
0
bool CLevelTool::GetSelectionPosition(Fmatrix& result)
{
	if(pCurTool)
    {
    	Fvector 			center;
    	Fbox 				BB;
        BB.invalidate		();
//    	pCurTool->GetBBox	(BB, true);

        const CCustomObject* object = pCurTool->LastSelected();
        if(!object)
        	return false;
            
        object->GetBox		(BB);
        
        BB.getcenter		(center);
        center.y			= BB.max.y;

		Fvector2			pt_ss;
        pt_ss.set			(10000,-10000);
        Fvector				pt_ss_3d;
        BB.setb				(center, Fvector().set(1.0f,1.0f,1.0f));
        for(int k=0;k<8;++k)
        {
        	Fvector pt;
        	BB.getpoint(k,pt);
			EDevice.mFullTransform.transform(pt_ss_3d, pt);
            
            pt_ss.x = _min(pt_ss.x, pt_ss_3d.y);
            pt_ss.y = _max(pt_ss.y, pt_ss_3d.y);
        }

        float r_bb_ss	 = pt_ss.y - pt_ss.x;
        clamp(r_bb_ss, 0.0f,0.10f);
        float des_radius = 0.2f; 
        float csale 	 = des_radius/r_bb_ss;
        
        result.scale	(csale,csale,csale);
        result.c 		= center;
        return 			true;
    }else
		return 			false;
}
Exemplo n.º 2
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;
}