Ignore:
Timestamp:
Dec 22, 2016, 8:49:19 PM (7 years ago)
Author:
chronos
Message:
  • Modified: Updated BGRABitmap package.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/Packages/bgrabitmap/bgramatrix3d.pas

    r472 r494  
    44
    55{$i bgrasse.inc}
    6 {$ifdef BGRASSE_AVAILABLE}
     6
     7{$ifdef CPUI386}
    78  {$asmmode intel}
    8 {$endif}
     9{$ENDIF}
     10{$ifdef cpux86_64}
     11  {$asmmode intel}
     12{$ENDIF}
    913
    1014interface
    1115
    1216uses
    13   BGRABitmapTypes, BGRASSE;
     17  BGRABitmapTypes, BGRASSE,
     18  BGRATransform;
    1419
    1520type
    1621  TMatrix3D = packed array[1..3,1..4] of single;
     22  TMatrix4D = packed array[1..4,1..4] of single;
    1723  TProjection3D = packed record
    1824    Zoom, Center: TPointF;
    1925  end;
     26  TComputeProjectionFunc = function(AViewCoord: TPoint3D_128): TPointF of object;
    2027
    2128operator*(const A: TMatrix3D; const M: TPoint3D): TPoint3D;
     
    3542function MatrixRotateZ(angle: single): TMatrix3D;
    3643
     44operator *(const A, B: TMatrix4D): TMatrix4D;
     45function MatrixIdentity4D: TMatrix4D;
     46function AffineMatrixToMatrix4D(AValue: TAffineMatrix): TMatrix4D;
     47
    3748{$IFDEF BGRASSE_AVAILABLE}
    3849procedure Matrix3D_SSE_Load(const A: TMatrix3D);
     
    4556implementation
    4657
    47 procedure multiplyVectInline(const A : TMatrix3D; const vx,vy,vz,vt: single; out outx,outy,outz: single);
     58procedure multiplyVect3(const A : TMatrix3D; const vx,vy,vz,vt: single; out outx,outy,outz: single);
    4859begin
    4960  outx := vx * A[1,1] + vy * A[1,2] + vz * A[1,3] + vt * A[1,4];
     
    5263end;
    5364
     65procedure multiplyVect4(const A : TMatrix4D; const vx,vy,vz,vt: single; out outx,outy,outz,outt: single);
     66begin
     67  outx := vx * A[1,1] + vy * A[1,2] + vz * A[1,3] + vt * A[1,4];
     68  outy := vx * A[2,1] + vy * A[2,2] + vz * A[2,3] + vt * A[2,4];
     69  outz := vx * A[3,1] + vy * A[3,2] + vz * A[3,3] + vt * A[3,4];
     70  outt := vx * A[4,1] + vy * A[4,2] + vz * A[4,3] + vt * A[4,4];
     71end;
     72
    5473operator*(const A: TMatrix3D; const M: TPoint3D): TPoint3D;
    5574begin
     
    5776  result.y := M.x * A[2,1] + M.y * A[2,2] + M.z * A[2,3] + A[2,4];
    5877  result.z := M.x * A[3,1] + M.y * A[3,2] + M.z * A[3,3] + A[3,4];
     78end;
     79
     80operator*(const A, B: TMatrix4D): TMatrix4D;
     81begin
     82  multiplyVect4(A, B[1,1],B[2,1],B[3,1],B[4,1], result[1,1],result[2,1],result[3,1],result[4,1]);
     83  multiplyVect4(A, B[1,2],B[2,2],B[3,2],B[4,2], result[1,2],result[2,2],result[3,2],result[4,2]);
     84  multiplyVect4(A, B[1,3],B[2,3],B[3,3],B[4,3], result[1,3],result[2,3],result[3,3],result[4,3]);
     85  multiplyVect4(A, B[1,4],B[2,4],B[3,4],B[4,4], result[1,4],result[2,4],result[3,4],result[4,4]);
     86end;
     87
     88function MatrixIdentity4D: TMatrix4D;
     89begin
     90  result[1,1] := 1;  result[2,1] := 0;  result[3,1] := 0; result[4,1] := 0;
     91  result[1,2] := 0;  result[2,2] := 1;  result[3,2] := 0; result[4,2] := 0;
     92  result[1,3] := 0;  result[2,3] := 0;  result[3,3] := 1; result[4,3] := 0;
     93  result[1,4] := 0;  result[2,4] := 0;  result[3,4] := 0; result[4,4] := 1;
     94end;
     95
     96function AffineMatrixToMatrix4D(AValue: TAffineMatrix): TMatrix4D;
     97begin
     98  result[1,1] := AValue[1,1];  result[2,1] := AValue[1,2];  result[3,1] := 0; result[4,1] := AValue[1,3];
     99  result[1,2] := AValue[2,1];  result[2,2] := AValue[2,2];  result[3,2] := 0; result[4,2] := AValue[2,3];
     100  result[1,3] := 0;            result[2,3] := 0;            result[3,3] := 1; result[4,3] := 0;
     101  result[1,4] := 0;            result[2,4] := 0;            result[3,4] := 0; result[4,4] := 1;
    59102end;
    60103
     
    391434
    392435operator*(constref A: TMatrix3D; var M: TPoint3D_128): TPoint3D_128;
    393 {$IFDEF CPUI386}var oldMt: single; {$ENDIF}
    394 begin
    395   {$IFDEF CPUI386}
     436{$IFDEF BGRASSE_AVAILABLE}var oldMt: single; {$ENDIF}
     437begin
     438  {$IFDEF BGRASSE_AVAILABLE}
    396439  if UseSSE then
    397440  begin
     
    490533function MultiplyVect3DWithoutTranslation(constref A: TMatrix3D; constref M: TPoint3D_128): TPoint3D_128;
    491534begin
    492   {$IFDEF CPUI386}
     535  {$IFDEF BGRASSE_AVAILABLE}
    493536  if UseSSE then
    494537  begin
     
    583626operator*(A,B: TMatrix3D): TMatrix3D;
    584627begin
    585   multiplyVectInline(A, B[1,1],B[2,1],B[3,1],0, result[1,1],result[2,1],result[3,1]);
    586   multiplyVectInline(A, B[1,2],B[2,2],B[3,2],0, result[1,2],result[2,2],result[3,2]);
    587   multiplyVectInline(A, B[1,3],B[2,3],B[3,3],0, result[1,3],result[2,3],result[3,3]);
    588   multiplyVectInline(A, B[1,4],B[2,4],B[3,4],1, result[1,4],result[2,4],result[3,4]);
     628  multiplyVect3(A, B[1,1],B[2,1],B[3,1],0, result[1,1],result[2,1],result[3,1]);
     629  multiplyVect3(A, B[1,2],B[2,2],B[3,2],0, result[1,2],result[2,2],result[3,2]);
     630  multiplyVect3(A, B[1,3],B[2,3],B[3,3],0, result[1,3],result[2,3],result[3,3]);
     631  multiplyVect3(A, B[1,4],B[2,4],B[3,4],1, result[1,4],result[2,4],result[3,4]);
    589632end;
    590633
Note: See TracChangeset for help on using the changeset viewer.