home *** CD-ROM | disk | FTP | other *** search
- // %PARAMETERS = "CH16LIST C:\UT2004"
- //Identifies the package
- //CH16_05LIST.uc
-
- class CH16_05LIST extends Commandlet;
- //#1 Definition of struct data types at class scope
- //3D vector
- struct L3DVector{
- var float x;
- var float y;
- var float z;
- };
- //2D vector
- struct L2DVector{
- var float x;
- var float y;
- };
-
- function int Main(string Args){
- // #2 Declaration of identifiers for vectors
- //Using the data types created above
- local L3DVector v3DFirst;
- local L2DVector v2DFirst;
- local float rMagnitude;
- rMagnitude = 0;
-
- // #3 Initialization of the 3D vector
- v3DFirst.x = 2;
- v3DFirst.y = 4;
- v3DFirst.z = 8;
- // Initialization of the 2D vector
- v2DFirst.x = 2;
- v2DFirst.y = 8;
-
- // #4 Calculation of the magnitude of the 3D vector
- rMagnitude = Sqrt(Square(v3DFirst.x)
- + Square(v3DFirst.y)
- + Square(v3DFirst.z));
- Log( Chr(10) $ " A unit vector is given by the ratio of each "
- $ Chr(10) $ " of the components of the vector "
- $ Chr(10) $ " to the magnitude of the vector: "
- $ Chr(10) $ " v / ||v||. ");
-
- Log(Chr(10) $" 3D Vector:" $ Chr(10));
- Log(" The magnitude of [ "
- @ v3DFirst.x
- @ v3DFirst.y
- @ v3DFirst.z
- @ " ] is " @ rMagnitude);
- if(rMagnitude != 0){
- v3DFirst.x /= rMagnitude;
- v3DFirst.y /= rMagnitude;
- v3DFirst.z /= rMagnitude;
- }
-
- Log(" Normalized, this 3D Vector is");
- Log(" [ "
- @ v3DFirst.x
- @ v3DFirst.y
- @ v3DFirst.z
- @ " ]");
- // #5 Calculation of the 2D vector
- rMagnitude = Sqrt( Square(v2DFirst.x) + Square(v2DFirst.y) );
-
- Log( Chr(10) $ " 2D Vector:" $ Chr(10));
- Log(" The magnitude of [ "
- @ v3DFirst.x
- @ v3DFirst.y
- @ " ] is "
- @ rMagnitude);
- if(rMagnitude != 0){
- v3DFirst.x /= rMagnitude;
- v3DFirst.y /= rMagnitude;
- }
-
- Log(" Normalized, this 2D Vector is");
- Log(" [ "
- @ v3DFirst.x
- @ v3DFirst.y
- @ " ]");
-
- return 0;
- }
-
-
-
-
-
-
-