Skip to main content
GameDev.net gamedev.net
🔒 Locked

Inverted Projection / Rendertarget Problems

Started by Carandiru Jan 4, 2007 at 7:29 PM 4 replies 1.7k views
Original Post
Carandiru
Carandiru
Ouch this problem is absolutely confusing, and I'm hoping either someone has run into the same problem or can atleast help me out a little bit. Basically we have a render target setup with orthographic projection. D3DXMatrixOrthoLH( &const_cast(m_matProjOrthoRTx512), 512, 512, -5000.0f, 5000.0f ); Next Step is Rendering a Terrain Patch Mesh to the The RenderTarget that is of 512x512, the Terrain Patch is 64x64 Vertices, and is scaled to the rendertarget resolution. 64 'x' vertices by 64 'z' vertices where height is represented by 'y'. So the default view of the orthographic projection is looking to into Z, not down onto y like we would typically use for viewing the terrain patch TOP DOWN. D3DXMatrixTranslation(&matModel, 0.0f, 0.0f, 0.0f); D3DXQuaternionRotationYawPitchRoll(&qR, D3DXToRadian(90.0f), D3DXToRadian(0.0f), D3DXToRadian(90.0f)); D3DXMatrixRotationQuaternion(&matRot, &qR); D3DXMatrixScaling(&matScale, RT512/RT64, RT512/RT64, RT512/RT64); D3DXMatrixMultiply(&matModel, &matRot, &matModel); D3DXMatrixMultiply(&matModel, &matScale, &matModel); // Final Model View Projection Matrix // D3DXMatrixMultiply(&matModelViewProj, &matModel, &m_matProjOrthoRTx512); So I made these key points to show that I have to orient the model to compensate for this. The Problem: Its Inverted!!!!! How on earth it is inverted, I'm trying to figure out. It seams like a mirror image of the same terrain patch rendered normally on the main screen. If I orient the "pitch" +-90 degrees, it fixes X from being inverted but Z is still inverted, and vice versa it fixes z from being inverted, but x is still inverted (mirrorred). So this is rather confusing. I've tried D3DXMatrixOrthoLH( &const_cast(m_matProjOrthoRTx512), -512, -512, -5000.0f, 5000.0f ); D3DXMatrixOrthoLH( &const_cast(m_matProjOrthoRTx512), -512, 512, -5000.0f, 5000.0f ); D3DXMatrixOrthoLH( &const_cast(m_matProjOrthoRTx512), 512, -512, -5000.0f, 5000.0f ); No avail, still run into the same roadblock of being able to fix one corner of the patch, but either x xor z is still mirrored. And with several different combinations of 3DXQuaternionRotationYawPitchRoll(&qR, D3DXToRadian(-90.0f), D3DXToRadian(0.0f), D3DXToRadian(90.0f)); 3DXQuaternionRotationYawPitchRoll(&qR, D3DXToRadian(90.0f), D3DXToRadian(0.0f), D3DXToRadian(-90.0f)); 3DXQuaternionRotationYawPitchRoll(&qR, D3DXToRadian(-90.0f), D3DXToRadian(0.0f), D3DXToRadian(-90.0f)); 3DXQuaternionRotationYawPitchRoll(&qR, D3DXToRadian(90.0f), D3DXToRadianD3DXToRadian(-90.0f), D3DXToRadian(90.0f)); Where some of them don't draw the mesh due to the fact that its is looking "under that patch". Help me out, cause I've stared at this problem for far to long.
Carandiru
Carandiru
Geez could someone say something?
Schrompf
Schrompf
Have a closer look at the coordinate space section of the D3D documentation. As far as I know, the post-projected Y coordinate is growing down to up, being inverted in respect to the normal texture coord projection you might use. There's no way to achieve a inversion with rotations only. Maybe insert a D3DXMatrixScaling() into the beginning of your projection matrix.

Just guessing, sorry. I remember having that problem one time or the other, too, but I can't dig up the places in my source where I solved it. So it's only a vague hint.

Bye, Thomas
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.
Carandiru
Carandiru
Well I'm assuming this, but these seems to more of proper way of doing it, and makes more sense.

Rather than rotating the model, I'm just setting a look at matrix to do basically the same thing, but more "naturally".

D3DXMATRIXA16 matView, matProj;

D3DXMatrixOrthoOffCenterLH(&matProj, -RT256, RT256, -RT256, RT256, 0.0f, 5000.0f);
D3DXMatrixLookAtLH( &matView,
&D3DXVECTOR3(0.0f, 5000.0f, 0.0f),
&D3DXVECTOR3(0.0f, 0.0f, 0.0f),
&D3DXVECTOR3(0.0f, 0.0f, 1.0f) );

D3DXMatrixMultiply(&const_cast(m_matViewProjOrthoRTx512),
&matView, &matProj);

D3DXMatrixTranslation(&matModel, 0.0f, 0.0f, 0.0f);
D3DXMatrixScaling(&matScale, RT512/RT64, RT512/RT64, RT512/RT64);
D3DXMatrixMultiply(&matModel, &matScale, &matModel);

// Final Model View Projection Matrix //
D3DXMatrixMultiply(&matModelViewProj, &matModel, &m_matViewProjOrthoRTx512);

So I'm assuming this a more proper way of doing this. But really man, it still is inverted, changing the parameters to D3DXMatrixOrthoOffCenterLH be reversed, and negating the up vector in D3DXMatrixLookAtLH still gives me the same confusing problem.

Messing with these parameters gives me different mirrored combinations.

Mirrored X, Mirrored Z
Mirrored X, Correct Z
Correct X, Mirrored Z

But never:
Correct X, Correct Z

Mind bogling confusing. It is probably REALLY simple too I bet. If anyone can lend a helping hand I might just have to honor you as the bestest online buddy I've ever had!

:P

Thanks again,
Carandiru
Carandiru
bump
TheAdmiral
TheAdmiral
Are you sure you're actually using a left-handed coordinate system? It sounds like you'd be better off using D3DXMatrixOrthoRH. This will flip the direction of your z axis, so you should be able to attain your 'Correct X, Correct Z'.

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.