Beispiel #1
0
bool OpenGLRenderer::renderBoundingVolumes(Object3D &object, Camera &camera, RenderTarget &renderTarget, bool showSphere, bool showAABB,
                                           bool showOOBB)
{
    if (showSphere) {
        if (renderBoundingSphere(object.getBoundingSphere(), object.getPosition(), glm::vec3(1.0f, 0.0f, 0.0f), camera, renderTarget) ==
            false) {
            return false;
        }
    }
    if (showAABB) {
        if (renderBoundingBox(object.getAABB(), glm::mat4(1.0f), glm::vec3(0.0f, 1.0f, 0.0f), camera, renderTarget) == false) {
            return false;
        }
    }
    if (showOOBB) {
        if (renderBoundingBox(object.getOOBB(), object.getModelMatrix(), glm::vec3(0.0f, 0.0f, 1.0f), camera, renderTarget) == false) {
            return false;
        }
    }
    return true;
}
Beispiel #2
0
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();
}