CortTest
Class CortPlayer

source: e:\games\UnrealTournament\CortTest\Classes\CortPlayer.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Pawn
         |
         +--Engine.PlayerPawn
            |
            +--Botpack.TournamentPlayer
               |
               +--Botpack.TournamentMale
                  |
                  +--Botpack.TMale1
                     |
                     +--CortTest.CortPlayer
Direct Known Subclasses:None

class CortPlayer
extends Botpack.TMale1


Variables
 pitch_offset, yaw_offset


Function Summary
 void Fire(optional float)
     
// overloaded Fire to display debug info
 void PlayerCalcView(out actor, out vector, out rotator)
     
//////////////////////////////// PlayerCalcView /////////////////////////
 final PrintQuat(Quaternion q)
 Quaternion add_quats(Quaternion q1, Quaternion q2)
     
// Concatenates two quaternions
 Quaternion axis_to_quat(Vector axis, float phi)
     
// convert an angle and an axis to the Quaternion corresponding to that
// rotation.  the axis must be normalized, but we assume as much.
 void normalize_quat(out Quaternion)
     
// normalizes a quaternion.  This shouldn't need to be called unless a quaternion
// is sticking around for hundreds of concatenations.



Source Code


00001	class CortPlayer expands TMale1 config(CortTest);
00002	
00003	// local Quaternion structure
00004	struct Quaternion {
00005		var float X, Y, Z, W;
00006	};
00007	
00008	// these offsets are read from the config file.
00009	var config int roll_offset, pitch_offset, yaw_offset;
00010	
00011	/////////////////////////////////// Other changes ////////////////
00012	// convenience function to set a vector's values
00013	function final Vector SetVect(float x, float y, float z)
00014	{
00015		local Vector dest;
00016		dest.X = x;
00017		dest.Y = y;
00018		dest.Z = z;
00019		return dest;
00020	}
00021	
00022	function final PrintQuat(Quaternion q)
00023	{
00024		ClientMessage("Quat is: " @q.X @q.Y @q.Z @q.W);
00025	}
00026	
00027	// overloaded Fire to display debug info
00028	exec function Fire( optional float F )
00029	{
00030		local Vector roll_axis, pitch_axis, yaw_axis;
00031		local Vector xax, yax, zax;
00032		local Quaternion rquat, pquat, yquat, oquat;
00033		local float M[16];
00034		local Rotator R;
00035	
00036		// initialize axes & rotator
00037		R = Rot(9000, 1000, 4500);
00038		roll_axis = SetVect(1.0, 0.0, 0.0);
00039		pitch_axis = SetVect(0.0, 1.0, 0.0);
00040		yaw_axis = SetVect(0.0, 0.0, 1.0);
00041	
00042		// snag & print current rotator axes
00043		GetAxes(R, xax, yax, zax);
00044		ClientMessage("Xax: " @xax @VSize(xax));
00045		ClientMessage("Yax: " @yax @VSize(yax));
00046		ClientMessage("Zax: " @zax @VSize(zax));
00047	
00048		// convert angle/axis pairs to quaternions
00049		pquat = axis_to_quat(pitch_axis, R.Pitch*3.141592/32768.0);
00050		yquat = axis_to_quat(yaw_axis, R.Yaw * 3.141592 / 32768.0);
00051		rquat = axis_to_quat(roll_axis, R.Roll*3.141592/32768.0);
00052	
00053		oquat = add_quats(yquat, pquat);
00054		oquat = add_quats(oquat, rquat);
00055	
00056		// build rotation matrix from oquat
00057		build_rotmatrix(M, oquat);
00058		R = get_rotator_from_matrix(M);
00059	
00060		PlaySound(Sound'Male1Voice.M1diebitch', SLOT_None, 2.0, false, 4096.0, 1.5);
00061		//Super.Fire(F);
00062	}
00063	
00064	
00065	/////////////////////////////// Quaternion Math Routines //////////////////////
00066	
00067	// convert an angle and an axis to the Quaternion corresponding to that
00068	// rotation.  the axis must be normalized, but we assume as much.
00069	final function Quaternion axis_to_quat(Vector axis, float phi)
00070	{
00071		local float scale;
00072		local Quaternion q;
00073	
00074		scale = sin(phi/2.0);
00075		q.X = axis.X * scale;
00076		q.Y = axis.Y * scale;
00077		q.Z = axis.Z * scale;
00078		q.W = cos(phi/2.0);
00079		return q;
00080	}
00081	
00082	
00083	// Concatenates two quaternions
00084	final function Quaternion add_quats(Quaternion q1, Quaternion q2)
00085	{
00086		local Quaternion dest;
00087		local Vector t1, t2, t3;
00088		local float t1DOTt2;
00089	
00090		// copy first three elements of quats into temp vectors,
00091		// scaled by the W value from the opposite quat
00092		t1 = SetVect(q1.X, q1.Y, q1.Z);
00093		t2 = SetVect(q2.X, q2.Y, q2.Z);
00094		
00095		// dot & cross product, then scale t1 and t2
00096		t1DOTt2 = t1 Dot t2;
00097		t3 = t2 Cross t1;
00098		t1 *= q2.W;
00099		t2 *= q1.W;
00100	
00101		// the first three elements of the final quaternion are the sums of
00102		// the corresponding fields of t1, t2 and t3.
00103		dest.X = t1.X + t2.X + t3.X;
00104		dest.Y = t1.Y + t2.Y + t3.Y;
00105		dest.Z = t1.Z + t2.Z + t3.Z;
00106	
00107		// the last element of the final quaternion...
00108		dest.W = (q1.W * q2.W) - t1DOTt2;
00109		return dest;
00110	}
00111	
00112	// normalizes a quaternion.  This shouldn't need to be called unless a quaternion
00113	// is sticking around for hundreds of concatenations.
00114	final function normalize_quat(out Quaternion q)
00115	{
00116	    local float mag;
00117	
00118	    mag = Sqrt(q.X*q.X + q.Y*q.Y + q.Z*q.Z + q.W*q.W);
00119	    q.X /= mag;
00120			q.Y /= mag;
00121			q.Z /= mag;
00122			q.W /= mag;
00123	}
00124	
00125	// build a rotation matrix out of a quaternion.  "matrices" are 
00126	// simple one-dimensional arrays of 16 floats, laid out as follows:
00127	//
00128	//    1  2  3  4
00129	//  +-----------
00130	// 1| 0  1  2  3
00131	// 2| 4  5  6  7
00132	// 3| 8  9 10 11
00133	// 4|12 13 14 15
00134	final function build_rotmatrix(out float M[16], Quaternion q)
00135	{
00136		M[0] = 1.0 - 2.0 * (q.Y * q.Y + q.Z * q.Z);
00137		M[1] = 2.0 * (q.X * q.Y - q.Z * q.W);
00138		M[2] = 2.0 * (q.Z * q.X + q.Y * q.W);
00139		//M[3] = 0.0;
00140	
00141		M[4] = 2.0 * (q.X * q.Y + q.Z * q.W);
00142		M[5]= 1.0 - 2.0 * (q.Z * q.Z + q.X * q.X);
00143		M[6] = 2.0 * (q.Y * q.Z - q.X * q.W);
00144		//M[7] = 0.0;
00145	
00146		M[8] = 2.0 * (q.Z * q.X - q.Y * q.W);
00147		M[9] = 2.0 * (q.Y * q.Z + q.X * q.W);
00148		M[10] = 1.0 - 2.0 * (q.Y * q.Y + q.X * q.X);
00149		//M[11] = 0.0;
00150	
00151		//M[12] = 0.0;
00152		//M[13] = 0.0;
00153		//M[14] = 0.0;
00154		//M[15] = 1.0;
00155	}
00156	
00157	// this is a general matrix-vector multiply.  but we don't USE it.
00158	/*
00159	final function Vector transform_vect(float M[16], Vector v)
00160	{
00161		local Vector dest;
00162		dest = SetVect(M[0]*v.X + M[1]*v.Y + M[2]*v.Z,
00163									 M[4]*v.X + M[5]*v.Y + M[6]*v.Z,
00164									 M[8]*v.X + M[9]*v.Y + M[10]*v.Z);
00165		return dest;
00166	}
00167	*/
00168	
00169	// this function takes a rotation matrix and returns the corresponding UnrealScript
00170	// Rotator.  Essentially what it's doing is using the matrix to transform the unit
00171	// vectors along the three coordinate axes, and then passing these vectors to
00172	// OrthoRotation().  But what's actually going on is much faster.
00173	final function Rotator get_rotator_from_matrix(float M[16])
00174	{
00175		local Vector xa, ya, za;
00176		local Rotator R;
00177	
00178		// we can extract the rotated axes directly from the matrix,
00179		// without any multiplies at all!  cool!
00180		xa = SetVect(M[0], M[4], M[8]);
00181		ya = SetVect(M[1], M[5], M[9]);
00182		//za = SetVect(M[2], M[6], M[10]); // seems to be incorrect!  we can fix that...
00183		za = xa Cross ya;
00184		ClientMessage("Xa: " @xa @VSize(xa));
00185		ClientMessage("Ya: " @ya @VSize(ya));
00186		ClientMessage("Za: " @za @VSize(za));
00187		// convert the axes to a rotator.
00188		R = OrthoRotation(xa, ya, za);
00189		return R;
00190	}
00191	/*
00192	//////////////////////////////// PlayerCalcView /////////////////////////
00193	function PlayerCalcView(out actor ViewActor, out vector CameraLocation, out rotator CameraRotation )
00194	{
00195		local vector View,HitLocation,HitNormal, FirstHit, spot;
00196		local float DesiredDist, ViewDist, WallOutDist;
00197		local actor HitActor;
00198		local Pawn PTarget;
00199	
00200		// additional local variables from Cort
00201		local Quaternion rquat, pquat, yquat, drquat, dpquat, dyquat, oquat;
00202		local Vector yaw_axis, pitch_axis, roll_axis; // the coordinate x/y/z axes
00203		local float M[16]; // rotation matrix
00204	
00205		if ( ViewTarget != None )
00206		{
00207			ViewActor = ViewTarget;
00208			CameraLocation = ViewTarget.Location;
00209			CameraRotation = ViewTarget.Rotation;
00210			PTarget = Pawn(ViewTarget);
00211			if ( PTarget != None )
00212			{
00213				if ( Level.NetMode == NM_Client )
00214				{
00215					if ( PTarget.bIsPlayer )
00216						PTarget.ViewRotation = TargetViewRotation;
00217					PTarget.EyeHeight = TargetEyeHeight;
00218					if ( PTarget.Weapon != None )
00219						PTarget.Weapon.PlayerViewOffset = TargetWeaponViewOffset;
00220				}
00221				if ( PTarget.bIsPlayer )
00222					CameraRotation = PTarget.ViewRotation;
00223				CameraLocation.Z += PTarget.EyeHeight;
00224			}
00225			if ( Carcass(ViewTarget) != None )
00226			{
00227				if ( bBehindView || (ViewTarget.Physics == PHYS_None) )
00228					CameraRotation = ViewRotation;
00229				else 
00230					ViewRotation = CameraRotation;
00231				if ( bBehindView )
00232					CalcBehindView(CameraLocation, CameraRotation, 190);
00233			}
00234			else if ( bBehindView )
00235				CalcBehindView(CameraLocation, CameraRotation, 180);
00236				return;
00237		}
00238	
00239		///////////////// Cort's changes here!
00240	
00241		// initialize axes
00242		roll_axis = SetVect(1.0, 0.0, 0.0);
00243		pitch_axis = SetVect(0.0, 1.0, 0.0);
00244		yaw_axis = SetVect(0.0, 0.0, 1.0);
00245	
00246		// convert angle/axis pairs to quaternions
00247		Log("before ViewRotation is: " @ViewRotation);
00248		rquat = axis_to_quat(roll_axis, ViewRotation.Roll*3.141592/32768.0);
00249		pquat = axis_to_quat(pitch_axis, ViewRotation.Pitch*3.141592/32768.0);
00250		yquat = axis_to_quat(yaw_axis, ViewRotation.Yaw*3.141592/32768.0);
00251	
00252		// these don't need to be re-calculated every frame.
00253		//drquat = axis_to_quat(roll_axis, roll_offset*3.141592/32768.0);
00254		//dpquat = axis_to_quat(pitch_axis, pitch_offset*3.141592/32768.0);
00255		//dyquat = axis_to_quat(yaw_axis, yaw_offset*3.141592/32768.0);
00256	
00257		// add the quats in the proper order
00258		//rquat = add_quats(rquat, drquat);
00259		//pquat = add_quats(pquat, dpquat);
00260		oquat = add_quats(yquat, pquat);
00261		oquat = add_quats(oquat, rquat);
00262		//oquat = add_quats(oquat, dyquat);
00263	
00264		// build rotation matrix from oquat
00265		build_rotmatrix(M, oquat);
00266	
00267		// get Rotator from matrix
00268		ViewRotation = get_rotator_from_matrix(M);
00269		Log(" after ViewRotation is: " @get_rotator_from_matrix(M));
00270		/////////////////// End Cort's changes
00271	
00272		// View rotation.
00273		CameraRotation = ViewRotation;
00274		DesiredFOV = DefaultFOV;		
00275		ViewActor = self;
00276		if( bBehindView ) //up and behind (for death scene)
00277			CalcBehindView(CameraLocation, CameraRotation, 180);
00278		else
00279		{
00280			// First-person view.
00281			CameraLocation = Location;
00282			CameraLocation.Z += Default.BaseEyeHeight;
00283		}
00284	}
00285	*/
00286	/////////////////////////////////// default properties ///////////////////
00287	defaultproperties
00288	{
00289	
00290	}

End Source Code