Crazy about my Game Engine.Just Help

Started by
5 comments, last by zyfu0000 14 years, 11 months ago
Hi, It is several months since I began to write my own engine(I call it Realm Engine) with the help of the ZFX Engine in the book <3D Game Engine Programing>.By now,I have completed several modules. But there maybe four faults in it,so I come to you all for help. 1. When I use the code SetView3D() or SetViewLookAt() to set the camera,it doesn't work even after I change the the Right,Up,Pos,Dir vector. What's worst,the sentence D3DXMatrixLookAtLH() doesn't work,either.Is there somewhere I have set it wrong? 2. I try to draw a triangle in the application.But if I set the parameter Z of vertexs' position less than 0.0f or larger than 1.0f,it woun't be drawn to the screen.I know it must be culled by the frustum,but I set it 1.0f---1000.0f using SetClipPlanes(1.0f,1000.0f); 3. When I try to draw a sphere in the application,a ellipse comes out instead of the sphere with its X-axis extended.So I have to scale the world matrix to keep its shape to still be a sphere.It mybe the aspect in the perspective projection matrix or the scale between width/height of the backbuffer,but I have checked it very carefully find nothing. 4. When I apply a texture to a triangle,its color in texture will be coved by the material.The texture just can be seen blurry,but you can see it for sure.And the texture looks lowering. Those four problems puzzle me for two weeks,but I cannot solve it.So please think about them.Thanks a lot!
Advertisement
Quote:Original post by zyfu0000
1. When I use the code SetView3D() or SetViewLookAt() to set the camera,it doesn't work even after I change the the Right,Up,Pos,Dir vector.
What's worst,the sentence D3DXMatrixLookAtLH() doesn't work,either.Is there somewhere I have set it wrong?
Possibly, we'll need to see some code. What do you mean "Doesn't work"?

Quote:Original post by zyfu0000
2. I try to draw a triangle in the application.But if I set the parameter Z of vertexs' position less than 0.0f or larger than 1.0f,it woun't be drawn to the screen.I know it must be culled by the frustum,but I set it 1.0f---1000.0f using SetClipPlanes(1.0f,1000.0f);
Again, we'll need to see some code. What vertex declaration / FVF are you using? If you're using transformed vertices (D3DFVF_XYZRHW), then the Z value is ignored and RHW needs to be between 0 and 1.

Quote:Original post by zyfu0000
3. When I try to draw a sphere in the application,a ellipse comes out instead of the sphere with its X-axis extended.So I have to scale the world
matrix to keep its shape to still be a sphere.It mybe the aspect in the perspective projection matrix or the scale between width/height of the
backbuffer,but I have checked it very carefully find nothing.
Again - we'll need to see code. But it sounds like you're either setting the aspect ratio wrong in the projection matrix, or your backbuffer is a very different size to your client area.

Quote:Original post by zyfu0000
4. When I apply a texture to a triangle,its color in texture will be coved by the material.The texture just can be seen blurry,but you can see it for
sure.And the texture looks lowering.
I don't really understand what you mean, can we see a screenshot?
1 and 2 might be related? Possibly your view and projection matrix may not be setup correctly? Having things that are not drawn when out of range for z = 0.0 to 1.0, sounds like you are in ortho mode? or like what Evil Steve said your FVF may not be correct.

As to D3DXMatrixLookAtLH not working? did u try printing out the value of the matrix to see if it is correct? or is it printing the wrong values?

You need to set the view matrix after calculating the matrix using SetTransform. But I think you are probably already doing it :)

Just my opinions =).
1.In the Render() function of the application using SetView3D():

HRESULT CD3D::SetView3D(const RealmVector &vRight,const RealmVector &vUp,const RealmVector &vDir,const RealmVector &vPos)
{
if (!m_bRunning)
{
return Realm_FAIL;
}
m_matView3D._14=0.0f;
m_matView3D._24=0.0f;
m_matView3D._34=0.0f;
m_matView3D._44=1.0f;
m_matView3D._11=vRight.x;
m_matView3D._21=vRight.y;
m_matView3D._31=vRight.z;
m_matView3D._41=-(vRight*vPos);
m_matView3D._12=vUp.x;
m_matView3D._22=vUp.y;
m_matView3D._32=vUp.z;
m_matView3D._42=-(vUp*vPos);
m_matView3D._13=vDir.x;
m_matView3D._23=vDir.y;
m_matView3D._33=vDir.z;
m_matView3D._43=-(vDir*vPos);
if (FAILED(m_pD3dDevice->SetTransform(D3DTS_VIEW,(D3DXMATRIX*)&m_matView3D)))
{
return Realm_FAIL;
}
CalculateViewProjMatrix();
CalculateWorldViewProjMatrix();
if (m_bUseShaders)
{
D3DXMATRIX *matView=(D3DXMATRIX*)&m_matView3D;
SetEffectConstant(DAT_MATRIX,"g_matView",matView);
}
return Realm_OK;
}
2.I used this to set my FVF :
#define D3DFVF_VERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)
3.The sphere is just a model I export from 3DMAX using my own plungin for exporting.
4.Sorry,I dont know how to post a picture on.Just like something a texture in the dense fog.
Thanks for replying.
Of cource,I have set break points to check the view matrix and proj matrix.Unfortunatly,they are all right to meet my calculation acording to the rules in the book.
Things are not drawn out if the Z parameter less than 0.0f or larger than 1.0f.
Quote: "...with the help of the ZFX Engine in the book <3D Game Engine Programing>...."

The code in this book is plagued with bugs! You are better off reading some other source, but you can use this book to learn about concepts (don't code from it).

Cheers.
Thanks for advise.I do not copy it to my engine.I just learn from it,and use its theory and ways to building engine,and I like its way to organise codes and mudules.Of course,it is not a complete engine,I will build my own.




By the way,I have solved the first and the second problems by setting the View and Project matrix up every call to draw the screen.But the third and the fourth I just can not make them out.Need you help.

This topic is closed to new replies.

Advertisement