Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


[C++] Name above other players


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 roby65   Members   -  Reputation: 154

Like
0Likes
Like

Posted 29 August 2012 - 06:34 AM

Hi Guys,

i have a multiplayer game where i need to draw player names above their heads.
I have Camera position/rotation and player position, and i need to calculate where to draw the 2d player name on the string.
Can someone suggest me what's the best way to do it?

Roby

Sponsor:

#2 kauna   Crossbones+   -  Reputation: 2861

Like
0Likes
Like

Posted 29 August 2012 - 06:40 AM

Hi,

If you know the world position of the player head, you may use your view-projection matrix to transform the position to the screen space.

Cheers!

#3 SiCrane   Moderators   -  Reputation: 9675

Like
0Likes
Like

Posted 29 August 2012 - 06:51 AM

Alternately, place a billboarded quad above each player in world space.

#4 Lightness1024   Members   -  Reputation: 739

Like
0Likes
Like

Posted 29 August 2012 - 07:19 AM

yes, why not with a little upscaling according to linear Z.

otherwise the position of the point in 2D is:
(you can use glm library)

vec4 proj = mul(vec4(vec3(worldPosition), 1), viewProjectionMatrix);
proj *= (1. / 2 * proj.w);
proj += vec4(0.5, 0.5, 0, 0);
vec2 screenPos = vec2(proj) * resolution; // resolution is a vec2.

#5 CC Ricers   Members   -  Reputation: 821

Like
0Likes
Like

Posted 29 August 2012 - 08:25 AM

This might be a cool reason to put an additional bone above the head of the players' character models. Extra bones that aren't used for deformation provide an easy marker in which to locate where to render other stuff like this.
My development blog: Electronic Meteor

#6 roby65   Members   -  Reputation: 154

Like
0Likes
Like

Posted 29 August 2012 - 02:06 PM

yes, why not with a little upscaling according to linear Z.

otherwise the position of the point in 2D is:
(you can use glm library)

vec4 proj = mul(vec4(vec3(worldPosition), 1), viewProjectionMatrix);
proj *= (1. / 2 * proj.w);
proj += vec4(0.5, 0.5, 0, 0);
vec2 screenPos = vec2(proj) * resolution; // resolution is a vec2.


I liked your code, but it's not working, maybe i made something wrong?

D3DXVECTOR3 worldPosition(100,100,500);
  D3DMATRIX viewProjectionMatrix=lastProjection;
  D3DXVECTOR4 proj;
  D3DXVec4Transform(&proj,&D3DXVECTOR4(worldPosition,1),&(D3DXMATRIX(viewProjectionMatrix)));
  proj *= (1. / 2 * proj.w);
  proj += D3DXVECTOR4(0.5, 0.5, 0, 0);
  D3DXVECTOR2 screenPos = D3DXVECTOR2(proj.x,proj.y) * 1680 * 1050;


#7 kauna   Crossbones+   -  Reputation: 2861

Like
0Likes
Like

Posted 29 August 2012 - 06:30 PM

D3DXVECTOR2 screenPos = D3DXVECTOR2(proj.x,proj.y) * 1680 * 1050;


Maybe you meant this : D3DXVECTOR2 screenPos = D3DXVECTOR2(proj.x* 1680,proj.y* 1050) ;

Cheers!

#8 Jason Z   Crossbones+   -  Reputation: 5412

Like
1Likes
Like

Posted 30 August 2012 - 07:24 AM

The general idea should just be to take the player position, add an offset to it to generate the location in object space that you want the text to appear (i.e. add vec3(0,1.5,0) or whatever size is necessary). Then project that point using your model/view/projection matrices, giving a clip space position. Next you normalize by dividing the vector by its w value, and scale the position according to the resolution of the display - which gives the final pixel location that you want to put your text on to.

I'm pretty sure the sample code above does this already, but I just wanted to provide a textual description of the process...




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS