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: Aircaft 3D Horizon meter for your cockpits  (Read 1520 times)

jestermon

« on: January 26, 2012, 09:56:16 PM »
Lots of chatter about meters and cockpits lately. Even some heated debates on on the topic... So to clear the air, here's a little teaser to keep you all busy for the next couple of months.

Why go 2D when all you need is the cockpit gauges on one skinmesh and just a single skinmesh for each of the needles..You're gonna need sprites for the needles anyway, so no resource difference.. 3D is always more fun

This demo is also a little tutorial full of comments. Of course you will need to make your own instruments, and do your own scaling.
Only the extra files you need for the are provided.
RadMath2.dll is included.

Please note that this a template tutorial, and not an invitation to request for meters.

Have fun.
V7.03

PS: It's not deigned for upside down flying, so if you want that, I'll leave it to you.
« Last Edit: January 26, 2012, 09:58:06 PM by jestermon »
« Reply #1 on: January 26, 2012, 10:02:28 PM »
hey Jes... could you fly that bad boy outbound from the world center for about 7 minutes, and tell me if you notice any jittering of the sprite...

just fly outbound in a straight line for about 6 to 7 minutes...

thx

--Mike

jestermon

« Reply #2 on: January 26, 2012, 10:09:21 PM »
You mean add motion to the plane, and run it for a while?
Will run it while I make some hot chocolate.

jestermon

« Reply #3 on: January 26, 2012, 10:29:26 PM »
Hmm. I added the line below to the script to make the plane fly. Made some hot chocolate, and then laughed at myself

Code: [Select]
   Vector3 zero =  Vector3(0, 0, 0);       //zero vector
   L2P(PLANE,PLANE,zero,Vector3(0,0,1)); //added below line above

Why laugh.. because the plane did not fly in the first place, and I don't use sprites but a round plain and a square plain meshes for the meter.

Anyway no jitters, and the hot chocolate really tastes great.

The location of the plane after about a few minutes.. see image

PS: Hmm. Because of the limitation of the floats in 3D Rad, you are bound to pick up problems with any game that plays far from world center. So the further you go, the more the decimals will be thrown off with large numbers, and decimal accuracy goes out the window.
The only way to get around that is to scale the game down, so that it really takes forever to fly out of float decimal range.

PS2: Ok. I got jitters on the mesh locations,and the meter and needle started crawling/jumping upwards, and kept going. Floats could obviously no longer position the objects precisely.
« Last Edit: January 26, 2012, 10:40:23 PM by jestermon »
« Reply #4 on: January 27, 2012, 07:13:33 AM »
Quote
Ok. I got jitters on the mesh locations,and the meter and needle started crawling/jumping upwards, and kept going. Floats could obviously no longer position the objects precisely.

that's what i was expecting...  i ran into the same issues a while back...

thx for the  confirmation...

--Mike
« Reply #5 on: January 27, 2012, 03:15:06 PM »
that's awesome  ;D
« Reply #6 on: January 28, 2012, 01:40:51 PM »
that's what i was expecting...  i ran into the same issues a while back...

Yeah I remember having same issue, flying a spaceship 6 million meters out..
Result of floatingpoint precision since rad translates everything from world space center.

So why move the plane? Just move the world :)
« Reply #7 on: January 28, 2012, 02:52:10 PM »
why not make the land move instead of the plane? :D

jestermon

« Reply #8 on: January 29, 2012, 05:06:51 AM »
why not make the land move instead of the plane? :D

Great for a single flight simulator, a mathematical nightmare if using more than 1 plane.
« Reply #9 on: January 29, 2012, 08:04:46 AM »
Quote
why not make the land move instead of the plane?

don't laugh at this suggestion... it actually works, and it's not that hard to do...

in the Light Plane Addon there is code you uncomment that does exactly this (based on some logic originally suggested by Shad)... and it works quite well...

here os the code... just make a new script and add it to the project... link the applicable objects as described in the header comments...

note - this logic was implemented way back before the global string functions were added to RAD, so you'll have to remove references to my RadGlobalStrings dll and replace the new global string functions where they are applicable...

Code: [Select]
/////////////////////////////////////////////////////////////////////////////////////
//
//    WorldCoords  Movable Universe Script To Take Care Of Loss Of Precision
//             When Traveling Far From World Center
//
//                  original code by shadamar
//
//
//    This is an example of how you might implement the movable universe logic that
//    to take advantage of projects requiring movement about a wide expansive universe
//
//
//    by default this script is not running - you will have to code it yourself as
//    required in your project.
//
//
//                            General Usage
//
//    ADD and LINK any object, including physic enabled objects, that needs to be
//    tracked and is not otherwise linked to a parent physics object.
//
//    Tracked terrains need to be added to the section below where the others added
//   
//    Use the World Coords to keep track of moving or static objects that need
//    to be tracked in the Virtual World xy map.
//
//    Be sure the number of objects agrees with the allObjs list
//
//    Be sure the number of terrains agrees with all the terrains listed
//
//    If you are using the Infinite Terrain System then only special case terrains
//    such as airports or other unique terrains only need to be tracked.
//
//    this addon uses the GlobalStrings DLL... make sure it is present as indicated
//
//    ADD NDBS AND OTHER NAV AIDS TO THE LIST AND INCREAS THE OBJSNUMBER
//
//    INCREASE THE REFERENCE FOR OTHER TRACKED OBJECTS INCLUDING THE PLANE WHICH
//    YOU ARE IN, AND ADD IT TO THE TRACKED OBJECTS ABOVE THE NUMOBJS LIST COUNT TO
//    BE UPDATED.
//
/////////////////////////////////////////////////////////////////////////////////////////




int[] allObjs={

               OBJ_132,  // item 0
               OBJ_242,
               OBJ_286,
               OBJ_308,
               OBJ_330,
               OBJ_352,
               OBJ_374,
               OBJ_396,   
               OBJ_418,   
               OBJ_440,   
               OBJ_462,
               OBJ_484,
               OBJ_792,
               OBJ_814,
               OBJ_1364,  // building      - may need to be removed if not in your project
               OBJ_1386,  // andro observer - may need to be removed if not in your project
               OBJ_154,   // ndb1   
               OBJ_1870   // ndb2
                          // total count 18 should be reflected below in numObjs
   
};

///                  The Number Count of Tracked Objects -1
///
int numberObjs = 18;      //whatever the number of objects I want to move



int[] allTerrains={
               OBJ_88,   //  the first terrain - remove if not in your project
               OBJ_110,  //  the second terrain - remove if not in your project

};

///                  The Number Count of All Terrain Objects -1
///
int numberTerrains = 2;      //whatever the number of objects I want to move



int            i;
int            startTime,currentTime;
Vector3[]      WorldCoords(numberObjs);
bool           WorldInitialized=false;
Vector3        WorldCenter;





//         FOR THE GLOBALSTRINGS DLL
//
int    DLLHandle;
string ASCII = " !'#$%&`(*+'-./0123456789;:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[/]^_'abcdefghijklmnopqrstuvwxyz{|}~";


//          FUNCTION THAT SETS THE DESIGNATED GLOBAL STRING
//
void AddGlobalString(string inString, int number){
    int        n;
    string     char;
    int        length   =iStringLen(inString)+1;

    if (DLLHandle != 0) {
        iDLLArraySet(1,length);
        for(n=1;n<length;n++){
           iStringMid(char,inString,n,1);
           if(char==" ")char="_";
           iDLLArraySet(n+1,iStringFind(ASCII,char,n,true));
        }
        iDLLArraySet(0,number);
        iDLLCall(DLLHandle,"AddGlobalString",0);
   
    }

}



//          FUNCTION THAT RETURNS THE DESIGNATED GLOBAL STRING
//
string  GetGlobalString(int number){
    string  newString;

    if(DLLHandle !=0){
      iDLLArraySet(0,number);
      //iDLLArraySet(1,5);
      iDLLCall(DLLHandle,"GetGlobalString",0);

       
      int     n,length;
      string  char;
      string myString;

      length=iDLLArrayGet(1);
      for(n=1;n<length;n++){
        iStringMid(char,ASCII,iDLLArrayGet(n+1),1);
        if(char=="_")char=" ";
        newString+=char;
      }
    }
    return newString;
}


//          FUNCTION THAT ADJUST THE LOCATIONS OF ALL TRACKED OBJECTS
//
void moveAll(Vector3 offsetCoords)
{
    Vector3 oldLoc;
    Vector3 newLoc;
    i=0;

   
    while (i<numberObjs )
    {
            iObjectLocation(allObjs[i], oldLoc);
            newLoc=oldLoc+offsetCoords;
            iObjectLocationSet(allObjs[i], newLoc);
            i++;
    }
    i=0;
    while (i<numberTerrains )
    {
            iObjectLocation(allTerrains[i], oldLoc);
            newLoc=oldLoc+offsetCoords;
            iObjectLocationReset(allTerrains[i], newLoc);
            i++;
    }

}




void Main()
{

  if(iInitializing()) {
     DLLHandle=iDLLLoad(".\\3drad_res\\objects\\script\\globalradstrings.dll");

  }

  if (iDeinitializing()) {
     //free memory resources used by the DLL module
     if (DLLHandle != 0) iDLLUnload(DLLHandle);
   }

  //        AT BEGINNING SET THE WORLDCOORDS OF ALL OBJECTS IN THE LIST OF TRACKED OBJECTS
  //         THIS INCLUDES STATIC AS WELL AS MOVING OBJECTS THAT NEED TO BE KEPT TRACK OF
  //
  if(! WorldInitialized){
     i=0;
     while (i<numberObjs ){
       iObjectLocation(allObjs[i],WorldCoords[i]);
     
       //                           make coord available to other scripts
       string  temp;
       if(DLLHandle !=0){
         iStringStr(temp,WorldCoords[i].x,"%0.3f"); AddGlobalString(temp,i*3);
         iStringStr(temp,WorldCoords[i].y,"%0.3f"); AddGlobalString(temp,(i*3) +1);
         iStringStr(temp,WorldCoords[i].z,"%0.3f"); AddGlobalString(temp,(i*3) +2);         
       }
       i++ ; 

     }
     WorldInitialized=true;
   }


   Vector3 mObj;
   Vector3 zeroPoint=Vector3(0,0,0);

   ///                  Track static objects here in the World Coords System
   ///
   iObjectLocation(allObjs[2],mObj);     //the plane body is where the player is so use it
   mObj.y=0;                       

   
   if (! iVectorCompare(mObj,zeroPoint,4000) && WorldInitialized)
   {
      //        get offsets then  move em
      Vector3 offSet;
      offSet.x=-mObj.x;
      offSet.y=0;  //-mObj.y;
      offSet.z=-mObj.z;

      moveAll(offSet);
      WorldCenter+=offSet;
     
      //          then update the world coords in the global dll
      //
      i=0;
      while (i<numberObjs  ){   
       string  temp;
       if(DLLHandle !=0){
         iStringStr(temp,WorldCoords[i].x,"%0.3f"); AddGlobalString(temp,i*3);
         iStringStr(temp,WorldCoords[i].y,"%0.3f"); AddGlobalString(temp,(i*3) +1);
         iStringStr(temp,WorldCoords[i].z,"%0.3f"); AddGlobalString(temp,(i*3) +2);         
       }
       i++;
     }
     
   }

     ///                Track moving object here in the World Coords System             
     ///                                                                               
     ///       Use the array space above the number of objects to store your moveables 
     ///        so their positions are constantly updated as the objects move.   
     ///                                                        // The Plane       
     i=18;

     iObjectLocation(allObjs[2],mObj);
     mObj.y=0;
     string  temp;
     if(DLLHandle !=0){
         iStringStr(temp,mObj.x - WorldCenter.x,"%0.3f"); AddGlobalString(temp,i*3);
         iStringStr(temp,mObj.y - WorldCenter.y,"%0.3f"); AddGlobalString(temp,(i*3) +1);
         iStringStr(temp,mObj.z - WorldCenter.z,"%0.3f"); AddGlobalString(temp,(i*3) +2);         
     }



   //        This is just a  display of the range between two tracked objects
   //        and may be deleted along with the associated value print object
   //
   //OUT_1958=(iVectorLength(mObj-WorldCoords[16])*0.000534);

}

--Mike

jestermon

« Reply #10 on: January 29, 2012, 06:51:38 PM »
Quote
why not make the land move instead of the plane?
don't laugh at this suggestion... it actually works, and it's not that hard to do...
Agreed not hard to do. Just invert the flight direction vector and rotation and away you go. The real messy (but fun) part comes with maintaining the flight path of other moving planes or objects in relation to your own, as well as the moving ground.
« Reply #11 on: January 29, 2012, 07:29:54 PM »
Quote
The real messy (but fun) part comes with maintaining the flight path of other moving planes or objects in relation to your own, as well as the moving ground.

the above code should take care of that... if the object is included in the list, its position will automatically be updated...

i've tried it with both physics and non physics objects... torpedos, cars, etc...

--Mike

jestermon

« Reply #12 on: January 29, 2012, 08:30:57 PM »
..the above code should take care of that... if the object is included in the list, its position will automatically be updated...
i've tried it with both physics and non physics objects... torpedos, cars, etc...
I've not tried it, hence my comment. . . or should that be "hense" my comment :D

jestermon

« Reply #13 on: February 16, 2012, 06:51:37 AM »
This time we go 2D, and use sprites for the horizon meter. This one is a little different. Instead of showing the horizon, we see the plane, and when the actual plane goes, up, so does the meter. A bit of of an inversion from the boring old horizon meter.
Added one of my old space race "huge" terrains, so that there is at least a decent runway to play on.
Have fun
v7.03
Pages: [1]