Page 1 of 1

Pointing arrow

Posted: Thu Nov 03, 2005 3:43 pm
by SanderVocke
In many space games, the player has a bunch of enemies to defeat, and when the enemies are not in sight, a little arrow pops up at the edge of the screen to show the player where to turn in order to find the enemy. I want to implement this as well, but i have a few problems:

-how should i find the correct 2d position of the screen where to put the arrow? (the arrow should be at the edge closest to the enemy)
-how do i rotate a 2d image around its center? (for making the arrow point)

Thanks alot.

Posted: Thu Nov 03, 2005 5:19 pm
by bitplane
I replied to this once already, but it didn't seem to save it. strange

the answer is use getScreenCoordinatesFrom3DPosition. I'd guess that if it's off the visible area, draw an arrow rather than a target.

to rotate a 2d image, you'll need to put it on a pair of triangles like so-
http://www.irrforge.org/index.php/Playi ... h_Irrlicht

Posted: Fri Nov 04, 2005 7:54 am
by SanderVocke
Thanks. There is one more problem i have to solve tho: once i have the 2d position of the target (which is not in my FOV), the arrow needs to be on the edge of the screen closest to the target (if the target was above and a bit to the right in 2d coordinates, the arrow would be at the top edge of the screen, a bit to the right). How would i tackle that problem?

Posted: Fri Nov 04, 2005 10:42 pm
by bitplane
semi pseudocode of how i'd do it-

Code: Select all

// remember if we were an arrow or a target last time
bool was_last_offscreen = offscreen;

offscreen = false;

// for right edge-
if (target2d.X > screenwidth - (arrowwidth/2)) 
{
  arrowpos2d.X = screenwidth - (arrowwidth/2);
  offscreen = true;
}
// (do the same for left, up and down)

// only change the texture when it changes
if (offscreen != was_last_offscreen)
{
  // change the texture, either arrow or target
}

if (offscreen)
{
  f32 angle = (arrowpos2d - target2d).getAngle();
  // rotate the arrow
}
// set the position of the arrow/target and draw it
btw i havent tried this so please let us know if it works, or even better post your working code as a scene node :)

Posted: Sat Nov 05, 2005 11:21 pm
by SanderVocke
Thx! ill try to implement it let you know if it works.

Posted: Sun Aug 06, 2006 1:51 am
by Dirtbiker
I'm creating the same system.
I know when the player is offscreen. I need to know the local Angle of the 2D Screen space between the Camera and Target vectors.
I'm sure I need a mathematical formulea.
I don't know how to use normalization, cross products, or dotproduct very well. I can't imagine what I should do.