/*******************************************************************************
 * Function Name  : StepLight
 * Inputs		  : *pLight
 * Description    : Advance one step in the light rotation.
 *******************************************************************************/
void OGLESLighting::StepLight(SLightVars &Light)
{
	PVRTMat4 RotationMatrix, RotationMatrixX, RotationMatrixY, RotationMatrixZ;

	// Increase rotation angles
	Light.vRotation.x += Light.vRotationStep.x;
	Light.vRotation.y += Light.vRotationStep.y;
	Light.vRotation.z += Light.vRotationStep.z;

	while(Light.vRotation.x > 360.0f) Light.vRotation.x -= 360.0f;
	while(Light.vRotation.y > 360.0f) Light.vRotation.y -= 360.0f;
	while(Light.vRotation.z > 360.0f) Light.vRotation.z -= 360.0f;

	// Create three rotations from rotation angles
	RotationMatrixX = PVRTMat4::RotationX(Light.vRotation.x * (PVRT_PIf / 180.0f));
	RotationMatrixY = PVRTMat4::RotationY(Light.vRotation.y * (PVRT_PIf / 180.0f));
	RotationMatrixZ = PVRTMat4::RotationZ(Light.vRotation.z * (PVRT_PIf / 180.0f));

	// Build transformation matrix by concatenating all rotations
	RotationMatrix =  RotationMatrixZ * RotationMatrixY * RotationMatrixX;

	// Transform light with transformation matrix, setting w to 1 to indicate point light
	PVRTTransformArray((PVRTVec3*)&Light.Position, &Light.vPosition, 1, &RotationMatrix);

	Light.Position.w = 1.0f;
}
Example #2
0
/*!***************************************************************************
 @Function			PVRTTransformArrayBack
 @Output			pTransformedVertex
 @Input				pVertex
 @Input				nNumberOfVertices
 @Input				pMatrix
 @Description		Transform all vertices in pVertex by the inverse of pMatrix
					and store them in pTransformedVertex.
					- pTransformedVertex is the pointer that will receive transformed vertices.
					- pVertex is the pointer to untransformed object vertices.
					- nNumberOfVertices is the number of vertices of the object.
					- pMatrix is the matrix used to transform the object.
*****************************************************************************/
void PVRTTransformArrayBack(
    PVRTVECTOR3			* const pTransformedVertex,
    const PVRTVECTOR3	* const pVertex,
    const int			nNumberOfVertices,
    const PVRTMATRIX	* const pMatrix)
{
    PVRTMATRIX	mBack;

    PVRTMatrixInverse(mBack, *pMatrix);
    PVRTTransformArray(pTransformedVertex, pVertex, nNumberOfVertices, &mBack);
}