Archived

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

AngelForce

Setting Matrices in a 2d-Engine

Recommended Posts

How should I set the world, projection and view matrix(dx8) when creating a 2d engine? At the moment I''m doing it like this:
  
        D3DXMATRIX mat;
	//Projection Matrix

	D3DXMatrixOrthoLH(&mat,
		m_ScreenWidth,
		m_ScreenHeight,
		0.0f,
		100.0f);
	m_lpD3DDevice->SetTransform(D3DTS_PROJECTION, &mat);

	//World Matrix

	D3DXMatrixIdentity(&mat);
	m_lpD3DDevice->SetTransform(D3DTS_WORLD, &mat);

	//View Matrix

	D3DXMatrixLookAtLH(&m_mat,
		&D3DXVECTOR3(0.0f, 0.0f, 0.0f),
		&D3DXVECTOR3(0.0f, 0.0f, 0.0f),
		&D3DXVECTOR3(0.0f, 1.0f, 0.0f));

	m_lpD3DDevice->SetTransform(D3DTS_VIEW, &mat);
  
I searched quite some time, but didn''t find any good tutorials on how to build a more advanced sprite engine(Only a lot of tuts on how to draw a triangle, spin it, texture it,... ) As I have it now it works fine for displaying sprites, however, I don''t seem to be able to scale them. Now I''m not sure, if it''s because of the matrices, but this is code I''m not fully sure about. What I want to do: -scale sprites -I only want/need to move the camera in x,y direction. -other fancy _3D_ things like particle systems I hope someone is able to help me. AngelForce -- If you find any mistakes, you''re allowed to keep ''em! ''When I look back I am lost.''

Share this post


Link to post
Share on other sites
From your writings, I take it that you try to code an engine for a 2d RPG (snes ff style), or a strategy (c&c or dune2 style).

In any case, I''m on this project as well, so I think I can help; first of all, check my other current post "...3 DirectX related questions", where I have put a piece of my own code, which DOES use sprites (scaled as well) AND particles.

A few general guidelines: you have done well using the orthogonal (orthocanonic in greek) projection matrix, since it does not scale the polygons based on their distance from the camera (a.k.a. it only takes x and y coords in consideration, which is exactly what we want :D ); just be sure to set the world and view matrices correctly, or you''ll see nothing. Nada. Niet. Zip. One more thing: as for scaling sprites, if you use the D3DXSprite interface, just use the scale parameters already implemented, if you use custom-made polygons (quads etc.), set the world matrix appropriately!

That''s that, I guess. Any questions? I''m not an eexpert myself, but I guess we must all help each other, or else we''ll just keep bumping on the same issues and rediscovering the wheel all the way from the start .

Hope this helped.
Flare

-----------<<>>-----------
Ga1adaN, Primus ante Adein
flareman@freemail.gr
-----------<<>>------------

Share this post


Link to post
Share on other sites