# Convert right hand camera to left hand

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

## Recommended Posts

I'm trying to convert this camera to left hand, but I can't figure it out.

[source lang = "cpp"]
D3DXMATRIX mTrans, mMatView, mMatProjection;
D3DXMatrixIdentity (&mMatView);
D3DXMatrixIdentity (&mMatProjection);

// ----- View matrix -----

pCamera2d->mLook = D3DXVECTOR3 (0.0f, 0.0f, 1.0f);
pCamera2d->mUp = D3DXVECTOR3 (0.0f, 1.0f, 0.0f);
pCamera2d->mRight = D3DXVECTOR3 (-1.0f, 0.0f, 0.0f);

// ----- Rotation -----

// Roll is rotation around the z axis (m_look)
// Create a matrix that can carry out this rotation
D3DXMATRIX rollMatrix;
// To apply roll we rotate up and right about the look vector (using our roll matrix)
D3DXVec3TransformCoord (&pCamera2d->mRight, &pCamera2d->mRight, &rollMatrix);
D3DXVec3TransformCoord (&pCamera2d->mUp, &pCamera2d->mUp, &rollMatrix);

// Build the view matrix from the transformed camera axis
mMatView._11 = pCamera2d->mRight.x; mMatView._12 = pCamera2d->mUp.x; mMatView._13 = pCamera2d->mLook.x;
mMatView._21 = pCamera2d->mRight.y; mMatView._22 = pCamera2d->mUp.y; mMatView._23 = pCamera2d->mLook.y;
mMatView._31 = pCamera2d->mRight.z; mMatView._32 = pCamera2d->mUp.z; mMatView._33 = pCamera2d->mLook.z;

mMatView._41 = -D3DXVec3Dot (&pCamera2d->mPos, &pCamera2d->mRight);
mMatView._42 = -D3DXVec3Dot (&pCamera2d->mPos, &pCamera2d->mUp);
mMatView._43 = -D3DXVec3Dot (&pCamera2d->mPos, &pCamera2d->mLook);

// ---- 2d set ----

D3DXMatrixRotationZ (&mTrans, (float) PI);
D3DXMatrixMultiply (&mMatView, &mTrans, &mMatView);
D3DXMatrixTranslation (&mTrans, -0.5f, -0.5f, 0);
D3DXMatrixMultiply (&mMatView, &mTrans, &mMatView);

// ---- Zoom ----

if (pCamera2d->mZoom != 1.0f)
{
D3DXMatrixScaling (&mTrans, pCamera2d->mZoom, pCamera2d->mZoom, pCamera2d->mZoom);
D3DXMatrixMultiply (&mMatView, &mMatView, &mTrans);
}
// ----- Set transformation -----

mInfo.mDevice->SetTransform (D3DTS_VIEW, &mMatView);

// ----- Projection matrix -----

D3DXMatrixOrthoRH (&mMatProjection, (float) mInfo.mViewPortWidth, (float) mInfo.mViewPortHeight, -2048.0f, 2048.0f);
mInfo.mDevice->SetTransform (D3DTS_PROJECTION, &mMatProjection);

[/source]

I know to changed anything with "RH" to "LH", but the view matrix is throwing me off. Any suggestions?

##### Share on other sites
The right vector should be (1, 0, 0) in a left-handed coordinate system, and not (-1, 0, 0).

##### Share on other sites

The right vector should be (1, 0, 0) in a left-handed coordinate system, and not (-1, 0, 0).

When I set it to positive 1 it draws backwards on the x-axis.

EDIT:

I found a way around this by rotating 180 degrees so that it is correct, but I don't want to do it like this.

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631712
• Total Posts
3001849
×