示例#1
0
//------------------------------------------------------------------------
const Matrix34 & CVehiclePartEntityAttachment::GetWorldTM()
{
	const Matrix34 &tm = GetLocalTM(false);
	m_worldTM = GetEntity()->GetWorldTM() * tm;

	return VALIDATE_MAT(m_worldTM);
}
 void CParticleSystem::DoRender()
 {
     for ( auto i : m_emitterVector )
     {
         i->Visit( &GetLocalTM() );
     }
 }
示例#3
0
void CControl::LocalToParent(float &x, float &y)
{
    CVec3 pos(x, y, 0.f);
    pos.Transform(GetLocalTM());
    x = pos.x;
    y = pos.y;
}
示例#4
0
void CControl::ParentToLocal(float &x, float &y)
{
    CVec3 pos(x, y, 0.f);
    kmMat4 inverse;
    kmMat4Inverse(&inverse, &GetLocalTM());
    pos.Transform(inverse);
    x = pos.x;
    y = pos.y;
}
示例#5
0
//------------------------------------------------------------------------
void CVehiclePartEntityAttachment::UpdateAttachment()
{
	IEntity* pEntity = GetAttachmentEntity();

	if (pEntity)
	{
		const Matrix34 &vehicleTM = GetLocalTM(false);
		pEntity->SetLocalTM(vehicleTM);

#if ENABLE_VEHICLE_DEBUG
		if (IsDebugParts())
		{
			VehicleUtils::DrawTM( GetWorldTM());
		}
#endif
	}
}
void CVehiclePartSuspensionPart::PostInit()
{
	const Matrix34& tm = GetLocalTM(false);
	const Matrix34& targetTm = m_targetPart->GetLocalTM(false);
	if (m_ikFlags & k_flagTargetHelper)
		m_targetOffset = targetTm.GetInverted() * m_targetOffset;
	m_pos0 = tm.GetTranslation();
	Vec3 targetPos = targetTm * m_targetOffset;
	m_direction0 = targetPos - m_pos0;
	float length = m_direction0.GetLength();
	if (length > 1e-2f)
	{
		m_invLength0 = 1.f/length;
		m_direction0 = m_direction0/length;
	}
	else
	{
		m_invLength0 = 0.f;
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "CVehiclePartSuspensionPart: inavlid suspension IK setup target is TOO close");
	}
	m_initialRot = Quat(tm);
}
示例#7
0
文件: physics.cpp 项目: skopp/rush
JObject* RBExport::ProcessPhysicsObject( INode* node )
{
    ObjectState os = node->EvalWorldState( m_CurTime ); 
    Object* pObj = os.obj;
    const char* pNodeName = node->GetName();

    if (!pObj)
    {
        Warn( "Physics node %s is invalid.", pNodeName );
    }

    JObject* pPhysObj = NULL;
    Mat4 objTM = Convert( GetLocalTM( node, m_CurTime ) );

    JString hostName = "";

    ExpNode* pExportedParent = GetExportedNode( node->GetParentNode() );
    if (pExportedParent && pExportedParent->m_pObject)
    {
        JObject* pParentObj = pExportedParent->m_pObject;
        if (obj_cast<PhysBody>( pParentObj ))
        {
            hostName = pParentObj->GetName();
        }
        else if (obj_cast<JBone>( pParentObj ))
        {
            hostName = pParentObj->GetName();
        }
    }

    //  check for joint type
    DWORD scID = pObj->SuperClassID();
    if (scID == HELPER_CLASS_ID) 
    {
        PhysJoint* pJoint = new PhysJoint(); 
        pJoint->SetHostBone( hostName.c_str() );
        pPhysObj = pJoint;
    }
    else
    {
        CStr className;
        pObj->GetClassName( className );
        IParamArray* pParam = pObj->GetParamBlock();
        IParamBlock* pParamBlock = NULL;

        if (pParam) pParamBlock = pParam->GetParamBlock();

        if (!stricmp( className, "sphere" ))
        {
            ColSphere* pSphere = new ColSphere();
            pPhysObj = pSphere;
            float radius = 0.0f;
            pParamBlock->GetValue( SPHERE_RADIUS, 0, radius, FOREVER );
            pSphere->SetRadius( radius );
            pSphere->SetHost( hostName.c_str() );
            pSphere->SetOffsetTM( objTM );
        }

        if (!stricmp( className, "box" ))
        {
            ColBox* pBox = new ColBox();
            pPhysObj = pBox;
            Vec3 ext;
            pParamBlock->GetValue( BOXOBJ_LENGTH, 0, ext.x, FOREVER );
            pParamBlock->GetValue( BOXOBJ_WIDTH,  0, ext.y, FOREVER );
            pParamBlock->GetValue( BOXOBJ_HEIGHT, 0, ext.z, FOREVER );
            pBox->SetExtents( ext );
            pBox->SetHost( hostName.c_str() );
            pBox->SetOffsetTM( objTM );
        }
        
        if (!stricmp( className, "capsule" ))
        {
            ColCapsule* pCapsule = new ColCapsule();
            pPhysObj = pCapsule;
            int   bCenters = 0;
            float radius   = 0.0f;
            float height   = 0.0f;
            pParamBlock->GetValue( PB_RADIUS,  0, radius,   FOREVER );
            pParamBlock->GetValue( PB_HEIGHT,  0, height,   FOREVER );
            pParamBlock->GetValue( PB_CENTERS, 0, bCenters, FOREVER );
            pCapsule->SetRadius( radius );
            pCapsule->SetHeight( height );
            pCapsule->SetHost( hostName.c_str() );
            pCapsule->SetOffsetTM( objTM );
        }

        if (!stricmp( className, "cylinder" ))
        {
            ColCylinder* pCylinder = new ColCylinder();
            pPhysObj = pCylinder;
            int   bCenters = 0;
            float radius   = 0.0f;
            float height   = 0.0f;
            pParamBlock->GetValue( PB_RADIUS,  0, radius,   FOREVER );
            pParamBlock->GetValue( PB_HEIGHT,  0, height,   FOREVER );
            pParamBlock->GetValue( PB_CENTERS, 0, bCenters, FOREVER );
            pCylinder->SetRadius( radius );
            pCylinder->SetHeight( height );
            pCylinder->SetHost( hostName.c_str() );
            pCylinder->SetOffsetTM( objTM );
        }

        if (!stricmp( className, "teapot" ))
        {
            //  by teapot we represent physical body (point of mass)
            PhysBody* pBody = new PhysBody();
            pBody->SetHostBone( hostName.c_str() );
            pPhysObj = pBody;
            pBody->SetOffsetTM( objTM );
        }

        //  if none of above,  try to export as trimesh collision primitive
        if (pPhysObj == NULL && scID == GEOMOBJECT_CLASS_ID)
        {
            ColMesh* pMesh = GetColMesh( node );
            if (pMesh)
            {
                pPhysObj = pMesh;
                pMesh->SetHost( hostName.c_str() );
                pMesh->SetOffsetTM( objTM );
            }
        }
    }
    
    if (pPhysObj)
    {
        if (!m_pPhysicsGroup)
        {
            m_pPhysicsGroup = new JGroup();
            m_pPhysicsGroup->SetName( "physics" );
        }
        pPhysObj->SetName( pNodeName );
        m_pPhysicsGroup->AddChild( pPhysObj );
    }
    else
    {
        Warn( "Unrecognized physics object type in  node %s", pNodeName );
        return NULL;
    }
    return pPhysObj;
} // RBExport::ProcessPhysicsObject