{----------------------------------------------------------------------------
  9bit fixed point vector math - DOS 16bit realmode (Turbo Pascal version)
  Copyright (c) 1994,95 by J.E. Hoffmann
  All rights reserved
 ----------------------------------------------------------------------------}
{$A+,B-,D-,E-,F-,G+,I-,L-,N-,O-,P-,Q-,R-,S-,T-,V-,X+,Y-}
unit _Math;



interface



const
  x     = 0;
  y     = 1;
  z     = 2;

type
  P2D = ^T2D;
  T2D = array[x..y] of Integer;

  P3D = ^T3D;
  T3D = array[x..z] of LongInt;

  P3D2D = ^T3D2D;
  T3D2D = RECORD
    P3  :T3D;
    P2  :T2D;
  end;

  P3DList = ^T3DList;
  T3DList = array[0..2047] of T3D;

  P2DList = ^T2DList;
  T2DList = array[0..2047] of T2D;

  P3D2DList = ^T3D2DList;
  T3D2DList = array[0..2047] of T3D2D;

  PMatrix = ^TMatrix;
  TMatrix = array[0..3, 0..3] of LongInt;

  PPoints = ^TPoints;
  TPoints = array[0..$FF] of T2D;



procedure VecAdd2D(A,B :T2D; var C :T2D);
procedure VecSub2D(A,B :T2D; var C :T2D);

procedure VecZero(var C :T3D);
procedure Vec(vx,vy,vz :LongInt; var C :T3D);
procedure UnVec(A :T3D; var vx,vy,vz :LongInt);
procedure VecAdd(A,B :T3D; var C :T3D);
procedure VecSub(A,B :T3D; var C :T3D);
function VecDot(A,B :T3D) :LongInt;
procedure VecCross(A,B :T3D; var C :T3D);
function VecDistance(A :T3D) :LongInt;
function VecLen(A :T3D) :LongInt;
procedure VecScalMul(k :LongInt; A :T3D; var C :T3D);
procedure VecNormalize(var C :T3D);

procedure Zero(var C :TMatrix);
procedure Cross(var A,B :TMatrix; var C :TMatrix);
procedure Transform(A :T3D; M :TMatrix; var C :T3D);
procedure Project(A :T3D; var C:T2D);
procedure Rotate(rx,ry,rz :Integer; var R :TMatrix);
procedure Create(tx,ty,tz, sx,sy,sz :LongInt; rx,ry,rz :Integer; var M :TMatrix);



implementation



procedure VecAdd2D(A,B :T2D; var C :T2D); external;
procedure VecSub2D(A,B :T2D; var C :T2D); external;

procedure VecZero(var C :T3D); external;
procedure Vec(vx,vy,vz :LongInt; var C :T3D); external;
procedure UnVec(A :T3D; var vx,vy,vz :LongInt); external;
procedure VecAdd(A,B :T3D; var C :T3D); external;
procedure VecSub(A,B :T3D; var C :T3D); external;
function VecDot(A,B :T3D) :LongInt; external;
procedure VecCross(A,B :T3D; var C :T3D); external;
function VecDistance(A :T3D) :LongInt; external;
function VecLen(A :T3D) :LongInt; external;
procedure VecScalMul(k :LongInt; A :T3D; var C :T3D); external;
procedure VecNormalize(var C :T3D); external;

procedure Zero(var C :TMatrix); external;
procedure Cross(var A,B :TMatrix; var C :TMatrix); external;
procedure Transform(A :T3D; M :TMatrix; var C :T3D); external;
procedure Rotate(rx,ry,rz :Integer; var R :TMatrix); external;
procedure Create(tx,ty,tz, sx,sy,sz :LongInt; rx,ry,rz :Integer; var M :TMatrix); external;
{$L _MATH.OBJ}



procedure Project(A :T3D; var C:T2D);
begin
  C[x] := 160+ (A[x] div (A[z] div $200));
  C[y] := 100- (A[y] div (A[z] div $200));
end;



end.
