Bilboard not rotating properly

This topic is 4957 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm trying to add billboards to my little project and since I always have trouble getting my head around 3D transformations it's not working... Screenshot of the problem: The coordinat system is DirectX's lefthanded with X right, Y up, Z into screen. As can be seen the billboard is facing the wrong way. This is only happening with the rotation around the y axis, rotation around the x axis works as it should. I use the following code to set the billboard up:
Matrix& Matrix::makeRotationMatrix( const Vector3& forward, const Vector3& up ) {
Vector3 axis_z( forward );
axis_z.normalize();

Vector3 axis_x( CrossProduct( up, axis_z ) );
axis_x.normalize();

Vector3 axis_y( CrossProduct( axis_z, axis_x ) );
axis_y.normalize();

makeZeroMatrix();

_11 = axis_x.X_; _12 = axis_y.X_; _13 = axis_z.X_;
_21 = axis_x.Y_; _22 = axis_y.Y_; _23 = axis_z.Y_;
_31 = axis_x.Z_; _32 = axis_y.Z_; _33 = axis_z.Z_;

_44 = 1.0f;

return *this;
}

void Billboard::draw( const Vector3* position, const Vector3* heading, const Vector3* up ) {
Vector3 n;
Vector3 u;
Matrix  m;

n = g_ActiveCamera->getPosition() - *position;

m.makeRotationMatrix( n, *up );

m._41 = position->X_;
m._42 = position->Y_;
m._43 = position->Z_;

Billboard_->draw( 2, 2, m.M_ );
}

void Billboard::draw( float width, float height, const float* world ) {
D3DXMATRIX world_matrix( world );

width  *= 0.5f;
height *= 0.5f;

D3DXVECTOR3 v1(  width,  height, 1.0f );
D3DXVECTOR3 v2( -width,  height, 1.0f );
D3DXVECTOR3 v3( -width, -height, 1.0f );
D3DXVECTOR3 v4(  width, -height, 1.0f );

D3DXVec3TransformCoord( &v1, &v1, &world_matrix );
D3DXVec3TransformCoord( &v2, &v2, &world_matrix );
D3DXVec3TransformCoord( &v3, &v3, &world_matrix );
D3DXVec3TransformCoord( &v4, &v4, &world_matrix );
}


I'm simply creating a rotation matrix from a vector from the billboard center to the camera and an up vector, and then translate the billboard to its world position. Can anyone shed any light on why the billboards aren't facing the right way?

Share on other sites
Not sure what's going on in your code, but I'll suggest you look at this for a more compact version.

Share on other sites
Thanks for the link, but as far as I can see that code gives a view-plane alligned billboard, but I'm looking for a view-point alligned. Take a look at figur 5 in this article for the difference.

Share on other sites
Aha ok, didn't notice that you wanted viewpoint oriented billboards. Could it be that you just need to reverse the heading direction? (essentially creating a right handed rotation). Just a wild guess :)

Share on other sites
Hmm, tried reversing the heading. This caused the billboard to move (which it shouldn't). Maybe the transformations are being applied in the wrong order (translating, then rotating, instead of rotating, then translating). Anyway, I'm to tired to think about it now, I'll look at it tomorow.

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• Forum Statistics

• Total Topics
634047
• Total Posts
3015231
×