byte MatrixLampPattern::getLampBank(int x) {
	byte result = 0;
	for (int row = 0; row < 8; row++) {
		result <<= 1;
		if (getLamp(x, row)) {
			result |= 1;
		}
	}
	return result;
}
byte UniversalLampPattern::getLampBank(int bankIndex) {
	byte result = 0;
	int bankBase = bankIndex << 3;
	for (int i = 7; i >= 0; i--) {
		result <<= 1;
		if (getLamp(bankBase + i)) {
			result |= 1;
		}
	}
	return result;
}
示例#3
0
// Texture object initialization
static int Texture_init(Texture *self, PyObject *args, PyObject *kwds)
{
	// parameters - game object with video texture
	PyObject *obj = NULL;
	// material ID
	short matID = 0;
	// texture ID
	short texID = 0;
	// texture object with shared texture ID
	Texture * texObj = NULL;

	static const char *kwlist[] = {"gameObj", "materialID", "textureID", "textureObj", NULL};

	// get parameters
	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|hhO!",
		const_cast<char**>(kwlist), &obj, &matID, &texID, &TextureType,
		&texObj))
		return -1;

	// if parameters are available
	if (obj != NULL)
	{
		// process polygon material or blender material
		try
		{
			// get pointer to texture image
			RAS_IPolyMaterial * mat = getMaterial(obj, matID);
			KX_LightObject * lamp = getLamp(obj);
			if (mat != NULL)
			{
				// is it blender material or polygon material
				if (mat->GetFlag() & RAS_BLENDERGLSL)
				{
					self->m_imgTexture = static_cast<KX_BlenderMaterial*>(mat)->getImage(texID);
					self->m_useMatTexture = false;
				} else
				{
					// get blender material texture
					self->m_matTexture = static_cast<KX_BlenderMaterial*>(mat)->getTex(texID);
					self->m_useMatTexture = true;
				}
			}
			else if (lamp != NULL)
			{
				self->m_imgTexture = lamp->GetLightData()->GetTextureImage(texID);
				self->m_useMatTexture = false;
			}

			// check if texture is available, if not, initialization failed
			if (self->m_imgTexture == NULL && self->m_matTexture == NULL)
				// throw exception if initialization failed
				THRWEXCP(MaterialNotAvail, S_OK);

			// if texture object is provided
			if (texObj != NULL)
			{
				// copy texture code
				self->m_actTex = texObj->m_actTex;
				self->m_mipmap = texObj->m_mipmap;
				if (texObj->m_source != NULL)
					Texture_setSource(self, reinterpret_cast<PyObject*>(texObj->m_source), NULL);
			}
			else
				// otherwise generate texture code
				glGenTextures(1, (GLuint*)&self->m_actTex);
		}
		catch (Exception & exp)
		{
			exp.report();
			return -1;
		}
	}
	// initialization succeded
	return 0;
}