[SOLVED] Matrix.CreateBillboard inquiry


I have some problem on my particles using Matrix.CreateBillboard on “some angle” it’s not facing the camera, I don’t know if my input on parameters are correct.

Matrix.CreateBillboard( ref m_Position, ref m_Camera.__Position, ref m_Camera.__UpVector, m_Camera._Word._Forward, out m_MatToFace );

Correct Image on most angle :

Not facing image on some angle :

Should I change Camera.Up vector and Camera.Forward on different angle ? any Idea how to fix some not facing billboard ?

Thanks ^ _ ^ y

Hi !
The matrix creation seems ok to me if the billboards are intended to be spherical. (Camera.Up instead of Vector.Up as it is right now)
Can you show how you calculate the positions of the vertices ? Maybe it’s where the problem lies.

What is “m_Camera.Word.” ? Is this the Camera’s World matrix ?

Hello! here’s how my implementation on each particle final World matrix

public static void UpdateQuadVertexPos

  D3D.Core VertexPNT[] pVerticesPNT, 

  ref Vector3      pPos, 
  float            pHalfSize, 
  float            pScale 


        float m_Half = pScale > 0.0f ? (pHalfSize * pScale) : pHalfSize;

        //TOP LEFT
        pVerticesPNT[0].Position.X = pPos.X + m_Half;
        pVerticesPNT[0].Position.Y = pPos.Y + m_Half;
        pVerticesPNT[0].Position.Z = pPos.Z;

        //TOP RIGHT
        pVerticesPNT[1].Position.X = pPos.X - m_Half;
        pVerticesPNT[1].Position.Y = pPos.Y + m_Half;
        pVerticesPNT[1].Position.Z = pPos.Z;

        //BOTTOM LEFT
        pVerticesPNT[2].Position.X = pPos.X + m_Half;
        pVerticesPNT[2].Position.Y = pPos.Y - m_Half;
        pVerticesPNT[2].Position.Z = pPos.Z;

        //BOTTOM RIGHT
        pVerticesPNT[3].Position.X = pPos.X - m_Half;
        pVerticesPNT[3].Position.Y = pPos.Y - m_Half;
        pVerticesPNT[3].Position.Z = pPos.Z;



    internal void UpdateParticleWorldMatrix( D3D.Particles.Particle p_Particle )

        //--> Translation
        Matrix.CreateTranslation(ref p_Particle._Pos, out m_MatToFace);

        //--> Scale
        Matrix.Multiply(ref m_MatToFace, ref __WScale, out m_MatToWorld);

        //--> Rotation
        Matrix.Multiply(ref m_MatToWorld, ref __WRotation, out m_MatToMul0);

        //--> To Face
        m_QuadTrans = m_MatToMul0.Translation;
        Matrix.CreateBillboard(ref m_QuadTrans, ref m_Camera.__Position, ref m._Camera.__UpVector, m_Camera._World.Forward, out m_MatToFace);

        //--> Final Particle world matrix      
        Matrix.Multiply(ref m_MatToFace, ref __WPosition, out p_Particle.__World  );



Where : p_Particle.__World is each particles final world matrix to be set on basic effect on rendering


I only put m_Camera.World on above code, but I already tried all my camera matrix forward, but still some angle not facing my camera.


Are you sure of the order of your matrices multiplies ?

Matrix.Multiply(ref m_MatToWorld, ref __WRotation, out m_MatToMul0);
Should’nt it be
Matrix.Multiply(ref __WRotation, ref m_MatToWorld, out m_MatToMul0);

Usually, world = scalerotationtranslation ?

1 Like

I’ll try to mess with my matrices multiplies and get back on the result, thanks Alkher…

Banging my head against the wall :smile: the problem is not with CreateBillboard and parameters, the artifacts only occurred when I attached the particle to a parent entity, e:g to the ship as shown above.

But your suggestions gave me an idea that somewhere in my final world matrix computation child to parent node matrix computation has the problem.

^ _^ Y It’s cool now! thanks man!

your game looks cool btw, can you share more? (Maybe in a different thread, or the General Showcase Thread General Showcase Thread)

1 Like

Thank you Sir Kosmo ^ _ ^ y … Once semi completed I’ll put a nice Video on that thread ^ _^ y Homeworld and Allegiance game style made in Monogame :wink:

1 Like