Jump to content
  • Advertisement
Sign in to follow this  
reaper93

Billboarding view orientation

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

I have a small issue with some view orientated billboards, I am using some old code that I dug out from a previous project, most of it seemed to work fine, until I noticed that when I supply a start vertex that is positioned far away from the origin, the rotation is wrong, it basically seems to displace the quad around the origin rather than then actual centre pivot point. Can't put my finger on what is causing it tho SHADER CODE
VS_OUTPUT CloudsVS(VS_INPUT IN)
{
    VS_OUTPUT OUT = (VS_OUTPUT)0;  

    //Transform the quad position
    float3 worldQuadPosition = mul(float4(IN.QuadPos, 1.0f), WorldMatrix);

    //Compute our Billboard matrix
    float3 view = normalize(cameraPosition - worldQuadPosition);
    float3 right = normalize(cross(float3(0.0f, 1.0f, 0.0f), view));
    float3 up = cross(view, right);

    //Construct our look at matrix
    float4x4 lookAt;
    lookAt[0] = float4(right, 0.0f);
    lookAt[1] = float4(up, 0.0f);
    lookAt[2] = float4(view, 0.0f);
    lookAt[3] = float4(worldQuadPosition,1.0f);

    float3 WorldPosition = mul(float4(IN.Position, 1.0f), lookAt);
    OUT.Position = mul( float4(WorldPosition, 1.0f), ViewProjMatrix ); 

    return OUT;
}

C++ Vert setup code, this is fine, like I said above it works for vertex start positions that are close to 0, my guess is the billboard is rotating around its origin rather than its pivot, how do I fix this?
	RAint dataIndex = 0;    
        RAfloat thetaStep = 360.0f/m_numberOfBillboards;

        for(RAint i = 0; i < m_numberOfBillboards; ++i)
        {
            //Generate starting vert
            //X = r cos theta, Y = r sin theta
            CVector3 startVert( m_range * cosf(RA_ATOR * thetaStep * i), 0.0f, m_range * sinf(RA_ATOR * thetaStep * i));
            //startVert = CVector3(1.0f, 0.0f, 1.0f);

            //Calculate the centre position of the quad
            CVector3 centre(startVert.x + (0.5f*m_quadWidth), startVert.y + (m_quadHeight * 0.5f), startVert.z);

            //Bottom left
            m_vertexData[dataIndex].QuadPos = centre;
            m_vertexData[dataIndex].t1 = 0.0f;
            m_vertexData[dataIndex].t2 = 1.0f;
            m_vertexData[dataIndex++].Pos = startVert;

            //Top left
            m_vertexData[dataIndex].QuadPos = centre;
            m_vertexData[dataIndex].t1 = 0.0f;
            m_vertexData[dataIndex].t2 = 0.0f;
            m_vertexData[dataIndex++].Pos = startVert + CVector3(0, m_quadHeight, 0);

            //Top right
            m_vertexData[dataIndex].QuadPos = centre;
            m_vertexData[dataIndex].t1 = 1.0f;
            m_vertexData[dataIndex].t2 = 0.0f;
            m_vertexData[dataIndex++].Pos = startVert + CVector3(m_quadWidth, m_quadHeight, 0);

            //Bottom right
            m_vertexData[dataIndex].QuadPos = centre;
            m_vertexData[dataIndex].t1 = 1.0f;
            m_vertexData[dataIndex].t2 = 1.0f;
            m_vertexData[dataIndex++].Pos = startVert + CVector3(m_quadWidth, 0, 0);
        }

Share this post


Link to post
Share on other sites
Advertisement
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!