Skip to main content
GameDev.net gamedev.net
🔒 Locked

Billboarding problem

Started by Screamer Feb 21, 2009 at 3:25 PM 3 replies 1.1k views
Original Post
Screamer
Screamer
I'm having trouble getting my billboarding to work properly. Right now the billboard isn't facing me. Any help is much appreciated. Thanks, Screamer


void Graphics_Engine::DrawBillboard()
{
	myBird = OBJFACTORY->GetObj(1);
	Model *targetModel = static_cast<Model*>(myBird->Has(Component::MODEL));
	
	//world position and world size
	HR(mSprite->Begin(D3DXSPRITE_OBJECTSPACE | D3DXSPRITE_ALPHABLEND));
	D3DXMATRIX viewTranspose = gCamera->getViewMatrix();
	D3DXMatrixTranspose(&viewTranspose, &viewTranspose);

	viewTranspose._14 = 0.0f;
	viewTranspose._24 = 0.0f;
	viewTranspose._34 = 0.0f;
	

	static bool firstTime;

	if(firstTime == false)
	{
		firstTime = true;
		GFX->AddSprite( "pow.dds", 256, 256, D3DXVECTOR3(0, 0, 0) );
	}

	float fWidth = 256.0f;//spriteCmpnts_[0]->width_;
	float fHeight = 256.0f;//spriteCmpnts_[0]->height_;

	D3DXMATRIX centerTex;
	D3DXMatrixTranslation(&centerTex, -fWidth/2.0f, -fHeight/2.0f, 0.0f);

	D3DXMATRIX rotationMatrix;
	D3DXMatrixRotationZ(&rotationMatrix, 0);

	D3DXMATRIX mat4Pos;
	D3DXMatrixTranslation(&mat4Pos, 0, 0, 0);

	float fSizeX = 5.0f;
	float fSizeY = 5.0f;

	float fScaleX = fSizeX/fWidth;
	float fScaleY = fSizeY/fHeight;

	D3DXMATRIX scale;
	D3DXMatrixIdentity(&scale);
	D3DXMatrixScaling(&scale, fScaleX, -fScaleY, 1.0f);

	D3DXMATRIX final;
	final = centerTex * scale * rotationMatrix * viewTranspose * mat4Pos * gCamera->getViewMatrix() * gCamera->getProjectionMatrix();
	//matrix for rotating texture

	D3DXMATRIX old;
	HR(mSprite->GetTransform(&old));
	HR(mSprite->SetTransform(&final));
	D3DXVECTOR3 vec3Position(0.0f, 0.0f, 0.0f);
	HR(mSprite->Draw(spriteCmpnts_[0]->mTex_, 0, &vec3Position, &vec3Position, D3DCOLOR_XRGB(255,255,255)));
	HR(mSprite->SetTransform(&old));
	HR(mSprite->End());

}


Screamer
Screamer
anyone have an example that works properly?
solenoidz
solenoidz
Try putting D3DXSPRITE_BILLBOARD in the begin method.
Or, you may need to set the world transform of the sprite to iversed matrix of the view matrix.
Screamer
Screamer
well the D3DX_SPRITE_BILLBOARD is for particles and doesn't work for me.
solenoidz
solenoidz
So don't use it, just use object_space and put the right world transform. For example

D3DXMATRIX viewInv = gCamera->getViewMatrix();	D3DXMatrixInverse(&viewInv,NULL ,&viewInv);viewInv._41=viewInv._42 = viewInv._43 = 0; HR(mSprite->SetTransform(&viewInv));HR(mSprite->Draw(....

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.