3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1]

Author Topic: what does iObjectLocation() really gives you???  (Read 931 times)

« on: April 17, 2012, 05:57:36 AM »
Hello 3DRad community,

I am doing a project (originally using AircrafDemo_autobalance.3dr project)that makes a UAV flies automatically from point A to point B..Where it will:

Take off automatically
Check the locations  of the Target (x1,y1,z1) and the UAV (x2,y2,z2) via iOjectLocation
Code: [Select]
void Position_target ()
{
   iObjectLocation(OBJ_458,Ball);
}   

void Position_plane ()
{
   Vector3 Location_propeller;
   Vector3 Location_elevator;
   Vector3 Location_rudder;
   Vector3 Location_rightaileron;
   Vector3 Location_leftaileron;

   iObjectLocation(OBJ_0,Location_propeller);
   iObjectLocation(OBJ_18,Location_elevator);
   iObjectLocation(OBJ_40,Location_rudder);
   iObjectLocation(OBJ_62,Location_rightaileron);
   iObjectLocation(OBJ_84,Location_leftaileron);

   
   Location.x = (Location_propeller.x + Location_elevator.x + Location_rudder.x + Location_rightaileron.x + Location_leftaileron.x)/5;
   Location.y = (Location_propeller.y + Location_elevator.y + Location_rudder.y + Location_rightaileron.y + Location_leftaileron.y)/5;
   Location.z = (Location_propeller.z + Location_elevator.z + Location_rudder.z + Location_rightaileron.z + Location_leftaileron.z)/5;
}
Get the length of the 2 vectors (from the origin ) using iVectorLength () or float = iFloatSqrt(x*x+y*y+z*z)
Code: [Select]
void length ()
{
   lengthUAV = iFloatSqrt(Location.x*Location.x + Location.y*Location.y + Location.z*Location.z);
   
   //lengthUAV = iVectorLength(Location);
   
   lengthTarget = iFloatSqrt(Ball.x*Ball.x + Ball.y*Ball.y + Ball.z*Ball.z);
   //lengthTarget = iVectorLength(Ball);
}
Get the dot product between them using iVectorDot() or float = x1*x2+y1*y2+z1*z2
Get the theta in cos(theta) where theta = dotproduct/(lengthUAV*lengthTarget)
Code: [Select]
oid dot_product ()
{
   //[UAVx UAVy UAVz].[Targetx Targety Targetz]

   //dotproduct = Location.x*Ball.x + Location.y*Ball.y + Location.z*Ball.z;

  // iVectorLengthSet(nLocation,Location,1);
  // iVectorLengthSet(nBall,Ball,1);
   

   dotproduct = iVectorDot(Location,Ball);

   dot = dotproduct/(lengthUAV*lengthTarget);
   
   arc_cos (dot);

   
}
Get theta via a_cos(theta) by using MathRad.dll
Code: [Select]
float arc_cos (float value)
{
   iDLLArraySet(0,value);
   iDLLCall(MathDLLHandle,"R_acos",0);
   angle = iDLLArrayGet(0);
   return angle;
}

Now the problem is I am getting a very big angle and the UAV is turning accordingly to the other side of the map, beyond the target.
I checked into it and found that the dot product (which is suppose to be from -1 to 1) is very huge no matter what option I choose (iVectorDot or the formula) which led me to this question:

what does iObjectLocation(OBJ_X,Vector3) really gives

PN: thanks to all who helped me in the previous post, also I am new to the 3DRad community, if I posted in the wrong thread, please kindly advice me :)

Regards,
Forat
« Reply #1 on: April 17, 2012, 11:08:54 AM »
what does iObjectLocation(OBJ_X,Vector3) really gives

Uhm, well, it gives you a Vector.
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0

psikoT

« Reply #2 on: April 17, 2012, 11:20:43 AM »
a Vector is a point in the space, represented by coordinates in three axis: X, Y, Z... ::)

I'm a geek! ;D
« Reply #3 on: April 17, 2012, 11:40:54 AM »
a Vector is a point in the space, represented by coordinates in three axis: X, Y, Z... ::)

Yep.
I like to think of a vector like this:

An arrow were the tip is the three coordinates (X, Y and Z) and the start is always zero.

If you use something like 'iObjectLocation()', the tip of the arrow is the 3D location of the object.

This principle explains why you can get the length of a vector and why you can get an orientation out of a vector (iQuaternionLookAt(Quaternion,Vector3,Vector3)).

I'm a geek! ;D

That's okay.  ::)
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0
« Reply #4 on: April 17, 2012, 11:52:01 AM »
ok maybe I should ref-raise the question, I got a problem with calculating the angle between the aeroplane and the Target, I got its location and the location of the Target,I calculated the angle, by getting:

the dotproduct
then getting cos(angle) = dotproduct/(lengthUAV*length*Target);
angle = arc-cos(angle)

and I got the wrong angle, and the wrong dot product which is greater 1, or lower than -1 (it is supposed to be between -1 and 1)
« Reply #5 on: April 17, 2012, 01:27:57 PM »
...I got a problem with calculating the angle between the aeroplane and the Target, I got its location and the location of the Target...

Wait, you can do exactly that with this, right?

Quote
iQuaternionLookAt(Quaternion,Vector3,Vector3)
   Quaternion = resulting quaternion. Return data.
                     It is the rotation required to orientate the Z+ vector
                     D3DXVECTOR3(0.0f,0.0f,1.0f) to the specified direction.
   Vector3 = direction
   Vector3 = up direction. For example Vector3(0,1,0)
   NOTE: this function will not work properly if 'direction' and 'up'
   vectors are parallel.
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0
« Reply #6 on: April 17, 2012, 02:44:45 PM »
this question belongs in the tech forum... not here...

--Mike
Pages: [1]