Jump to content
  • Advertisement
Sign in to follow this  
Gantz

Small problem with BillBoard flag ID3DXSPRITE

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

Hey guys I recently changed my project and added in some shaders as well as changing a few things in the camera and model class. I had sprites in my scene that used the billboard flag so they were always facing the camera. However since updating the project the sprite will be drawn but the billboard flag seems to be ignored as they no longer follow the camera. Here is the old stuff in the camera class
 

     // Set up the view matrix
    D3DXMATRIXA16 MatScale, MatX, MatY, MatZ, MatTrans;
	D3DXMatrixRotationX( &MatX, -m_Rot.x );
	D3DXMatrixRotationY( &MatY, -m_Rot.y );
	D3DXMatrixRotationZ( &MatZ, -m_Rot.z );
	D3DXMatrixTranslation( &MatTrans, -m_Pos.x, -m_Pos.y, -m_Pos.z);
	m_MatView = MatTrans * MatY * MatX * MatZ;
    g_pd3dDevice->SetTransform( D3DTS_VIEW, &m_MatView );

    // For the projection matrix, we set up a perspective transform (which
    // transforms geometry from 3D view space to 2D viewport space, with
    // a perspective divide making objects smaller in the distance). To build
    // a perpsective transform, we need the field of view (1/4 pi is common),
    // the aspect ratio, and the near and far clipping planes (which define at
    // what distances geometry should be no longer be rendered).

	if(FieldOfView <= 1.1)
	{
		FieldOfView = 1.1;
	} //Cap the field of view so the camera will not cause errors

    D3DXMatrixPerspectiveFovLH( &m_MatProj, D3DX_PI/FieldOfView, 1.33f, m_Near, m_Far );
    g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &m_MatProj );

and here is what I changed it to

     // Set up the view matrix
    D3DXMATRIXA16 MatScale, MatX, MatY, MatZ, MatTrans;
	D3DXMatrixRotationX( &MatX, -m_Rot.x );
	D3DXMatrixRotationY( &MatY, -m_Rot.y );
	D3DXMatrixRotationZ( &MatZ, -m_Rot.z );
	D3DXMatrixTranslation( &MatTrans, -m_Pos.x, -m_Pos.y, -m_Pos.z);
	m_MatView = MatTrans * MatY * MatX * MatZ;

    // For the projection matrix, we set up a perspective transform (which
    // transforms geometry from 3D view space to 2D viewport space, with
    // a perspective divide making objects smaller in the distance). To build
    // a perpsective transform, we need the field of view (1/4 pi is common),
    // the aspect ratio, and the near and far clipping planes (which define at
    // what distances geometry should be no longer be rendered).
    D3DXMatrixPerspectiveFovLH( &m_MatProj, D3DX_PI/4, 1.33f, m_Near, m_Far );

	// Combine the view and projection matrix into a single matrix - this will
	// be passed to vertex shaders (more efficient this way)
	m_MatViewProj = m_MatView * m_MatProj;

and this is how I am rendering my sprites

	g_pd3dDevice->GetTransform(D3DTS_WORLD, &m_WorldMatrix);
	g_pd3dDevice->GetTransform(D3DTS_VIEW, &m_ViewMatrix);

	m_Sprite->SetWorldViewLH(&m_WorldMatrix,&m_ViewMatrix);

	m_Sprite->Begin( D3DXSPRITE_BILLBOARD | D3DXSPRITE_ALPHABLEND | D3DXSPRITE_DONOTMODIFY_RENDERSTATE);

	g_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true);

	D3DXMatrixTranslation(&m_TranslationMatrix, x,y,z);
	
	D3DXMatrixScaling(&m_ScaleMatrix, 0.1, 0.1, 0.0f);
 
	m_Sprite->SetTransform(&(m_TranslationMatrix * m_ScaleMatrix));

	//Draw the sprite
	m_Sprite->Draw(m_Texture,NULL,&m_Center,NULL,0xFFFFFFFF);

	g_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false);

	//End
	m_Sprite->End();

Any help or advice would help, I know that two matrices were combined when I changed the code but I'm not sure where I would use that in conjunction with the sprites. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
I don't see anything obviously wrong with your code, but generally I don't take other people's code and mentally execute it or paste it into a program and run it, simply because I don't have the time to do that for every person that asks a question.

So standard questions apply here, since I see you're not checking any HRESULTs:

- debug runtime installed?
- debug D3DX linked?
- no relevant messages in the debug output?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!