Jump to content
  • Advertisement
Sign in to follow this  
FredericDumont

Problem with reflection with directx 9 /c++

This topic is 2537 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

Hi eveyone,

I am an amateur Directx programmer and have trouble to make a simple reflection mapping using planar reflection. The attached file show that my projected surface doesn't fit with the rest of my scene.
I' ve been struggling with this problem now for a few days...



Here is the code, I can't figure out what's the problem..

[font="Consolas"][font="Consolas"]D3DXMATRIX ReflectionViewMatrix;

D3DXPLANE WaterPlaneW;

D3DXMATRIX mWorld, mTWorld;

D3DXMatrixInverse(&mWorld,NULL,&matWorld);

D3DXMatrixTranspose(&mWorld,&mWorld);

WaterPlane = D3DXPLANE(0,-1,0,2);

D3DXPlaneTransform(&WaterPlaneW,&WaterPlane,&mWorld);

D3DXMatrixMultiply(&MatReflectW,&matWorld,&MatReflect);

D3DXMatrixReflect(&MatReflectW, &WaterPlane);







ReflectionViewMatrix = matView*matProj;



D3DXMatrixInverse(&ReflectionViewMatrix ,NULL,&ReflectionViewMatrix);

D3DXMatrixTranspose(&ReflectionViewMatrix ,&ReflectionViewMatrix );

D3DXPLANE ViewSpacePlane;

ReflectionPlane = D3DXPLANE(0,-1,0,2);

D3DXPlaneNormalize(&ReflectionPlane,&ReflectionPlane);

D3DXPlaneTransform(&ViewSpacePlane,&ReflectionPlane,&ReflectionViewMatrix);

ViewPort.X = 0;

ViewPort.Y = 0;

ViewPort.Height = 512;

ViewPort.Width = 512;



ViewPort.MaxZ = 1.0f;

ViewPort.MinZ = 0.0f;

d3ddev->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);



RenderToSurface->BeginScene(Surface,&ViewPort);



d3ddev->Clear(0,NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,0),1.0f, 0.0f);

d3ddev->SetClipPlane(0,ViewSpacePlane);

d3ddev->SetRenderState(D3DRS_CLIPPLANEENABLE,D3DCLIPPLANE0);

d3ddev->SetTransform(D3DTS_WORLD,&(MatReflectW));



[/font]

[/font][font="Consolas"][color="#008000"][font="Consolas"][color="#008000"][font="Consolas"][color="#008000"]/* Rendering the scene again*/[/font][/font][/font]

[font="Consolas"][color="#008000"][font="Consolas"][color="#008000"][font="Consolas"][color="#008000"][/font][/font][/font][font="Consolas"][font="Consolas"] D3DXMATRIX matRot,

matScale,

matTrans,

Result;

ter->RenderTerrain();

d3ddev->SetRenderState(D3DRS_CULLMODE,D3DCULL_CW);



cube->RenderNorthFace();

cube->RenderTopFace();

cube->RenderEastFace();

cube->RenderSouthFace();

cube->RenderWestFace();

cube->RenderBackFace();

D3DXMatrixTranslation(&matTrans,60,4,40);

D3DXMatrixRotationX(&matRot,D3DXToRadian(90));

D3DXMatrixScaling(&matScale,3,3,3);

Result = matScale*matRot*matTrans;

d3ddev->SetTransform(D3DTS_WORLD, &Result);

mesh->RenderMesh();

D3DXMatrixTranslation(&matTrans,86,3,70);

D3DXMatrixRotationX(&matRot,D3DXToRadian(90));

D3DXMatrixScaling(&matScale,3,3,3);

Result = matScale*matRot*matTrans;

d3ddev->SetTransform(D3DTS_WORLD, &Result);

mesh->RenderMesh();

D3DXMatrixTranslation(&matTrans,30,1,15);

D3DXMatrixRotationX(&matRot,D3DXToRadian(90));

D3DXMatrixScaling(&matScale,3,3,3);

Result = matScale*matRot*matTrans;

d3ddev->SetTransform(D3DTS_WORLD, &Result);

mesh->RenderMesh();

D3DXMatrixTranslation(&matTrans,20,1,15);

D3DXMatrixRotationX(&matRot,D3DXToRadian(90));

D3DXMatrixScaling(&matScale,3,3,3);

Result = matScale*matRot*matTrans;

d3ddev->SetTransform(D3DTS_WORLD, &Result);

mesh->RenderMesh();

D3DXMatrixTranslation(&matTrans,60,1,45);

D3DXMatrixRotationX(&matRot,D3DXToRadian(90));

D3DXMatrixScaling(&matScale,3,3,3);

Result = matScale*matRot*matTrans;

d3ddev->SetTransform(D3DTS_WORLD, &Result);

mesh->RenderMesh();

D3DXMatrixTranslation(&matTrans,70,5,45);

D3DXMatrixRotationX(&matRot,D3DXToRadian(90));

D3DXMatrixScaling(&matScale,3,3,3);

Result = matScale*matRot*matTrans;

d3ddev->SetTransform(D3DTS_WORLD, &Result);

mesh->RenderMesh();

D3DXMatrixTranslation(&matTrans,65,5,40);

D3DXMatrixRotationX(&matRot,D3DXToRadian(90));

D3DXMatrixScaling(&matScale,3,3,3);

Result = matScale*matRot*matTrans;

d3ddev->SetTransform(D3DTS_WORLD, &Result);

mesh->RenderMesh();

D3DXMatrixTranslation(&matTrans,60,2,90);

D3DXMatrixRotationX(&matRot,D3DXToRadian(90));

D3DXMatrixScaling(&matScale,0.5,0.5,0.5);

Result = matScale*matRot*matTrans;

d3ddev->SetTransform(D3DTS_WORLD, &Result);

mesh1->RenderMesh();

D3DXMatrixTranslation(&matTrans,80,2,60);

D3DXMatrixRotationX(&matRot,D3DXToRadian(90));

D3DXMatrixScaling(&matScale,0.5,0.5,0.5);

Result = matScale*matRot*matTrans;

d3ddev->SetTransform(D3DTS_WORLD, &Result);

mesh2->RenderMesh();



[/font]

[/font][font="Consolas"][color="#008000"][font="Consolas"][color="#008000"][font="Consolas"][color="#008000"]/* Rendering the scene again*/[/font][/font][/font]

[font="Consolas"][color="#008000"][font="Consolas"][color="#008000"][font="Consolas"][color="#008000"][/font][/font][/font][font="Consolas"][font="Consolas"]

d3ddev->SetRenderState(D3DRS_CLIPPLANEENABLE,FALSE);

d3ddev->SetTransform(D3DTS_WORLD,&(matWorld));

RenderToSurface->EndScene(D3DX_FILTER_NONE);

d3ddev->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);

[/font][/font]
Thanks in advance for any help you could give me !

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!