예제 #1
0
void NodeCube::draw() {
	// Update the OpenGL textures if needed
	for (uint i = 0; i < 6; i++) {
		if (_faces[i]->isTextureDirty() && isFaceVisible(i)) {
			_faces[i]->uploadTexture();
		}
	}

	Texture *textures[6];
	for (uint i = 0; i < 6; i++) {
		textures[i] = _faces[i]->_texture;
	}

	_vm->_gfx->drawCube(textures);
}
예제 #2
0
파일: Block.cpp 프로젝트: gbougard/NBK
	bool CBlock::getFaceAproximation(BLOCK_FACE_SELECTOR faceSelector, sSimpleFace &faceApprox)
	{
		if (faceSelector>BFS_BOTTOM || faceSelector==BFS_TOP || !isFaceVisible(faceSelector))
		{
			return false;
		}

		switch (faceSelector)
		{
			case BFS_FRONT:
			{
				faceApprox.a = boundingBox.E;
				faceApprox.b = boundingBox.F;
				faceApprox.c = boundingBox.B;
				faceApprox.d = boundingBox.A;
				break;
			}

			case BFS_BACK:
			{
				faceApprox.a = boundingBox.G;
				faceApprox.b = boundingBox.H;
				faceApprox.c = boundingBox.D;
				faceApprox.d = boundingBox.C;
				break;
			}

			case BFS_RIGHT:
			{
				faceApprox.a = boundingBox.C;
				faceApprox.b = boundingBox.B;
				faceApprox.c = boundingBox.F;
				faceApprox.d = boundingBox.G;
				break;
			}

			case BFS_LEFT:
			{
				faceApprox.a = boundingBox.H;
				faceApprox.b = boundingBox.E;
				faceApprox.c = boundingBox.A;
				faceApprox.d = boundingBox.D;
				break;
			}
		}

		return true;
	}
예제 #3
0
void Node::update() {
	// First undraw ...
	for (uint i = 0; i < _spotItems.size(); i++) {
		_spotItems[i]->updateUndraw();
	}

	// ... then redraw
	for (uint i = 0; i < _spotItems.size(); i++) {
		_spotItems[i]->updateDraw();
	}

	bool needsUpdate = false;
	for (uint i = 0; i < _effects.size(); i++) {
		needsUpdate |= _effects[i]->update();
	}

	// Apply the effects for all the faces
	for (uint faceId = 0; faceId < 6; faceId++) {
		Face *face = _faces[faceId];

		if (face == 0)
			continue; // No such face in this node

		if (!isFaceVisible(faceId)) {
			continue; // This face is not currently visible
		}

		uint effectsForFace = 0;
		for (uint i = 0; i < _effects.size(); i++) {
			if (_effects[i]->hasFace(faceId))
				effectsForFace++;
		}

		if (effectsForFace == 0)
			continue;
		if (!needsUpdate && !face->isTextureDirty())
			continue;

		// Alloc the target surface if necessary
		if (!face->_finalBitmap) {
			face->_finalBitmap = new Graphics::Surface();
		}
		face->_finalBitmap->copyFrom(*face->_bitmap);

		if (effectsForFace == 1) {
			_effects[0]->applyForFace(faceId, face->_bitmap, face->_finalBitmap);

			face->addTextureDirtyRect(_effects[0]->getUpdateRectForFace(faceId));
		} else if (effectsForFace == 2) {
			// TODO: Keep the same temp surface to avoid heap fragmentation ?
			Graphics::Surface *tmp = new Graphics::Surface();
			tmp->copyFrom(*face->_bitmap);

			_effects[0]->applyForFace(faceId, face->_bitmap, tmp);
			_effects[1]->applyForFace(faceId, tmp, face->_finalBitmap);

			tmp->free();
			delete tmp;

			face->addTextureDirtyRect(_effects[0]->getUpdateRectForFace(faceId));
			face->addTextureDirtyRect(_effects[1]->getUpdateRectForFace(faceId));
		} else {
			error("Unable to render more than 2 effects per faceId (%d)", effectsForFace);
		}
	}
}