IonicWind Software

Aurora Compiler => 3D Graphics => Topic started by: J B Wood (Zumwalt) on August 11, 2006, 07:44:56 PM

Title: Targeting issue.
Post by: J B Wood (Zumwalt) on August 11, 2006, 07:44:56 PM
Ok, late at night, brain hurts..
What is the formula for determining target angle?
For instance, I have my distance to object already, I have the source object location and I have the destination object location.
I need to know how to calculate between the source and destination so that I can rotate my gun to face the target.
Sorry but I am VERY crappy at math, so having a bugger of a time writing this formula.

Please point me to some references if you don't want to tell me how to solve this seemingly simply equation.
Thanks
Title: Re: Targeting issue.
Post by: J B Wood (Zumwalt) on August 11, 2006, 07:49:47 PM
*note this is part of my growing V3 class to show you I am trying :(*



V3 :: pointat(C3Dobject obj1, C3Dobject obj2), float
{
VECTOR3 m1,m2,r1;
VECTOR2 v1,v2;
m1 = obj1.getposition(0); // get the position of the tank
m2 = obj2.getposition(0); // get the postion of the target

v1.x = m1.x;
v1.y = m1.z;
v2.x = m2.x;
v2.y = m2.z;

float result;
result = VecToDgrs(v1,v2);
return result;
}


V3 :: VecToDgrs(VECTOR2 obj1, VECTOR2 obj2),float
{
//obj1 = home
//obj2 = target

float result;
pi=3.14159265;
if obj1.x<obj2.x AND obj1.y<obj2.y {Result = 180-(180*atan(abs(obj1.x/obj1.y))/pi);}
else if obj1.x<obj2.x AND obj1.y>obj2.y {Result = 180*atan(abs(obj1.x/obj1.y))/pi;}
else if obj1.x>obj2.x AND obj1.y<obj2.y {Result = 180+(180*atan(abs(obj1.x/obj1.y))/pi);}
else if obj1.x>obj2.x AND obj1.y>obj2.y {Result = 360-(180*atan(abs(obj1.x/obj1.y))/pi);}
return result;
}
Title: Re: Targeting issue.
Post by: kryton9 on August 11, 2006, 08:08:11 PM
I have that in my subs for vec to degrees and also got one for the target
http://www.ionicwind.com/forums/index.php?topic=805.0

the second example  has it
Title: Re: Targeting issue.
Post by: kryton9 on August 11, 2006, 08:58:18 PM
Should also mention, I think in the mech demo, you would send it the x and z positions instead of the x and y as I did in my example.
It is just whatever axis coordinates are for the plane being used.

The first x and z would be the guns location and the second is the x and z of the target. In my example x and y and tx and ty. Hope that helps.
Title: Re: Targeting issue.
Post by: J B Wood (Zumwalt) on August 12, 2006, 08:38:22 AM
Same problem with that as I had the other way I was doing it.
Updating and uploading for you to check out the code and issue (I have remarked out the border to speed it up)
Title: Re: Targeting issue.
Post by: kryton9 on August 12, 2006, 11:33:45 AM
Great will try it out in a bit.