Tuesday, June 13, 2006

Back to Cyber Jaya & 3D Graphic Fundamentals II

CyberJaya Once again

It's not bad thing or what, but somehow, I back to CyberJaya. There a lot of people questioning me, why are you going back to cyber one week before the school start? errr, no reason, just want to get back here. Felt something i need to settle (such as...returning my overdue library book), something to discuss (such as...Hatchlings games new game design.), someone to meet and hang our with (such as... Someone lah). So...is that no reason? okok...nonsense I knew.

I had some crazy, plain and tiring days at Setapak, Wangsa Maju is a better word now, since they moved the base to Wangsa Maju section 2. Anyway, i enjoyed it, and i guess its time for me back to cyber to start preparing myself for a new sems. Don't get me wrong, i'm not that hardworking, preparing not in the sense of study or what. Just need to clean my room, arrange the mess, make up a plan for a new sems (in Game Dev sake :P).

3D graphic pipeline II

First of all, actually I didnt finish discusing about the 3D graphic thing at previous post. It's too long to continue and too tired for me to continue typing that night, .... ya, I was lazy. hehe. (OMG its so late! i still day dreaming)

Second part I going to share the World Matrix, View Matrix and Projection Matrix which is essential in displaying something 3D on our screen. Thanks to mathematic we able to do all these very complex and mathematic heavy concept transformation in just applying the knowledge of matrix. And thanks to Direct X SDK provided us a very simple way to apply those matrix. Without them, i think 3D is a over tough subject which kill everyone off and I don't think we playing World of Warcraft now...

World Matrix. World Matrix hold the information of final transformation of that particular mesh in the 3D world. Every Mesh is start in the middle of the world aka. (0,0,0) and every vertex of it will reside following its origin (so called local coordinate). In other words, every meshed in direct x is naturally place at the center of world, until they multiply their world matrix (which mean apply all the rotation, scale and translation which represent in the world matrix) and appear at that position after all. So, world matrix is a matrix which define the final destination of one mesh and all those information will pass to next step, all apply another matrix, view matrix.

View Matrix. View matrix, also can refer as the Camera in our 3D world. View matrix will contain the position of the camera, right vector, up vector and Look at vector of the camera which representing where are our screen is actually watching at in the 3D world. I easily use a function

D3DXMatrixLookAtLH( D3DXMATRIX* pOut, CONST D3DXVECTOR3* pEye,
CONST D3DXVECTOR3* pAt, CONST D3DXVECTOR3* pUp);

This function help us easy define all necessary vector and apply to the camera (view Matrix). After set this up, we just simply multipy the transformed world matrix with view matrix and virtually we now have all the meshes display as the way we looking at in the 3D world throught the camera position. After all, we left last matrix to multiply at, the projection matrix.

Projection Matrix is abit complex, i hope i can explain it well. How are the graphic actually turning the 3D world into our 2D screen? Don't forget that our screen is just a flat thing to displaying thing. Here where the projection matrix do it's works. Projection will convert every vertex in the view matrix into a range of -1 to 1 (in 4 way, up, down, left and right, all in range -1 to 1). Projection Matrix is the matrix which filter out the vertex which actually not visible to the screen and determine which matrix is actually staying in the final rendering.

After turning everything in range to -1 - 1. We need to times the computed range with the Screen acutual pixel (800x600? or 1024x768) to get where actually the vertex reside on the screen. After all, we will time the vector (position) of the vertex with the final matrix can get the final rendering vector, lastly will call the rendering function of direct x, this is beyond this, and me now.

Abit bored and confusing? sorry, i don't think i am a good teacher then :P Actually I'm not 100% sure i knew this concept, still far away. I think I need some practice indeed. I did a software rendering program which actually displaying 2 rotating cube using software drawing but applied all the thing i share. I just refering to the work provided, understand and try to memorize the code and type them out myself. not a proud this to share :P Wait till i code one full 3D program and i will share, hope that happen soon. Okay...i think thats all...tiring...

Today Feeling +=+ I dreamed that i have a son...is that a nightmare??