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

  1. // %PARAMETERS = "CH16LIST C:\UT2004"
  2. //Identifies the package
  3. //CH16_05LIST.uc
  4.  
  5. class CH16_05LIST extends Commandlet;
  6. //#1 Definition of struct data types at class scope
  7. //3D vector
  8.   struct L3DVector{
  9.      var float    x;
  10.      var float    y;
  11.      var float    z;
  12.   };
  13. //2D vector
  14.   struct L2DVector{
  15.      var float x;
  16.      var float y;
  17.   };
  18.  
  19. function int Main(string Args){
  20. // #2 Declaration of identifiers for vectors
  21. //Using the data types created above
  22.    local L3DVector v3DFirst;
  23.    local L2DVector v2DFirst;
  24.    local float rMagnitude;
  25.    rMagnitude = 0;
  26.  
  27. // #3 Initialization of the 3D vector
  28.    v3DFirst.x = 2;
  29.    v3DFirst.y = 4;
  30.    v3DFirst.z = 8;
  31. // Initialization of the 2D vector
  32.    v2DFirst.x = 2;
  33.    v2DFirst.y = 8;
  34.  
  35. // #4 Calculation of the magnitude of the 3D vector
  36.    rMagnitude = Sqrt(Square(v3DFirst.x)
  37.                    + Square(v3DFirst.y)
  38.                    + Square(v3DFirst.z));
  39.    Log( Chr(10) $ "  A unit vector is given by the ratio of each "
  40.                 $ Chr(10) $ "  of the components of the vector "
  41.                 $ Chr(10) $ "  to the magnitude of the vector: "
  42.                 $ Chr(10) $ "  v / ||v||. ");
  43.  
  44.    Log(Chr(10) $"  3D Vector:" $ Chr(10));
  45.    Log("  The magnitude of [ "
  46.                                 @ v3DFirst.x
  47.                                 @ v3DFirst.y
  48.                                 @ v3DFirst.z
  49.                                 @ " ] is " @ rMagnitude);
  50.    if(rMagnitude != 0){
  51.       v3DFirst.x /= rMagnitude;
  52.       v3DFirst.y /= rMagnitude;
  53.       v3DFirst.z /= rMagnitude;
  54.    }
  55.  
  56.     Log("  Normalized, this 3D Vector is");
  57.     Log("  [ "
  58.                                 @ v3DFirst.x
  59.                                 @ v3DFirst.y
  60.                                 @ v3DFirst.z
  61.                                 @ " ]");
  62.  // #5 Calculation of the 2D vector
  63.    rMagnitude = Sqrt( Square(v2DFirst.x) + Square(v2DFirst.y) );
  64.  
  65.    Log( Chr(10) $ "  2D Vector:" $ Chr(10));
  66.    Log("  The magnitude of [ "
  67.                                 @ v3DFirst.x
  68.                                 @ v3DFirst.y
  69.                                 @ " ] is "
  70.                                 @ rMagnitude);
  71.     if(rMagnitude != 0){
  72.         v3DFirst.x /= rMagnitude;
  73.         v3DFirst.y /= rMagnitude;
  74.     }
  75.  
  76.     Log("  Normalized, this 2D Vector is");
  77.     Log("  [ "
  78.                                 @ v3DFirst.x
  79.                                 @ v3DFirst.y
  80.                                 @ " ]");
  81.  
  82.    return 0;
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.