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.
Pointing arrow
-
- Posts: 40
- Joined: Mon Oct 31, 2005 1:19 pm
- Location: Netherlands
Pointing arrow
"The shortest distance between two points is always under construction."
- Noelie Alite
- Noelie Alite
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
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
-
- Posts: 40
- Joined: Mon Oct 31, 2005 1:19 pm
- Location: Netherlands
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
- Noelie Alite
semi pseudocode of how i'd do 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
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
-
- Posts: 40
- Joined: Mon Oct 31, 2005 1:19 pm
- Location: Netherlands
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.
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.