All pastes #21519 Raw Edit

Stuff

public text v1 · immutable
#21519 ·published 2005-08-29 18:57 UTC
rendered paste body
Unit FMState;

Interface

Type
	// Basic physical properties for any discernible object
	TPhysicalObject = Record
		Position,                  // current aircraft-position
		Orientation,               // current aircraft orientation
		Movement      : TSTVertex; // Pre-calculated movement rates
		Speed         : Float;     // current aircraft speed
		ChangedOrient : Boolean;   // true if the aicraft orientation was changed
	End;

	// A list of all physical entities in the engine
	TPhysicalObjectList = Array Of TPhysicalObject;

Procedure StepPhysicalObject(Var PS : TPhysicalObject);
Function AppendPhysicalObject(Var POL : TPhysicalObjectList): Cardinal;
Procedure StepAllPhysicalObjects(Var POL : TPhysicalObjectList);

Implementation

Procedure StepPhysicalObject(Var PS : TPhysicalObject);
Var
	RotateX,
	RotateY,
	RotateZ,
	Combined : TSTMatrix;

Begin
	// Only re-calculate if changed orientation
	If ChangedOrient Then
	Begin
		// Start as a straight movement
		PS.Movement.X := PS.Speed;
		PS.Movement.Y := 0;
		PS.Movement.Z := 0;
		// Calculate rotation matrices
		SetRotateMatrixX(RotateX, PS.Orientation.X);
		SetRotateMatrixY(RotateY, PS.Orientation.Y);
		SetRotateMatrixZ(RotateZ, PS.Orientation.Z);
		SetIdentityMatrix(Combined);
		// Multiply all transformation matrices into one
		MultiplyMatrix(Combined, RotateX);
		MultiplyMatrix(Combined, RotateY);
		MultiplyMatrix(Combined, RotateZ);
		// Apply transformation
		PS.Movement := TransformVertex(PS.Movement, Combined);
		ChangedOrient := False;
	End;
	// Move position around by movement ammount
	PS.Position := PS.Position + PS.Movement;
End;

Function AppendPhysicalObject(Var POL : TPhysicalObjectList): Cardinal;
Begin
	// Increase the list size
	SetLength(POL, Length(POL) + 1);
	// Return last object (recently created)
	AppendPhysicalObject := Length(POL) - 1;
End;

Procedure StepAllPhysicalObjects(Var POL : TPhysicalObjectList);
Var
	Ctrl : Cardinal;
Begin
	// Update all physical objects in the list
	For Ctrl := 0 To Length(POL) - 1 Do
		StepPhysicalObject(POL[Ctrl]);
End;

End.