Pointing arrow

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
SanderVocke
Posts: 40
Joined: Mon Oct 31, 2005 1:19 pm
Location: Netherlands

Pointing arrow

Post 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.
"The shortest distance between two points is always under construction."
- Noelie Alite
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post 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
SanderVocke
Posts: 40
Joined: Mon Oct 31, 2005 1:19 pm
Location: Netherlands

Post 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?
"The shortest distance between two points is always under construction."
- Noelie Alite
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post 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 :)
SanderVocke
Posts: 40
Joined: Mon Oct 31, 2005 1:19 pm
Location: Netherlands

Post by SanderVocke »

Thx! ill try to implement it let you know if it works.
"The shortest distance between two points is always under construction."
- Noelie Alite
Dirtbiker
Posts: 29
Joined: Wed Aug 31, 2005 7:02 am
Location: U.S.
Contact:

Post 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.
Post Reply