• Advertisement
Sign in to follow this  

Convert right hand camera to left hand

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

If you intended to correct an error in the post then please contact us.

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;
D3DXMatrixRotationAxis (&rollMatrix, &pCamera2d->mLook, D3DXToRadian(pCamera2d->mAngle));
// 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);


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

Share this post

Link to post
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.


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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement