I don’t know I’m allowed to post two topic in the same time… if I’m not, I’m very sorry :s !
I am a new problem, lol!
I try to make a game with tanks. It’s a 2D game, and I use a upper view (I don’t know if I use the good words, I’m sorry) I have done a target so as to aim at ennemy but the tank’s cannon must be rotated toward the target.
I have used my Pythagore and “trigonometrie” knowledge in order to get the angle created by the horizontal axe and the axe formed by the position point of tank and position point of cursor, as is shown on the following page:
http://www.developpez.net/forums/showthread.php?t=95419
But, my rotated Objet disapears when the angle is close to 45° … I don’t understand why… ???
Here is the part of my code:
int adj = cible_X-tank_X;
int opp = cible_Y-tank_Y;
double hyp = (adj^2+opp^2)^(1/2);
double cosi_a = Math.abs(adj/hyp);
double angl = Math.acos(cosi_a);
double pi = Math.PI;
double angle = 0;
if (adj<0 && opp<0){angle= angl + pi;}
if (adj>0 && opp<0){angle= -angl;}
if (adj<0 && opp>0){angle= -(angl + pi);}
if (adj>=0 && opp>=0){angle= angl;}
c.setColor(new Color(100,60,80));
c.rotate(angle,tank_X,tank_Y);
c.drawRect(tank_X-40,tank_Y-30,80,60);
:’( please!! help me!
PS: oups, I would want to say “thanks to the cursor!”: “grâce à la souris” in french.