Jump to content

  • Log In with Google      Sign In   
  • Create Account


Problems with camera looking up


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Telanor   Members   -  Reputation: 1296

Like
1Likes
Like

Posted 09 March 2013 - 10:49 PM

I'm trying to calculate a view/projection/bounding frustum for the 6 directions of a point light and I'm having trouble with the views pointing along the Y axis. Our game uses a right-handed, Y-up system. For the other 4 directions I create the LookAt matrix using (0, 1, 0) as the up vector. Obviously that doesn't work when looking along the Y axis so for those I use an up vector of (-1, 0, 0) for -Y and (1, 0, 0) for +Y. The view matrix seems to come out correctly (and the projection matrix always stays the same), but the bounding frustum is definitely wrong.

This is the code I'm using:
camera.Projection = Matrix.PerspectiveFovRH((float)Math.PI / 2, ShadowMapSize / (float)ShadowMapSize, 1, 5);

for(var i = 0; i < 6; i++)
{
	var renderTargetView = shadowMap.GetRenderTargetView((TextureCubeFace)i);
	var up = DetermineLightUp((TextureCubeFace) i);
	var forward = DirectionToVector((TextureCubeFace) i);

	camera.View = Matrix.LookAtRH(Position, Position + forward, up);
	camera.BoundingFrustum = new BoundingFrustum(camera.View * camera.Projection);
}

private static Vector3 DirectionToVector(TextureCubeFace direction)
{
	switch (direction)
	{
		case TextureCubeFace.NegativeX:
			return -Vector3.UnitX;
		case TextureCubeFace.NegativeY:
			return -Vector3.UnitY;
		case TextureCubeFace.NegativeZ:
			return -Vector3.UnitZ;
		case TextureCubeFace.PositiveX:
			return Vector3.UnitX;
		case TextureCubeFace.PositiveY:
			return Vector3.UnitY;
		case TextureCubeFace.PositiveZ:
			return Vector3.UnitZ;
		default:
			throw new ArgumentOutOfRangeException("direction");
	}
}

private static Vector3 DetermineLightUp(TextureCubeFace direction)
{
	switch (direction)
	{
		case TextureCubeFace.NegativeY:
			return -Vector3.UnitX;
		case TextureCubeFace.PositiveY:
			return Vector3.UnitX;
		default:
			return Vector3.UnitY;
	}
}
I can post some example output if it'll help.

Edited by Telanor, 09 March 2013 - 10:51 PM.


Sponsor:

#2 riuthamus   Moderators   -  Reputation: 4601

Like
0Likes
Like

Posted 17 March 2013 - 03:51 AM

If this is too technical let us know. I can provide you with a more basic understanding. Curious if anybody had any thoughts on this as it would help us deal with our point light issue. I can provide pictures/video!


Edited by riuthamus, 17 March 2013 - 03:51 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS