April 28, 2024, 02:11:34 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Targeting issue.

Started by J B Wood (Zumwalt), August 11, 2006, 07:44:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

J B Wood (Zumwalt)

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

J B Wood (Zumwalt)

*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;
}

kryton9

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

kryton9

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.

J B Wood (Zumwalt)

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)

kryton9

Great will try it out in a bit.