Archived

This topic is now archived and is closed to further replies.

skullfire

Using vectors to tell billboard sprite

Recommended Posts

Well, I am making a system much like Xenogears or Doom, in which you can look at a sprite from different angles, and, depending on it, the sprite texture will change. For instance, If you look at the character, and he''s facing the viewer, the sprite that will be selected wil be the front facing sprite. To do this, i have made some vectors: Camara.m_vPosition = position of cam Camara.m_vView = viewing vector of cam Camara.m_vUp = World Up Vector(0,1,0) Character1.m_vPosition = position of character Character1.m_vView = viewing vector of char So, having this vectors(im not using the world up vector), i want to calculate an angle between the cam''s position relative to the sprite, and the character''s view vector.... i have rad a lot, and all seems to point to using the dot product... but.. its not really workin... can any1 help me? Here''s the main formula source.
        TVector3 vDist1 = Normalize(Camara.m_vPosition - Character1.m_vPosition);
        TVector3 vDist2 = Normalize(Character1.m_vView);// - Character1.m_vPosition);

        vDist1.y = vDist2.y = 0;
        float angle = acos(DotProduct(vDist1,vDist2)*M_PI/180)*180/M_PI;

Share this post


Link to post
Share on other sites
first thing i notice: shouldnt you set y to 0 before you normalize? also acos should only return results between 0-180. and what about that rad/deg back and forth? acos will return rad, you convert that to deg and thats it. why on earth would you want to convert the cos, which has nothing to do with rad or deg?

how is it not working? all i can tell from the code is that you seem to already went through some wild trial and error.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.