本文整理汇总了C++中Object3D::getType方法的典型用法代码示例。如果您正苦于以下问题:C++ Object3D::getType方法的具体用法?C++ Object3D::getType怎么用?C++ Object3D::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Object3D
的用法示例。
在下文中一共展示了Object3D::getType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void World::update(float dt)
{
Player* player = NULL;
// Update all the objects.
for(int i = 0; i < mObjectList.size(); i++)
{
Object3D* object = mObjectList[i];
// Remove from the list if dead.
if(!object->getAlive()) {
// Inform the current wave about the dead enemy. [TODO] Check if we are in PlayState.
if(object->getType() == ENEMY)
PlayState::Instance()->getCurrentWave()->enemyKilled();
removeObject(object);
continue;
}
// Get the distance above the ground.
float distance = object->getPosition().y - mTerrain->getHeight(object->getPosition().x, object->getPosition().z);
// Snap to ground.
// Note the +50 to give it some margin (only for enemies).
float margin = object->getType() != PLAYER ? 50 : 0;
if(distance < object->getHeightOffset() + margin && object->getVelocity().y <= 0)
{
object->setPosition(object->getPosition() - D3DXVECTOR3(0, distance, 0) + D3DXVECTOR3(0, object->getHeightOffset(), 0));
object->setVelocity(D3DXVECTOR3(object->getVelocity().x, 0, object->getVelocity().z));
}
// Set on ground.
if(distance < object->getHeightOffset() + 0.2)
object->setOnGround(true);
else
object->setOnGround(false);
// Update the object.
object->update(dt);
// Gravity.
object->accelerate(0, getGravity(), 0);
// Friction.
if(object->getOnGround())
{
D3DXVECTOR3 norm;
D3DXVec3Normalize(&norm, &object->getVelocity());
D3DXVECTOR3 velocity = norm * mFriction * object->getFriction();//object->getVelocity()
object->accelerate(velocity.x, 0.0f, velocity.z);
}
// Move the object with it's speed.
// [NOTE] Only update the objects position here! Change the speed on other places instead!
D3DXVECTOR3 speed = object->getVelocity();
object->move(speed.x, speed.y, speed.z);
if(object->getType() == PLAYER)
player = dynamic_cast<Player*>(object);
}
// [HACK]
// Test if player is in range of a powerup.
if(player != NULL)
{
for(int i = 0; i < mObjectList.size(); i++) {
if(mObjectList[i]->getType() == ENERGY_POWERUP) {
D3DXVECTOR3 dist = mObjectList[i]->getPosition() - player->getPosition();
dist.y = 0.0f;
float d = sqrt(dist.x*dist.x + dist.z*dist.z);
if(d < 70) // PICKUP_RADIUS
(dynamic_cast<Powerup*>(mObjectList[i]))->pickup(player);
}
else
continue;
}
}
// Terrain editing.
// [NOTE] Disabled.
//editTerrain();
}