Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Projections in D3D8

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

I am just learning Direct3D 8 right now and having some trouble.. I know that there is model space (coordinate system of your models and objects), world space (coordinate system of the entire world where other objects are in the scene), and then there''s the projection (which maps your 3D world coordinates to 2D viewport space). OK, what I have is two different objects (2 squares of a checkerboard, red and black, in model space). I defined their vertices as (0,0,0), (1,0,0), (0,1,0) and (1,1,0). These are the coords in their model space. Now I set up the world coords in a double for loop such as...
	for ( int y = 0; y < NUM_ROWS; ++y )
		for ( int x = 0; x < NUM_ROWS; ++x )
			int oddeven = ( x + y ) & 1;

			// Set up world matrix

			D3DXMatrixTranslation( &m_matWorld, ( float ) x, ( float ) y, 0.0 );

			// Set up world transformation

			m_d3dDevice->SetTransform( D3DTS_WORLD, &m_matWorld );

			// Draw the square

			m_d3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, m_vertices[ oddeven ], sizeof( CustomVertex ) );
So world space goes from 0 ... to NUM_ROWS in x, y and z (I guess??) I set up a projection matrix (from pazarra''s book btw) as ...
	// Set up projection matrix

	D3DXMatrixIdentity( &m_matProj );
	m_matProj._11 = .1875;	
	m_matProj._41 =	-0.75;	
	m_matProj._22 =	-0.25;	
	m_matProj._42 =	1.0;	
	// Set the projection matrix

	m_d3dDevice->SetTransform( D3DTS_PROJECTION, &m_matProj );
Can someone explain to me why Pazerra set up his projection matrix like that? I''m totally confused about the projection matrix.......thanks!

Share this post

Link to post
Share on other sites
Use D3DXMatrixPerspectiveFovLH() instead. If you use identity for model, world and camera matrices then you fold all three spaces into one space. Projection matrix xforms 3d homogenous coordinates into 3d clip space -1 <= x <= 1, -1 <= y <= 1 and 0 <= z <= 1, i.e. a 3d box. If you use 0 for w-coordinate then your 3d point will be put on one of the 3d clip cube's face or clip plane, since when your 4d point gets divided by the 4th component or w it yields a one for z. ie. (0, 0, 3, 0) multiplied by projection matrix will yield (0, 0, 3, 3) then d3d will divide all vector components by w or 3 in this example so that z will become 1. After projection xform the coordinates will get multiplied by viewport matrix that will place them into screen space. Remember that in the end you're moving the world geometry that exists in one 3d space only. You set the world and view matrices for sole reason of moving all world geometry thus giving illusion that your camera moves thru the world. If you're using camera paradigm then think of xforming the world geometry in the opposite direction that you would want it to move and you'll get the camera paradigm right. You can also forget about the camera and think of xforming the geometry from center of one coordinate system. It's better to think in terms of camera and vectors rather than cos/sin calculations. It's easier to manipulate world this way. Like for example xforming one coodinate into another rather than thinking of moving the geometry from one orientation to another. Using vectors you can build xform matrices easily and not have to deal with sin/cos. Just use new world orthogonal axes as vectors and put them into matrix then xform your world geometry points by this matrix to move them. This also works for creating a moving camera system. My geometry lives in world space and when I want to move it I pass points thru xform matrix then set the view matrix to put them into eye or camera space. This space is one where camera points down the +z axis, ie. world geometry xforms into this space, then it gets xformed by projection matrix into 3d clip space and then into screen space. Hopefully I didn't confused you. So, in closing you're just moving points around at low level though having a camera/vector paradigm at higher level makes the scene easier to visualize and manipulate.

Edit: there is no model matrix, just world, view, projection and viewport. In Opengl there isn't a world matrix just view, projection and viewport. You setup view matrix to xform points into view space. You can also use LookAt() function to setup your camera.

[edited by - JD on December 1, 2002 5:42:57 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!