# Billboarding/Rotation Issue

This topic is 3033 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've made a hemisphere of vertices and I'm attempting to get it to rotate so as to always face the camera position. It works for the most part but when the camera position moves into negative X values the rotation seems to go haywire. Negative Y and Z values seem to cause no problems.

It's probably a simple solution but I can't seem to get what the problem is. If anyone could help me I'd greatly appreciate it.

Here's what I'm using to create the rotation matrix. I'm trying to keep the "right" vector on the XZ plane as I only want the hemisphere to pan and tilt, not roll.

	origTarget = D3DXVECTOR3(0.0f, 0.0f, 1.0f);	origRight = D3DXVECTOR3(1.0f, 0.0f, 0.0f);	origUp = D3DXVECTOR3(0.0f, 1.0f, 0.0f);	D3DXVECTOR3 terrainToCamera = D3DXVECTOR3(GetCamera().position().x - mInfo.PlanetPosition.x, GetCamera().position().y - mInfo.PlanetPosition.y, GetCamera().position().z - mInfo.PlanetPosition.z);// Project the vector to the XZ plane	D3DXVECTOR3 terrainToCameraXZ = D3DXVECTOR3(terrainToCamera.x, 0.0f, terrainToCamera.z);	D3DXVec3Normalize(&terrainToCameraXZ, &terrainToCameraXZ);	float yRotation = acos( D3DXVec3Dot( &terrainToCameraXZ, &origTarget) );	D3DXMATRIX yRotationMatrix;	D3DXMatrixRotationY(&yRotationMatrix, yRotation);	D3DXVECTOR3 rotatedRight;	D3DXVec3TransformCoord(&rotatedRight, &origRight, &yRotationMatrix);		D3DXVec3Normalize(&rotatedRight, &rotatedRight);	D3DXVec3Normalize(&terrainToCamera, &terrainToCamera);	D3DXVECTOR3 rotatedUp;	D3DXVec3Cross(&rotatedUp, &rotatedRight, &terrainToCamera);	D3DXVec3Normalize(&rotatedUp, &rotatedUp);	D3DXMATRIX terrainWorld = D3DXMATRIX(rotatedRight.x, rotatedRight.y, rotatedRight.z, 0.0f,										 rotatedUp.x, rotatedUp.y, rotatedUp.z, 0.0f,										 terrainToCamera.x, terrainToCamera.y, terrainToCamera.z, 0.0f,										 mInfo.PlanetPosition.x, mInfo.PlanetPosition.y, mInfo.PlanetPosition.z, 1.0f);

[Edited by - FatPope on August 23, 2010 1:40:35 PM]

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 9
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633679
• Total Posts
3013300
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!