コード例 #1
0
ファイル: physicsserver.cpp プロジェクト: skopp/rush
Vec3 PhysicsServer::GetObjectTorque( int objID )
{
    if (objID < 0 || objID >= m_Objects.size()) return Vec3::null;
    PhysBody* pBody = m_Objects[objID]->GetRootBody();
    if (!pBody) return Vec3::null;
    return pBody->GetTorque();
}
コード例 #2
0
ファイル: physicsserver.cpp プロジェクト: skopp/rush
void PhysicsServer::SetObjectTorque( int objID, const Vec3& v )
{
    if (objID < 0 || objID >= m_Objects.size()) return;
    PhysBody* pBody = m_Objects[objID]->GetRootBody();
    if (!pBody) return;
    pBody->SetTorque( v );
}
コード例 #3
0
ファイル: physicsserver.cpp プロジェクト: skopp/rush
Mat3 PhysicsServer::GetObjectInertia( int objID )
{
    if (objID < 0 || objID >= m_Objects.size()) return Mat3::identity;
    PhysBody* pBody = m_Objects[objID]->GetRootBody();
    if (!pBody) return Mat3::identity;
    return pBody->GetInertia();  
} // PhysicsServer::GetObjectInertia
コード例 #4
0
ファイル: physicsserver.cpp プロジェクト: skopp/rush
void PhysicsServer::SetObjectInertia( int objID, const Mat3& inertiaTensor )
{
    if (objID < 0 || objID >= m_Objects.size()) return;
    PhysBody* pBody = m_Objects[objID]->GetRootBody();
    if (!pBody) return;
    pBody->SetInertia( inertiaTensor );  
} // PhysicsServer::SetObjectInertia
コード例 #5
0
ファイル: physicsserver.cpp プロジェクト: skopp/rush
float PhysicsServer::GetObjectMass( int objID )
{
    if (objID < 0 || objID >= m_Objects.size()) return 0.0f;
    PhysBody* pBody = m_Objects[objID]->GetRootBody();
    if (!pBody) return 0.0f;
    return pBody->GetMass();  
} // PhysicsServer::GetObjectMass
コード例 #6
0
ファイル: physicsserver.cpp プロジェクト: skopp/rush
void PhysicsServer::SetObjectMass( int objID, float mass )
{
    if (objID < 0 || objID >= m_Objects.size()) return;
    PhysBody* pBody = m_Objects[objID]->GetRootBody();
    if (!pBody) return;
    pBody->SetMass( mass );  
} // PhysicsServer::SetObjectMass
コード例 #7
0
ファイル: physicsserver.cpp プロジェクト: skopp/rush
void PhysicsServer::SetObjectTM( int objID, const Mat4& tm )
{
    if (objID < 0 || objID >= m_Objects.size()) return;
    PhysBody* pBody = m_Objects[objID]->GetRootBody();
    if (!pBody) return;
    pBody->SetTM( tm );
} // PhysicsServer::SetObjectTM
コード例 #8
0
ファイル: physicsserver.cpp プロジェクト: skopp/rush
void PhysicsServer::SetObjectPos( int objID, const Vec3& pos )
{
    if (objID < 0 || objID >= m_Objects.size()) return;
    PhysBody* pBody = m_Objects[objID]->GetRootBody();
    if (!pBody) return;
    pBody->SetPos( pos );
} // PhysicsServer::SetObjectPos
コード例 #9
0
ファイル: physicsserver.cpp プロジェクト: skopp/rush
const Mat4& PhysicsServer::GetObjectTM( int objID )
{
    if (objID < 0 || objID >= m_Objects.size()) return Mat4::identity;
    PhysBody* pBody = m_Objects[objID]->GetRootBody();
    if (!pBody) return Mat4::identity;
    return pBody->GetTM();
} // PhysicsServer::GetObjectTM
コード例 #10
0
void PhysObject::Enable( bool bEnable )
{
    if (bEnable == m_bEnabled) return;
    JObjectIterator it( this );
    while (*it)
    {
        JObject* pObject = (*it);
        PhysBody* pBody = obj_cast<PhysBody>( pObject );
        if (pBody)
        {
            pBody->SetEnabled( bEnable );
        }
        ColGeom* pGeom = obj_cast<ColGeom>( pObject );
        if (pGeom)
        {
            pGeom->SetEnabled( bEnable );
        }
        ++it;
    }
    m_bEnabled = bEnable;
} // PhysObject::Enable
コード例 #11
0
ファイル: MainState.cpp プロジェクト: colintan95/raven
void MainState::FireProjectile() {
	if (!m_FireReady) {
		return;
	}

	// (TODO:) manage projectiles; they are currently causing memory leaks
	
	Projectile* projectile = (Projectile*)m_EnginePtr->GetEntityManager()->CreateEntity("Projectile");
	projectile->TranslateTo(m_Player->GetWorldPosition());


	Texture* tex = m_EnginePtr->GetTextureRegistry()->GetTexture("projectile.png");
	Sprite* sprite = m_EntityManagerPtr->CreateSprite((Entity*)projectile, tex, 1);
	sprite->AddClip("idle", 0, 0, 30, 5, 1, 1, 1);
	sprite->SetOrigin(Vec2(0, 3));


	PhysBody* body = m_EntityManagerPtr->CreatePhysBody((Entity*)projectile, kPhysBodyDynamic, kPhysLayerFriendProj);
	body->SetOrigin(Vec2(0, 3));
	body->SetWidth(30.0);
	body->SetHeight(5.0);


	if (m_Player->GetFlipY()) {
		projectile->FlipY(true);
		body->SetVelocity(Vec2(-1.0, 0.0));
	}
	else {
		projectile->FlipY(false);
		body->SetVelocity(Vec2(1.0, 0.0));
	}

	m_EnginePtr->GetScene()->AddEntity(projectile, 0);

	// Adds the projectile to the projectile array
	m_ProjectileArray.PushBack(projectile);

	m_FireReady = false;
}
コード例 #12
0
ファイル: MainState.cpp プロジェクト: colintan95/raven
MainState::MainState(GameEngine* engine): BaseGameState(engine),
m_ProjectileArray(kProjectileMax)
{
	m_EntityManagerPtr = engine->GetEntityManager();
	m_PhysWorldPtr = engine->GetPhysWorld();

	// Set the game controller
	m_Controller = new GameController(this);

	memset((void*)m_PlayerDirState, 0, sizeof(bool) * 4);


	// Creates the player entity
	m_Player = (Player*)m_EntityManagerPtr->CreateEntity("Player");
	

	// Creates the player sprite
	Texture* playerTex = m_EnginePtr->GetTextureRegistry()->GetTexture("metalslug.png");
	Sprite* playerSprite = m_EntityManagerPtr->CreateSprite((Entity*)m_Player, playerTex, 1);
	playerSprite->AddClip("idle", 5, 0, 30, 40, 1, 1, 1);
	playerSprite->PlayClip("idle", true);
	playerSprite->SetOrigin(Vec2(15, 20));


	// Create the player phys body
	PhysBody* playerBody = m_EntityManagerPtr->CreatePhysBody((Entity*)m_Player, kPhysBodyControlled, kPhysLayerFriend);
	playerBody->SetOrigin(Vec2(15, 20));
	playerBody->SetWidth(30.0);
	playerBody->SetHeight(40.0);


	// Creates the enemy entity
	m_Enemy = (Enemy*)m_EntityManagerPtr->CreateEntity("Enemy");
	m_Enemy->TranslateTo(Vec2(200.0, 0.0));
	

	// Creates the enemy sprite
	Texture* enemyTex = m_EnginePtr->GetTextureRegistry()->GetTexture("ms_enemy.png");
	Sprite* enemySprite = m_EntityManagerPtr->CreateSprite((Entity*)m_Enemy, enemyTex, 1);
	enemySprite->AddClip("idle", 0, 4, 30, 40, 1, 1, 1);
	enemySprite->PlayClip("idle", true);
	enemySprite->SetOrigin(Vec2(15, 20));


	// Create the enemy phys body
	PhysBody* enemyBody = m_EntityManagerPtr->CreatePhysBody((Entity*)m_Enemy, kPhysBodyStatic, kPhysLayerEnemy);
	enemyBody->SetOrigin(Vec2(15, 20));
	enemyBody->SetWidth(30.0);
	enemyBody->SetHeight(40.0);


	m_PhysWorldPtr->ResetAllLayerIgnore();

	// Sets which layer ignores which
	m_PhysWorldPtr->AddLayerIgnore(kPhysLayerFriend, kPhysLayerFriend);
	m_PhysWorldPtr->AddLayerIgnore(kPhysLayerEnemy, kPhysLayerEnemy);
	m_PhysWorldPtr->AddLayerIgnore(kPhysLayerFriendProj, kPhysLayerFriendProj);
	m_PhysWorldPtr->AddLayerIgnore(kPhysLayerEnemyProj, kPhysLayerEnemyProj);
	m_PhysWorldPtr->AddLayerIgnore(kPhysLayerFriend, kPhysLayerEnemy);
	m_PhysWorldPtr->AddLayerIgnore(kPhysLayerFriend, kPhysLayerFriendProj);
	m_PhysWorldPtr->AddLayerIgnore(kPhysLayerEnemy, kPhysLayerEnemyProj);


	m_FireReady = true;

	//delete[] pngData;
}
コード例 #13
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