void ProjectiveTextureMethod::setRenderState(MethodVO* vo, IRenderable* renderable, IContext* context, Camera3D* camera)
{
	Matrix3D projMatrix;
	projMatrix.copyFrom(m_projector->getViewProjection());
	projMatrix.prepend(renderable->getRenderSceneTransform(camera));
	projMatrix.copyRawDataTo(vo->m_vertexData->data(), vo->m_vertexConstantsIndex, true);
}
Пример #2
0
void DirectionalLight::getObjectProjectionMatrix(IRenderable* renderable, Camera3D* camera, Matrix3D& result)
{
	Matrix3D matrix(renderable->getRenderSceneTransform(camera));
	matrix.append(getInverseSceneTransform());

	float projAABBPoints[24];
	BoundingVolumeBase* bounds = renderable->getSourceEntity()->getBounds();
	matrix.transformVectors(bounds->getAABBPoints(), projAABBPoints, 8);

	float xMin, yMin, zMin, xMax, yMax, zMax;
	xMin = yMin = zMin = MathConsts::Infinity;
	xMax = yMax = zMax = -MathConsts::Infinity;
	for (int i = 0; i < 24;)
	{
		float d = projAABBPoints[i++];
		if (d < xMin)
			xMin = d;
		if (d > xMax)
			xMax = d;

		d = projAABBPoints[i++];
		if (d < yMin)
			yMin = d;
		if (d > yMax)
			yMax = d;

		d = projAABBPoints[i++];
		if (d < zMin)
			zMin = d;
		if (d > zMax)
			zMax = d;
	}

	float invXRange = 1 / (xMax - xMin);
	float invYRange = 1 / (yMax - yMin);
	float invZRange = 1 / (zMax - zMin);
	float(&raw)[16] = result.m_rawData;
	raw[0] = 2 * invXRange;
	raw[5] = 2 * invYRange;
	raw[10] = invZRange;
	raw[12] = -(xMax + xMin) * invXRange;
	raw[13] = -(yMax + yMin) * invYRange;
	raw[14] = -zMin * invZRange;
	raw[1] = raw[2] = raw[3] = raw[4] = raw[6] = raw[7] = raw[8] = raw[9] = raw[11] = 0;
	raw[15] = 1;
	result.prepend(matrix);
}