Jump to content


Photo

Finding X, Y Coordinates Of The Same Object


  • Please log in to reply
1 reply to this topic

#1 Revixter27

Revixter27

    GMC Member

  • GMC Member
  • 23 posts

Posted 07 March 2009 - 02:00 PM

I am creating a topdown action-RPG. The player is located in the bottom middle of the screen. When the player turns left/right the entire view angle changes so he always stays in the same spot on the screen.

Here's what the code looks like in the step event of the player:
//centering the player
view_xview = (x + 220 * cos(degtorad(direction))) - 400;
view_yview = (y - 220 * sin(degtorad(direction))) - 300;

//view angle
view_angle = -direction + 90;


Now, I have implemented a HUD (health bar, attack meters, etc) which both looks and performs great on its own view plane.
// Draw HUD
d3d_set_projection_ortho(0,0,view_wview,view_hview,0);
d3d_set_projection_ortho( view_xview,view_yview,view_wview,view_hview,view_a
ngle);


Now if I have any object in the game world and I want to know its x and y position as it correlates to the HUD's view, how would I figure this out?

For example, you see a goblin. This goblin has both an x and y position inside the gameworld. By hovering the mouse over the goblin a text box appears giving you details about him (health, stats, etc). This text box should be inside the view of the HUD and appear over the goblin on screen. Let's say the goblin's x, y values are 1500, 600 respectively. Due to the rotating view (based on the player location and angle), the goblins location on the HUD view might be 200, 400. How would I pinpoint this 200, 400 location?

Currently, I use the draw_text_transformed function to draw the information in the game world view (NOT the HUD view) then rotate it to the player's direction. This makes the text sometimes fuzzy or "shake" a little bit, and not to mention it disallows me use of the some the draw_rect functions I intend to use as a textbox border. However, it does "work".

I tried to explain this the best I can, If you need code or an executable example let me know, I'd be happy to provide.

Thanks in advance, guys!

Edited by Revixter27, 07 March 2009 - 02:06 PM.

  • 0

#2 ditdingiscool

ditdingiscool

    GMC Member

  • New Member
  • 335 posts

Posted 07 March 2009 - 05:06 PM

I am creating a topdown action-RPG. The player is located in the bottom middle of the screen. When the player turns left/right the entire view angle changes so he always stays in the same spot on the screen.

Here's what the code looks like in the step event of the player:

//centering the player
view_xview = (x + 220 * cos(degtorad(direction))) - 400;
view_yview = (y - 220 * sin(degtorad(direction))) - 300;

//view angle
view_angle = -direction + 90;


Now, I have implemented a HUD (health bar, attack meters, etc) which both looks and performs great on its own view plane.
// Draw HUD
d3d_set_projection_ortho(0,0,view_wview,view_hview,0);
d3d_set_projection_ortho( view_xview,view_yview,view_wview,view_hview,view_a
ngle);


Now if I have any object in the game world and I want to know its x and y position as it correlates to the HUD's view, how would I figure this out?

For example, you see a goblin. This goblin has both an x and y position inside the gameworld. By hovering the mouse over the goblin a text box appears giving you details about him (health, stats, etc). This text box should be inside the view of the HUD and appear over the goblin on screen. Let's say the goblin's x, y values are 1500, 600 respectively. Due to the rotating view (based on the player location and angle), the goblins location on the HUD view might be 200, 400. How would I pinpoint this 200, 400 location?

Currently, I use the draw_text_transformed function to draw the information in the game world view (NOT the HUD view) then rotate it to the player's direction. This makes the text sometimes fuzzy or "shake" a little bit, and not to mention it disallows me use of the some the draw_rect functions I intend to use as a textbox border. However, it does "work".

I tried to explain this the best I can, If you need code or an executable example let me know, I'd be happy to provide.

Thanks in advance, guys!


first you need the relative co-ordinates(relative to the player) like so:
rx=goblin.x-player.x
ry=goblin.y-player.y

then get the co-ordinates in a Cartesian coordinate system:
s=point_distance(0,0,rx,ry)
r=point_direction(0,0,rx,ry)

then we need to add/subtract from the direction(not sure which :mellow: )
r+=view_angle[0]

and put it back to normal coordinates:
rx=lengthdir_x(s,r)
ry=lengthdir_y(s,r)

now rx and ry contain the co-ordinates
NOTE:these coordinates are RELATIVE to the players in-view co-ordinates, so if the player is in the middle off the view you should do this:

rx+=view_wview[0]/2
ry+=view_hview[0]/2

i hope this helped...

oh shoot, if you want to use the dirty method(aka your method ;) )
you should set the interpolation to false(interpolate between pixels in the game settings)
this should stop the fuzziness
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users