home *** CD-ROM | disk | FTP | other *** search
/ UnrealScript Game Programming All in One / UnrealScriptGameProgrammingAllInOne.iso / UGPAIOListings / UGPAIOListingsCh16 / CH16LIST / Classes / CH16_04LIST.uc < prev    next >
Encoding:
Text File  |  2006-02-17  |  1.9 KB  |  79 lines

  1. // %PARAMETERS = "CH16LIST C:\UT2004"
  2. //Identifies the package
  3. //CH16_04LIST.uc
  4.  
  5. class CH16_04LIST extends Commandlet;
  6.  
  7. //#1
  8. //Definiom of struct data types at class scope
  9. //3D vector
  10.   struct L3DVector{
  11.      var float    x;
  12.      var float    y;
  13.      var float    z;
  14.   };
  15. //2D vector
  16.   struct L2DVector{
  17.      var float x;
  18.      var float y;
  19.   };
  20.  
  21. function int Main(string Args){
  22.  
  23. //#2
  24. //Declaration of identifiers for vecotrs
  25. //Using the data types created above
  26.    local L3DVector v3DFirst;
  27.    local L2DVector v2DFirst;
  28.    local float rMagnitude;
  29.  
  30.    rMagnitude = 0;
  31.  
  32. //#3 
  33. // Initialization of the 3D vector
  34.    v3DFirst.x = 2;
  35.    v3DFirst.y = 4;
  36.    v3DFirst.z = 8;
  37.  
  38. // Initialization of the 2D vector
  39.    v2DFirst.x = 2;
  40.    v2DFirst.y = 8;
  41.  
  42. // #4
  43. // Calculation of the magnitude of the 3D vector
  44.    rMagnitude = Sqrt(Square(v3DFirst.x)
  45.                    + Square(v3DFirst.y)
  46.                    + Square(v3DFirst.z));
  47.  
  48.  
  49.    Log( Chr(10) $ Chr(10) $ "  To calculate the magnitude of a vector, "
  50.                 $ Chr(10) $ "  you take the square root of the sum of  "
  51.                 $ Chr(10) $ "  the squares of its constituent elements. ");
  52.  
  53.    Log(Chr(10) $"  3D Vector:" $ Chr(10));
  54.    Log(Chr(10) $"  The magnitude of [ " 
  55.                                 @ v3DFirst.x
  56.                                 @ v3DFirst.y
  57.                                 @ v3DFirst.z
  58.                                 @ " ] is " @ rMagnitude);
  59.  
  60.  // #5
  61.   // Calculation of the 2D vector
  62.    rMagnitude = Sqrt( Square(v2DFirst.x) + Square(v2DFirst.y) );
  63.  
  64.    Log(Chr(10) $ "  2D Vector:" $ Chr(10));
  65.    Log(Chr(10) $ "  The magnitude of [ "
  66.                                 @ v3DFirst.x
  67.                                 @ v3DFirst.y
  68.                                 @ " ] is "
  69.                                 @ rMagnitude  $ Chr(10));
  70.  
  71.  
  72.    return 0;
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.