Jump to content

  • Log In with Google      Sign In   
  • Create Account

Setting up Direct3D Camera for 2D game


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1   Members   -  Reputation: 105

Like
0Likes
Like

Posted 05 February 2014 - 07:01 PM

My first post here, i was going to search the forums for similar topics but I could not find the search tool for the forums.

 

so here is my camera setup:

        HRESULT result;
	result = Direct3D_Object->CreateDevice(GameSettings.GraphicAdapter, GameSettings.DeviceType, 
                                               GameSettings.WindowHandle, GameSettings.HardwareAccelaration,
                                               &D3DPParameters, &D3D_Device);

	if (result == D3D_OK)
	{
		D3DXMATRIX V;
		D3DXVECTOR3 pos(0.0f, 0.0f, -400.0f);
		D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
		D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
		D3DXMatrixLookAtLH(&V, &pos, &target, &up);
		D3D_Device->SetTransform(D3DTS_VIEW, &V);

		D3DXMATRIX P;
		float width = 800;
		float height = 600;
		D3DXMatrixPerspectiveFovLH(&P, D3DX_PI*0.5f,
		width/height, -400.0f, 0.0f);
		D3D_Device->SetTransform(D3DTS_PROJECTION, &P);

so I used D3DX_PI*0.5f for the angel so that I can easly set the camera distance away from the origin (0, 0, 0), just by setting the z for the camera = - half the screen width...

 

6LuMk.png

 

this way my camera wont show anything that is behind the z = 0!!

 

 

and here the code to draw the spirit:

LPD3DXSPRITE SpriteTest;
LPDIRECT3DTEXTURE9 TestTexture;
LPCTSTR ImageName = L"test.jpg";

D3DXMATRIX TestMat;
D3DXVECTOR2 ScaleVector;
D3DXVECTOR3 PositionVector;

PositionVector.x = 0;
PositionVector.y = 0;
PositionVector.z = 0;

ScaleVector.x = (float) 400/566;
ScaleVector.y = (float) 400/566;

D3DXCreateTextureFromFileEx(D3D_Device, ImageName, 566, 800, D3DX_DEFAULT, 0, 
                            GameSettings.BackBufferFormat, D3DPOOL_MANAGED, 
                            D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &TestTexture);

D3DXMatrixTransformation2D(&TestMat, NULL, NULL, &ScaleVector, NULL, NULL, NULL);

SpriteTest->SetTransform(&TestMat);
SpriteTest->Draw(TestTexture, NULL, NULL, &PositionVector, D3DCOLOR_XRGB(255, 255, 255));

however this comes up when I run the game?

 

 

 

6LtsR.jpg

 

please if you need any more information let me know

 

thank you for your time.

 

Also if anyone can tell me how to search the forums that also would help.

 

Edit: I forgot to mention client dimentions are 800*600 I confirmed them using GetClientRect

thanx again for you help.

 

Edit: Iam using Directx9 (Directx SDK June 2010)

 

Edit: test.jpg size is 566 x 800 pixel


Edited by CppVoidppC, 06 February 2014 - 07:11 AM.


#2   Members   -  Reputation: 330

Like
3Likes
Like

Posted 06 February 2014 - 12:00 PM

For 2D game you should use 

D3DXMatrixOrthoLH(&matOrtho,640, 480, -1000, 1000);

You dont have to worry about camera or things... Any thing u draw will be exactly its size !

 

because it's more simple. 


Edited by greenpig83, 06 February 2014 - 12:02 PM.


#3   Members   -  Reputation: 105

Like
0Likes
Like

Posted 06 February 2014 - 01:13 PM

thank you... really... thanx for taking the time to answer my question.

hat off for you.cool.png

 

is there anything i should do to mark your answer as the perfect answer or the one that i accept as the solution to my problem other than the one up thing?

wish you good luck....

 

For 2D game you should use 

D3DXMatrixOrthoLH(&matOrtho,640, 480, -1000, 1000);

You dont have to worry about camera or things... Any thing u draw will be exactly its size !

 

because it's more simple. 






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.




PARTNERS