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 ... 5 6 [7] 8

Author Topic: RadMath dll  (Read 11729 times)

« Reply #90 on: April 21, 2012, 11:08:12 AM »
4)

how to get the Trigonometric functions Tangent   tan (or tg)

"tan" is: (http://es.wikipedia.org/wiki/Tangente_(trigonometr%C3%ADa) )



of  WorldLocationPL ?

where "a" i think is "z"
and   "b" i think is "y"


(mike: I'm making the algorithm in 2 dimension first)
Using: 3d rad v7.22 | IntelPentM 2Ghz, 1GB ram, 160 hdd | ATI Mobility Radeon 9600 128Mb 446Mhz (1920x1200 60 Hertz) | Ati Catalyst 09.3 Control Center 2009.0225.1546.28221 | AGP4x Performace profile| Dx9c D3D6.14.10.0647 OpenGL6.14.10.8543 |
« Reply #91 on: April 21, 2012, 11:18:33 AM »
Yeah, I've had this kind of math at school.

You will need the inverted sines and cosines for this, and 3D Rad doesn't have them.
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0
« Reply #92 on: April 21, 2012, 12:09:53 PM »
3D Rad doesn't have them.

     There are certain functions already available in Rad, such as iFloatCos, iFloatSqrt etc.. But I have included all standard math functions to provide a complete suite.


Hi RobertooMolvadoo,
yes you need to include this dll from jestermon
This is jestermon post, Is in the first page. :  RadMath.dll, a dll with 17 maths functions she make for us
you can include it

I'm working in the solution to my question



Using: 3d rad v7.22 | IntelPentM 2Ghz, 1GB ram, 160 hdd | ATI Mobility Radeon 9600 128Mb 446Mhz (1920x1200 60 Hertz) | Ati Catalyst 09.3 Control Center 2009.0225.1546.28221 | AGP4x Performace profile| Dx9c D3D6.14.10.0647 OpenGL6.14.10.8543 |
« Reply #93 on: April 21, 2012, 12:30:04 PM »
Okay, good luck.

But could you explain me why you don't just use iQuaternionLookAt?
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0
« Reply #94 on: April 21, 2012, 12:51:20 PM »
Okay, good luck.

But could you explain me why you don't just use iQuaternionLookAt?
I never used before
I'm new. And i dont know how to use it
I have fear of  the note: "Will not work properly if 'direction' and 'up' vectors are paralle"

thanks i will need the luck
« Last Edit: April 21, 2012, 12:53:01 PM by a_mattano »
Using: 3d rad v7.22 | IntelPentM 2Ghz, 1GB ram, 160 hdd | ATI Mobility Radeon 9600 128Mb 446Mhz (1920x1200 60 Hertz) | Ati Catalyst 09.3 Control Center 2009.0225.1546.28221 | AGP4x Performace profile| Dx9c D3D6.14.10.0647 OpenGL6.14.10.8543 |
« Reply #95 on: April 21, 2012, 05:11:34 PM »
4)

how to get the Trigonometric functions Tangent   tan (or tg)

"tan" is: (http://es.wikipedia.org/wiki/Tangente_(trigonometr%C3%ADa) )



of  WorldLocationPL ?

where "a" i think is "z"
and   "b" i think is "y"

(mike: I'm making the algorithm in 2 dimension first)

So in simple words how can i make



using jestermond radmath?

i has "a" and "b" and need to know "alpha".
so i need to do  TAN-1 to get the angle alpha , but don't know how to do it
Using: 3d rad v7.22 | IntelPentM 2Ghz, 1GB ram, 160 hdd | ATI Mobility Radeon 9600 128Mb 446Mhz (1920x1200 60 Hertz) | Ati Catalyst 09.3 Control Center 2009.0225.1546.28221 | AGP4x Performace profile| Dx9c D3D6.14.10.0647 OpenGL6.14.10.8543 |
« Reply #96 on: April 21, 2012, 07:16:55 PM »
Quote
I have fear of  the note: "Will not work properly if 'direction' and 'up' vectors are paralle"

There's really no problem since that rarely happens, and if it does, I'm sure it will hardly be noticeable.

Usually, your up direction should be "world-up" or "local-up". For example, world up is Vector3(0,1,0) and local-up is available in my example projects.

If you need any help, most of these trig functions can be avoided with 3DRad's vector functions.
« Reply #97 on: April 22, 2012, 02:14:50 PM »

Thanks!
i need to make the "inverse tan"
in the windows7 calculator is call "atand()" and gives me the angle
i think in jestermon radmath there is no such thing. is there a way get to the solution? kindly Alan
Using: 3d rad v7.22 | IntelPentM 2Ghz, 1GB ram, 160 hdd | ATI Mobility Radeon 9600 128Mb 446Mhz (1920x1200 60 Hertz) | Ati Catalyst 09.3 Control Center 2009.0225.1546.28221 | AGP4x Performace profile| Dx9c D3D6.14.10.0647 OpenGL6.14.10.8543 |
« Reply #98 on: April 22, 2012, 03:17:15 PM »

Thanks!
i need to make the "inverse tan"
in the windows7 calculator is call "atand()" and gives me the angle
i think in jestermon radmath there is no such thing. is there a way get to the solution? kindly Alan

OK, i get it.

in RadMath dll  atand or "inverse tan" is

R_atan2(float,float)
   Return data in quaternion (max 3,14159...... positive or negative)
   float = first value Y axis  or up down direction
   float = second value X or Z axis  distance negative or positive as horizontal

and then i use  "R_radians2degrees" RadMath dll function to convert in to angles.

...and i have exactly the same thing as "R_quat2axis" as you
RobertooMolvadoo tell me.
Quote
But could you explain me why you don't just use iQuaternionLookAt?
i didn't know. maby i was needing an example. But thank!Thanks to you to Rush.
this was inside jestermon code

   iObjectOrientation(OBJ_22,q); //get the quat
   R_quat2axis(q);

and gives the same result.
Now i understand how it works!!!! and i will put the solution to my step number 4)

the solution is "degree"

Code: [Select]
   PL = AL;                                               /// ad Past Location , as i learn here from jestermon
   iObjectLocation ( OBJ_22 , AL ) ;                      //OBJ_22 is the Airplane RigidBody

   WorldLocationPL.x = AL.x - PL.x ;
   WorldLocationPL.y = AL.y - PL.y ;
   WorldLocationPL.z = AL.z - PL.z ;
   

   alpha = R_atan2(WorldLocationPL.y,WorldLocationPL.z);//primero la altura y luego la distancia
   degree = R_radians2degrees(alpha);

and here is the part of the code more compact

Code: [Select]
   degreeX = R_radians2degrees(R_atan2(AL.x - PL.x,AL.y - PL.y));//primero la altura y luego la distancia
   compass = R_radians2degrees(R_atan2(AL.x - PL.x,AL.z - PL.z));//primero la distncia EO y luego la distancia NS
   degreeZ = R_radians2degrees(R_atan2(AL.y - PL.y,AL.z - PL.z));//primero la altura y luego la distanciaNS
« Last Edit: April 22, 2012, 05:02:48 PM by a_mattano »
Using: 3d rad v7.22 | IntelPentM 2Ghz, 1GB ram, 160 hdd | ATI Mobility Radeon 9600 128Mb 446Mhz (1920x1200 60 Hertz) | Ati Catalyst 09.3 Control Center 2009.0225.1546.28221 | AGP4x Performace profile| Dx9c D3D6.14.10.0647 OpenGL6.14.10.8543 |
« Reply #99 on: April 22, 2012, 05:08:52 PM »

5) How to change in Compass degree style
from 0 to 360      North = 0 or 360

answer

Quote
    if   (compass<0)   
                     {
                       compass360=360-(compass*-1);
                      }

                      else

                      {
                        compass360=compass;               //this change the degrees in to compass style
                       }

Using: 3d rad v7.22 | IntelPentM 2Ghz, 1GB ram, 160 hdd | ATI Mobility Radeon 9600 128Mb 446Mhz (1920x1200 60 Hertz) | Ati Catalyst 09.3 Control Center 2009.0225.1546.28221 | AGP4x Performace profile| Dx9c D3D6.14.10.0647 OpenGL6.14.10.8543 |
« Reply #100 on: April 23, 2012, 09:15:07 AM »
So here is the code of the World Angle of the WINDARROW

Compass Heading (y axis)
y:  0 to  360   

pitch and bank
z:  0 to  90   (airplane is climbing pointing up North)
   -0 to -90   (airplane is going down direction North)
    200 to  290   ((positive = climbing) in the other side the number "2" is similar to "S" South)
   -200 to -290  (negative is descending South direction)

NOTE: the number "2" of 200 is just a reference for South

pitch and bank
x:  0 to  90   (airplane has pitch if it looks North)
   -0 to -90 
    200 to  290 
   -200 to -290

Code: [Select]
//****************************************************************************
/// START OF RADMATH FUNCTION BLOCK
///****************************************************************************
int MathDLLHandle=0;
int POINTER = OBJ_0;
float [] AxisValue (4);
//-----------------------------------------------------------------------------
//R_radians2degrees
//-----------------------------------------------------------------------------
float R_radians2degrees(float value)
{
   iDLLArraySet(0,value);
   iDLLCall(MathDLLHandle,"R_radians2degrees",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//R_degrees2radians
//-----------------------------------------------------------------------------
float R_degrees2radians(float value)
{
   iDLLArraySet(0,value);
   iDLLCall(MathDLLHandle,"R_degrees2radians",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//R_cos
//-----------------------------------------------------------------------------
float R_cos(float value)
{
   iDLLArraySet(0,value);
   iDLLCall(MathDLLHandle,"R_cos",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//R_sin
//-----------------------------------------------------------------------------
float R_sin(float value)
{
   iDLLArraySet(0,value);
   iDLLCall(MathDLLHandle,"R_sin",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//R_tan
//-----------------------------------------------------------------------------
float R_tan(float value)
{
   iDLLArraySet(0,value);
   iDLLCall(MathDLLHandle,"R_tan",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//R_acos
//-----------------------------------------------------------------------------
float R_acos(float value)
{
   iDLLArraySet(0,value);
   iDLLCall(MathDLLHandle,"R_acos",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//R_atan
//-----------------------------------------------------------------------------
float R_atan(float value)
{
   iDLLArraySet(0,value);
   iDLLCall(MathDLLHandle,"R_atan",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//R_asin
//-----------------------------------------------------------------------------
float R_asin(float value)
{
   iDLLArraySet(0,value);
   iDLLCall(MathDLLHandle,"R_asin",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//R_sinh
//-----------------------------------------------------------------------------
float R_sinh(float value)
{
   iDLLArraySet(0,value);
   iDLLCall(MathDLLHandle,"R_sinh",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//R_cosh
//-----------------------------------------------------------------------------
float R_cosh(float value)
{
   iDLLArraySet(0,value);
   iDLLCall(MathDLLHandle,"R_cosh",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//R_tanh
//-----------------------------------------------------------------------------
float R_tanh(float value)
{
   iDLLArraySet(0,value);
   iDLLCall(MathDLLHandle,"R_tanh",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//R_atan2
//-----------------------------------------------------------------------------
float R_atan2(float value1, float value2)
{
   iDLLArraySet(0,value1);
   iDLLArraySet(1,value2);
   iDLLCall(MathDLLHandle,"R_atan2",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//R_exp
//-----------------------------------------------------------------------------
float R_exp(float value)
{
   iDLLArraySet(0,value);
   iDLLCall(MathDLLHandle,"R_exp",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//R_log
//-----------------------------------------------------------------------------
float R_log(float value)
{
   iDLLArraySet(0,value);
   iDLLCall(MathDLLHandle,"R_log",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//R_log10
//-----------------------------------------------------------------------------
float R_log10(float value)
{
   iDLLArraySet(0,value);
   iDLLCall(MathDLLHandle,"R_log10",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//R_sqrt
//-----------------------------------------------------------------------------
float R_sqrt(float value)
{
   iDLLArraySet(0,value);
   iDLLCall(MathDLLHandle,"R_sqrt",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//R_pow
//-----------------------------------------------------------------------------
float R_pow(float value1, float value2)
{
   iDLLArraySet(0,value1);
   iDLLArraySet(1,value2);
   iDLLCall(MathDLLHandle,"R_pow",0);
   float f = iDLLArrayGet(0);
   return f;
}
//-----------------------------------------------------------------------------
//MathInitialize
//-----------------------------------------------------------------------------
void MathInitialize()
{
   MathDLLHandle = iDLLLoad(".\\3DRad_res\\objects\\Script\\RadMath2.dll");
}
//-----------------------------------------------------------------------------
//MathDeInitialize
//-----------------------------------------------------------------------------
void MathDeInitialize()
{
   if (MathDLLHandle != 0)
      iDLLUnload(MathDLLHandle);
}
//-----------------------------------------------------------------------------
//R_vectorAngle   - Returns angle between vectors
//-----------------------------------------------------------------------------
float R_vectorAngle(Vector3 a, Vector3 b)
{
   Vector3 na,nb;
   float dot, angle;
   iVectorLengthSet(na,a,1);
   iVectorLengthSet(nb,b,1);
   dot = iVectorDot(na,nb);
   angle = R_acos(dot);
   angle = R_radians2degrees(angle);
   return angle;
}
//-----------------------------------------------------------------------------
//R_quat2axis - Returns the axis angles from a quaternion
//-----------------------------------------------------------------------------
void R_quat2axis(Quaternion q)
{
   Vector3 v;
   float x,y,z,w;
   string s;
   x=q.x; y=q.y; z=q.z; w=q.w;
   iDLLArraySet(0,x);
   iDLLArraySet(1,y);
   iDLLArraySet(2,z);
   iDLLArraySet(3,w);
   iDLLCall(MathDLLHandle,"R_quat2axis",0);
   float angle = iDLLArrayGet(0);
   x = iDLLArrayGet(1); s=x; if(s=="-1.#IND") x=0;
   y = iDLLArrayGet(2); s=y; if(s=="-1.#IND") y=0;
   z = iDLLArrayGet(3); s=z; if(s=="-1.#IND") z=0;
   AxisValue[0]=angle;
   AxisValue[1]=x;
   AxisValue[2]=y;
   AxisValue[3]=z;
}


///****************************************************************************
/// END OF RADMATH FUNCTION BLOCK
///****************************************************************************

//Add your globals here


Vector3 WL , PL ;          //AirplaneLocation           PastLocation
Vector3 WorldLocationPL;   // PastLocation move to 000 worl location
float alpha,degreeX, compass, degreeZ, compass360, degreeZ90, degreeX90;

Vector3 v;
Quaternion q;
float angle;
string PS;
int PRINT = OBJ_88;


void Main()
{
   if(iInitializing())
   {
      MathInitialize();
   }
   else if (iDeinitializing())
   {
      MathDeInitialize();
   }


   PL = WL;                                               /// ad Past Location , as i learn here from jestermon
   iObjectLocation ( OBJ_22 , WL ) ;                      //OBJ_22 is the WindArrow of the Airplane
   
   degreeX = R_radians2degrees(R_atan2(WL.y - PL.y,WL.x - PL.x));//primero la altura y luego la distancia
   if       (degreeX>90) {degreeX90=380-degreeX;} //this change the degrees from 0 to 90 North direccion and 200 to 290 in South direccion (The "2" indicate direction S )
   else if  (degreeX<-90) {degreeX90=(-1*380)-degreeX;}
   else     {degreeX90=degreeX;}//this change the degrees from -0 to -90 North direccion and -200 to -290 in South direccion (The "2" indicate direction S )

   compass = R_radians2degrees(R_atan2(WL.x - PL.x,WL.z - PL.z));//primero la distncia EO y luego la distancia NS
if   (compass<0) {compass360=360-(compass*-1);}else{compass360=compass;}//this change the degrees in to compass style

   degreeZ = R_radians2degrees(R_atan2(WL.y - PL.y,WL.z - PL.z));//primero la altura y luego la distanciaNS
   if       (degreeZ>90) {degreeZ90=380-degreeZ;}///else{degreeZ90=degreeZ;}//this change the degrees from 0 to 90 North direccion and 200 to 290 in South direccion (The "2" indicate direction S )
   else if  (degreeZ<-90) {degreeZ90=(-1*380)-degreeZ;}
   else     {degreeZ90=degreeZ;}//this change the degrees from -0 to -90 North direccion and -200 to -290 in South direccion (The "2" indicate direction S )


 // OUT_22 44 and 66 was ValuePrint and now we have iObjectTextSet
   iObjectTextSet(PRINT, PS ="WIND ARROW WORLD ANGLE   EO x="+degreeX90+"          COMPASS y="+compass360+"            NS z="+degreeZ90);
}


Can a guru clean it and make it more compact?
I'm Junior!
« Last Edit: April 23, 2012, 01:16:52 PM by a_mattano »
Using: 3d rad v7.22 | IntelPentM 2Ghz, 1GB ram, 160 hdd | ATI Mobility Radeon 9600 128Mb 446Mhz (1920x1200 60 Hertz) | Ati Catalyst 09.3 Control Center 2009.0225.1546.28221 | AGP4x Performace profile| Dx9c D3D6.14.10.0647 OpenGL6.14.10.8543 |
« Reply #101 on: April 23, 2012, 08:03:18 PM »
Quote
Can a guru clean it and make it more compact?

Haha.. ok let me try.  :D
« Reply #102 on: April 27, 2012, 09:51:40 AM »
So... was this even helpful?? ::)
« Reply #103 on: May 08, 2012, 06:44:05 AM »
No?

Ok.

I guess.. there's no reason I should be sharing my scripts for FREE.. so I'm going to remove them. Have fun solving your own rotations. ::) They'll be extra fun when you try to mix quaternions and good old fashioned trig. lol
« Last Edit: May 08, 2012, 06:48:49 AM by Rush3Fan »
« Reply #104 on: May 08, 2012, 02:11:55 PM »
hahahahahaaaahaahaaaaa  ;D  ;D  ;D

give em a lil time Rush... a lot of em don't realize that they'll probably be needing this kinda stuff if they plan on making a real game...

--Mike
Pages: 1 ... 5 6 [7] 8