Someone clarify what this code means please...

Started by
5 comments, last by EbonySeraph 22 years, 9 months ago
D3DXMATRIX mat; D3DXMatrixPerspectiveFovLH(&mat, D3DX_PI/6, WINDOW_WIDTH/WINDOW_HEIGHT, 1.0, 100.0); pDevice->SetTransform(D3DTS_PROJECTION, &(D3DMATRIX)mat); D3DXMatrixIdentity(&mat); pDevice->SetTransform(D3DTS_WORLD, &(D3DMATRIX)mat); D3DXMatrixTranslation(&mat, 0, 0, 10.0); pDevice->SetTransform(D3DTS_VIEW, &(D3DMATRIX)mat); I dont get what it does....sort of. I do sometimes, then all at once I forget. I need it to stick. "Ogun''s Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.
"Ogun's Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.
Advertisement
And why should you use PeekMessage instead of GetMessage. I have a really good book on Windows Programming and it always uses get message except for printing when it uses PeekMessage. It explained why it used it there which is good. But in NeXe''s tutorial I dont see why use PeekMessage.

"Ogun''s Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.
"Ogun's Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.
About the matrices - it may sound strange, but I''d recommend the OpenGL red book for a good explanation of what the matrices mean and why they''re applied. Of course, the actual code will be in OpenGL, but it will be really easy to map that to the DX code.
http://www.amazon.com/exec/obidos/ASIN/0201604582/o/qid=993957013/sr=2-1/ref=aps_sr_b_1_1/104-0576845-2987947
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
quote:Original post by EbonySeraph
And why should you use PeekMessage instead of GetMessage. I have a really good book on Windows Programming and it always uses get message except for printing when it uses PeekMessage. It explained why it used it there which is good. But in NeXe''s tutorial I dont see why use PeekMessage.


If your doing game programming you should use PeekMessage. GetMessage only works IF there is a message in the queue (i forgot how to spell it...) So you check for peekmessage and if there isn''t a message then you do your games rendering.

PaladinGLT
I agree, PeekMessage is what you should use for your game loop, EbonySeraph. You could use either, but it would be harder. Trust me.
The point is that GetMessage will block until a message is received. You really don''t want anything to block in your main game loop.
quote:Original post by EbonySeraph
D3DXMATRIX mat;

D3DXMatrixPerspectiveFovLH(&mat, D3DX_PI/6, WINDOW_WIDTH/WINDOW_HEIGHT, 1.0, 100.0);
pDevice->SetTransform(D3DTS_PROJECTION, &(D3DMATRIX)mat);

D3DXMatrixIdentity(&mat);
pDevice->SetTransform(D3DTS_WORLD, &(D3DMATRIX)mat);

D3DXMatrixTranslation(&mat, 0, 0, 10.0);
pDevice->SetTransform(D3DTS_VIEW, &(D3DMATRIX)mat);

I dont get what it does....sort of. I do sometimes, then all at once I forget. I need it to stick.

"Ogun''s Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.


The D3DXMatrixPerspectiveFovLH function creates a matrix (mat) that represents your projection - i.e. your projection matrix - for a left-handed coordinate system. This represents how your 3D world is mapped to your screen.

The D3DX_PI/6 represents your FOV (field of view) which is how wide you can ''see''.

The WINDOW_WIDTH/WINDOW_HEIGHT represents your aspect ratio - which determines the shape of your rendered primitives, etc. in your world. The correct aspect ratio will ensure that square objects do in fact appear square when viewed on your screen.

The 1.0 and 100.0 values define your near and far clipping plane respecively, i.e. how far you can see into the distance and how close the want objects near to you to be clipped. Imagine that it defines a ''slice'' of your 3D scene that you want to view between the values of 1.0 and 100.0.


The pDevice->SetTransform(D3DTS_WORLD....) is responsible for transforming your 3D geometry into world-space. It takes, say, your cube object and maps it into the world along with your other objects, etc. You have specified an identity matrix for your world transform so your geometry will be based about your world origin - that is, you have applied no transformations to it.

The pDevice->SetTransform(D3DTS_VIEW...) is responsible for setting the view matrix. This defines how you view the world through your ''camera''. The matrix you have specified contains a translation which ''moves'' your ''camera'' 10.0 units along the z-axis.

Hope this helps - it is probably worth spending a little time looking through a math book and getting familiar with matrices and how they are used in 3D graphics.

Regards,
Sharky

This topic is closed to new replies.

Advertisement