Автор Тема: Чёита??  (Прочитано 812 раз)

0 Пользователей и 1 Гость просматривают эту тему.

Оффлайн T.w.i.$.t Автор темы

  • Завсегдатай
  • ***
  • Сообщений: 275
  • ТрЭшТроЛь
Чёита??
« : Апреля 25, 2012, 13:52:21 »
Цитировать
{
\file      DGLE2_types.h
\author      Korotkov Andrey aka DRON
\version   Beta 2
\date      17.03.2011 (c)Korotkov Andrey

\brief      Engine types definition header.

This header is a part of DGLE2_SDK.

\warning   Don't include this header directly, include "DGLE2.pas" instead.
\see      DGLE2.pas
}

unit DGLE2_types;

interface

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}

uses Windows
{$IF CompilerVersion >= 20}
, Generics.Collections
{$IFEND}
;

const

   //E_ENGINE_WINDOW_FLAGS
      EWF_DEFAULT            = $00000000;//< This flag is suitable in most cases.
      EWF_ALLOW_SIZEING      = $00000001;//< User can resize engine window arbitrarily
      EWF_TOPMOST            = $00000002;//< Engine window will be always on top.
      EWF_DONT_HOOK_MLOOP      = $00000004;//< If flag set and engine doesn't owns window, host applications main loop will not be hooked. User must call window repaint manually.
      EWF_DONT_HOOK_ROOT_WIN   = $00000008;//< If flag set and engine doesn't owns window, main host application window will not be hooked. User must redirect windows messages manually.
      EWF_RESTRICT_ALT_ENTER   = $00000010;//< Switching between fullscreen and windowed modes by pressing "Alt-Enter" will be restricted.
      EWF_RESTRICT_CONSOLE   = $00000020;//< Restricts calling engine console window by pressing "~" key.


type

   TWinHandle   = HWND;
   PByte      = Pointer;
   TEngWindow = packed record
      uiWidth         : Cardinal;
      uiHeight      : Cardinal;
      bFullScreen      : Boolean;
      bVSync         : Boolean;
      uiSamplesCount   : Cardinal;
      stFlags         :{ENG_WINDOW_FLAGS}Integer;
   end;

   TSystemInfo = packed record
      cOSName            : array[0..127] of AnsiChar;
      cCPUName         : array[0..127] of AnsiChar;
      uiCPUCount         : Cardinal;
      uiCPUFreq         : Cardinal;
      uiRAMTotal         : Cardinal;
      uiRAMAvailable      : Cardinal;
      cVideocardName      : array[0..127] of AnsiChar;
      uiVideocardCount   : Cardinal;
      uiVideocardRAM      : Cardinal;
   end;   
   
   TPluginInfo = packed record
      btPluginSDKVersion   : Cardinal;
      cName            : array[0..127] of AnsiChar;
      cVersion         : array[0..64] of AnsiChar;
      cVendor            : array[0..127] of AnsiChar;
      cDiscription      : array[0..256] of AnsiChar;
   end;

   TWinMessage = packed record
      message         : Cardinal;
      wParam         : WPARAM;
      lParam         : LPARAM;
   end;

   TColor4 = packed record
      r, g, b, a : Single;
   end;
   PColor4 = ^TColor4;

   TPoint3 = packed record
      case byte of
         0: (_1D : array[0..2] of Single);
         1: (x, y, z : Single);
   end;
   PPoint3 = ^TPoint3;

   TPoint2 = packed record
      case byte of
         0: (_1D : array[0..1] of Single);
         1: (x, y : Single);
   end;
   PPoint2 = ^TPoint2;

   TVertex2 = packed record
      x, y, u, w, r, g, b, a : Single;
   end;
   PVertex2 = ^TVertex2;

   TVertex3 = packed record
      x, y, z, u, w, r, g, b, a : Single;
   end;
   PVertex3 = ^TVertex3;

   TRectf = packed record
      x, y, width, height : Single;
   end;
   PRectf = ^TRectf;

   TMatrix = packed record
      case byte of
         0: (_1D : array[0..15] of Single);
         1: (_2D : array[0..3, 0..3] of Single);
   end;
   PMatrix = ^TMatrix;

  TTransformStack = class
  private
{$IF CompilerVersion >= 20}
    stack: TStack<TMatrix>;
{$ELSE}
    stack: array of TMatrix;
{$IFEND}
    Constructor Create; overload;
  public
    Constructor Create(const base_transform: TMatrix); overload;
    procedure Push;
    procedure Pop;
    function Top: TMatrix;
    procedure Mult1(const transform: TMatrix);
    procedure Mult2(const transform: TMatrix);
  end;

   TMouseStates = packed record
      iX            : Integer;
      iY            : Integer;
      iDeltaX         : Integer;
      iDeltaY         : Integer;
      iDeltaWheel      : Integer;
      bLeftButton      : Boolean;
      bRightButton   : Boolean;
      bMiddleButton    : Boolean;
   end;

   TKeyboardStates = packed record
      bCapsLock   : Boolean;
      bShiftL      : Boolean;
      bShiftR      : Boolean;
      bCtrlL      : Boolean;
      bCtrlR      : Boolean;
      bAltL      : Boolean;
      bAltR      : Boolean;
   end;

   TJoystickStates = packed record
      iXAxes      : Integer;      // x-axis position
      iYAxes      : Integer;      // y-axis position
      iZAxes      : Integer;      // z-axis position
      iXRotate   : Integer;      // x-axis rotation
      iYRotate   : Integer;      // y-axis rotation
      iZRotate   : Integer;      // z-axis rotation
      iVX         : Integer;      // x-axis velocity
      iVY         : Integer;      // y-axis velocity
      iVZ         : Integer;      // z-axis velocity
      iVXRotate   : Integer;      // x-axis angular velocity
      iVYRotate   : Integer;      // y-axis angular velocity
      iVZRotate   : Integer;      // z-axis angular velocity
      iAX         : Integer;      // x-axis acceleration
      iAY         : Integer;      // y-axis acceleration
      iAZ         : Integer;      // z-axis acceleration
      iAXRotate   : Integer;      // x-axis angular acceleration
      iAYRotate   : Integer;      // y-axis angular acceleration
      iAZRotate   : Integer;      // z-axis angular acceleration
      iFX         : Integer;      // x-axis force
      iFY         : Integer;      // y-axis force
      iFZ         : Integer;      // z-axis force
      iFXRotate   : Integer;      // x-axis torque
      iFYRotate   : Integer;      // y-axis torque
      iFZRotate   : Integer;      // z-axis torque
      iSlider0   : Integer;      // extra axes positions
      iSlider1   : Integer;      //
      iVSlider0   : Integer;      // extra axes velocities
      iVSlider1   : Integer;      //
      iASlider0   : Integer;      // extra axes accelerations
      iASlider1   : Integer;      //
      iFSlider0   : Integer;      // extra axes forces
      iFSlider1   : Integer;      //
      iPOV0      : Integer;      // POV directions
      iPOV1      : Integer;      //
      iPOV2      : Integer;      //
      iPOV3      : Integer;      //
   end;

 const   //E_KEYBOARD_KEY_CODES

   KEY_ESCAPE         = $01;   // Escape
   KEY_TAB            = $0F;   // Tab
   KEY_GRAVE         = $29;   // accent grave "~"
   KEY_CAPSLOCK      = $3A;   // Caps Lock
   KEY_BACKSPACE      = $0E;   // Backspace
   KEY_RETURN         = $1C;   // Enter
   KEY_SPACE         = $39;   // Space
   KEY_SLASH         = $35;   // "/"
   KEY_BACKSLASH      = $2B;   // "\"

   KEY_SYSRQ         = $B7;   // PtrScr (SysRq)
   KEY_SCROLL         = $46;   // Scroll Lock
   KEY_PAUSE         = $C5;   // Pause

   KEY_INSERT         = $D2;   // Insert
   KEY_DELETE         = $D3;   // Delete
   KEY_HOME         = $C7;   // Home
   KEY_END            = $CF;   // End
   KEY_PGUP         = $C9;   // PgUp
   KEY_PGDN         = $D1;   // PgDn

   KEY_LSHIFT         = $2A;   // Left Shift
   KEY_RSHIFT         = $36;   // Right Shift
   KEY_LALT         = $38;   // Left Alt
   KEY_RALT         = $B8;   // Right Alt
   KEY_LWIN         = $DB;   // Left Windows key
   KEY_RWIN         = $DC;   // Right Windows key
   KEY_LCONTROL      = $1D;   // Left Control
   KEY_RCONTROL      = $9D;   // Right Control

   KEY_UP            = $C8;   // UpArrow
   KEY_RIGHT         = $CD;   // RightArrow
   KEY_LEFT         = $CB;   // LeftArrow
   KEY_DOWN         = $D0;   // DownArrow

   KEY_1            = $02;
   KEY_2            = $03;
   KEY_3            = $04;
   KEY_4            = $05;
   KEY_5            = $06;
   KEY_6            = $07;
   KEY_7            = $08;
   KEY_8            = $09;
   KEY_9            = $0A;
   KEY_0            = $0B;

   KEY_F1            = $3B;
   KEY_F2            = $3C;
   KEY_F3            = $3D;
   KEY_F4            = $3E;
   KEY_F5            = $3F;
   KEY_F6            = $40;
   KEY_F7            = $41;
   KEY_F8            = $42;
   KEY_F9            = $43;
   KEY_F10            = $44;
   KEY_F11            = $57;
   KEY_F12            = $58;

   KEY_Q            = $10;
   KEY_W            = $11;
   KEY_E            = $12;
   KEY_R            = $13;
   KEY_T            = $14;
   KEY_Y            = $15;
   KEY_U            = $16;
   KEY_I            = $17;
   KEY_O            = $18;
   KEY_P            = $19;
   KEY_A            = $1E;
   KEY_S            = $1F;
   KEY_D            = $20;
   KEY_F            = $21;
   KEY_G            = $22;
   KEY_H            = $23;
   KEY_J            = $24;
   KEY_K            = $25;
   KEY_L            = $26;
   KEY_Z            = $2C;
   KEY_X            = $2D;
   KEY_C            = $2E;
   KEY_V            = $2F;
   KEY_B            = $30;
   KEY_N            = $31;
   KEY_M            = $32;
   KEY_MINUS         = $0C;   // "-"
   KEY_PLUS         = $0D;   // "+"
   KEY_LBRACKET      = $1A;   // "["
   KEY_RBRACKET      = $1B;   // "]"

   KEY_SEMICOLON      = $27;   // ";"
   KEY_APOSTROPHE      = $28;   // '"'

   KEY_COMMA         = $33;   // ","
   KEY_PERIOD         = $34;   // "."

   KEY_NUMPAD0         = $52;
   KEY_NUMPAD1         = $4F;
   KEY_NUMPAD2         = $50;
   KEY_NUMPAD3         = $51;
   KEY_NUMPAD4         = $4B;
   KEY_NUMPAD5         = $4C;
   KEY_NUMPAD6         = $4D;
   KEY_NUMPAD7         = $47;
   KEY_NUMPAD8         = $48;
   KEY_NUMPAD9         = $49;
   KEY_NUMPADPERIOD   = $53;   // "." on numpad
   KEY_NUMPADENTER      = $9C;   // Enter on numpad
   KEY_NUMPADSTAR      = $37;   // "*" on numpad
   KEY_NUMPADPLUS      = $4E;   // "+" on numpad
   KEY_NUMPADMINUS      = $4A;   // "-" on numpad
   KEY_NUMPADSLASH      = $B5;   // "/" on numpad
   KEY_NUMLOCK         = $45;   // Num Lock on numpad

function Color4f(r,g,b,a: Single): TColor4;
function Color4(r,g,b,a: Byte): TColor4; overload;
function Color4(color : Cardinal; alpha : Byte = 255): TColor4;  overload;
function Color4(): TColor4; overload;
function Point2(): TPoint2; overload;
function Point2(x,y : Single): TPoint2; overload;
function Point3(): TPoint3; overload;
function Point3(x,y,z : Single): TPoint3; overload;
function Vertex2(x,y,u,w,r,g,b,a : Single): TVertex2;
function Vertex3(x,y,z,u,w,r,g,b,a : Single): TVertex3;
function Rectf(x, y, width, height : Single): TRectf;
function IntersectRect(const stRect1, stRect2 : TRectf):Boolean;
function PointInRect(const stPoint : TPoint2; const stRect : TRectf):Boolean;
function Matrix(): TMatrix;
function MatrixMulGL(stMLeft, stMRight : TMatrix): TMatrix;
function MatrixInverce(const stMatrix : TMatrix): TMatrix;
function MatrixTranspose(const stMatrix : TMatrix): TMatrix;
function MatrixIdentity(): TMatrix;
function MatrixScale(const fVec : TPoint3): TMatrix;
function MatrixTranslate(const fVec : TPoint3): TMatrix;
function MatrixRotate(angle : Single; const fAxis : TPoint3): TMatrix;
function MatrixBillboard(const stMatrix : TMatrix): TMatrix;
function EngWindow(): TEngWindow; overload;
function EngWindow(uiWidth, uiHeight : Integer; bFullScreen : Boolean; bVSync : Boolean = false; uiSamplesCount : Cardinal = 1; stFlags :{ENG_WINDOW_FLAGS}Integer = EWF_DEFAULT): TEngWindow; overload;
function MatrixSub(stLeftMatrix, stRightMatrix : TMatrix): TMatrix; overload;
function MatrixAdd(stLeftMatrix, stRightMatrix : TMatrix): TMatrix; overload;
function MatrixMul(stLeftMatrix, stRightMatrix : TMatrix): TMatrix; overload;
function MatrixSub(stLeftMatrix: TMatrix; right: Single): TMatrix; overload;
function MatrixAdd(stLeftMatrix: TMatrix; right: Single): TMatrix; overload;
function MatrixDiv(stLeftMatrix: TMatrix; right: Single): TMatrix; overload;
function MatrixMul(stLeftMatrix: TMatrix; right: Single): TMatrix; overload;

implementation

function Color4f(r,g,b,a: Single): TColor4;
begin
   Result.r := r;
   Result.g := g;
   Result.b := b;
   Result.a := a;
end;

function Color4(r,g,b,a: Byte): TColor4; overload;
begin
   Result.r := r/255.;
   Result.g := g/255.;
   Result.b := b/255.;
   Result.a := a/255.;
end;

function Color4(color : Cardinal; alpha : Byte = 255): TColor4; overload;
begin
   Result.r := Byte(color shr 16)/255.;
   Result.g := Byte(color shr 8)/255.;
   Result.b := Byte(color)/255.;
   Result.a := alpha/255.;
end;

function Color4(): TColor4; overload;
begin
   Result.r := 1.;
   Result.g := 1.;
   Result.b := 1.;
   Result.a := 1.;
end;

function Point2(): TPoint2; overload;
begin
   Result.x := 0.;
   Result.y := 0.;
end;

function Point2(x,y : Single): TPoint2; overload;
begin
   Result.x := x;
   Result.y := y;
end;

function Point3(): TPoint3; overload;
begin
   Result.x := 0.;
   Result.y := 0.;
   Result.z := 0.;
end;

function Point3(x,y,z : Single): TPoint3; overload;
begin
   Result.x := x;
   Result.y := y;
   Result.z := z;
end;

function Vertex2(x,y,u,w,r,g,b,a : Single): TVertex2;
begin
   Result.x := x;
   Result.y := y;
   Result.u := u;
   Result.w := w;
   Result.r := r;
   Result.g := g;
   Result.b := b;
   Result.a := a;
end;

function Vertex3(x,y,z,u,w,r,g,b,a : Single): TVertex3;
begin
   Result.x := x;
   Result.y := y;
   Result.z := z;
   Result.u := u;
   Result.w := w;
   Result.r := r;
   Result.g := g;
   Result.b := b;
   Result.a := a;
end;

function Rectf(x, y, width, height : Single): TRectf;
begin
   Result.x      := x;
   Result.y      := y;
   Result.width   := width;
   Result.height   := height;
end;

function IntersectRect(const stRect1, stRect2 : TRectf):Boolean;
begin
   Result :=   ((stRect1.x < stRect2.x + stRect2.width) and (stRect1.x + stRect1.width > stRect2.x) and (stRect1.y < stRect2.y + stRect2.height) and (stRect1.y + stRect1.height > stRect2.y))or
            ((stRect2.x + stRect2.width < stRect1.x) and (stRect2.x > stRect1.x + stRect1.width) and (stRect2.y + stRect2.height < stRect1.y) and (stRect2.y > stRect1.y + stRect1.height));
end;

function PointInRect(const stPoint : TPoint2; const stRect : TRectf):Boolean;
begin
   Result := (stPoint.x > stRect.x) and (stPoint.x < stRect.x + stRect.width) and (stPoint.y > stRect.y) and (stPoint.y < stRect.y + stRect.height);
end;

function Matrix(): TMatrix;
begin
   ZeroMemory(@Result._1D, 16 * SizeOf(Single));
end;

function MatrixMulGL(stMLeft, stMRight : TMatrix): TMatrix;
begin
   result := MatrixMul(stMRight, stMLeft);
end;

function MatrixInverce(const stMatrix : TMatrix): TMatrix;
type   MatrixRows = array[0..7] of Single;
      PMatrixRows = ^MatrixRows;
var      mat : array[0..3] of MatrixRows;
      rows : array[0..3] of PMatrixRows;
      i, r, row_num, c : Integer;
      major, cur_ABS, factor : Single;
begin
   mat[0, 0] := stMatrix._2D[0][0];
   mat[0, 1] := stMatrix._2D[0][1];
   mat[0, 2] := stMatrix._2D[0][2];
   mat[0, 3] := stMatrix._2D[0][3];
   mat[0, 4] := 1.0;
   mat[0, 5] := 0.0;
   mat[0, 6] := 0.0;
   mat[0, 7] := 0.0;

   mat[1, 0] := stMatrix._2D[1][0];
   mat[1, 1] := stMatrix._2D[1][1];
   mat[1, 2] := stMatrix._2D[1][2];
   mat[1, 3] := stMatrix._2D[1][3];
   mat[1, 4] := 0.0;
   mat[1, 5] := 1.0;
   mat[1, 6] := 0.0;
   mat[1, 7] := 0.0;

   mat[2, 0] := stMatrix._2D[2][0];
   mat[2, 1] := stMatrix._2D[2][1];
   mat[2, 2] := stMatrix._2D[2][2];
   mat[2, 3] := stMatrix._2D[2][3];
   mat[2, 4] := 0.0;
   mat[2, 5] := 0.0;
   mat[2, 6] := 1.0;
   mat[2, 7] := 0.0;

   mat[3, 0] := stMatrix._2D[3][0];
   mat[3, 1] := stMatrix._2D[3][1];
   mat[3, 2] := stMatrix._2D[3][2];
   mat[3, 3] := stMatrix._2D[3][3];
   mat[3, 4] := 0.0;
   mat[3, 5] := 0.0;
   mat[3, 6] := 0.0;
   mat[3, 7] := 1.0;

   rows[0] := PMatrixRows(@mat[0]);
   rows[1] := PMatrixRows(@mat[1]);
   rows[2] := PMatrixRows(@mat[2]);
   rows[3] := PMatrixRows(@mat[3]);


   for i := 0 to 3 do
   begin
      row_num := i;
      major := Abs(rows[i, i]);
      for r := i + 1 to 3 do
      begin
         cur_ABS := Abs(rows[r, i]);
         if cur_ABS > major then
         begin
            major := cur_ABS;
            row_num := r;
         end;
      end;
      if row_num <> i then
      begin
         rows       := Pointer(Integer(rows) xor Integer(rows[row_num]));
         rows[row_num]   := Pointer(Integer(rows) xor Integer(rows[row_num]));
         rows       := Pointer(Integer(rows) xor Integer(rows[row_num]));
      end;
      for r := i + 1 to 3 do
      begin
         factor := rows[r, i] / rows[i, i];
         for c := i to 7 do rows[r, c] := rows[r, c] - factor * rows[i, c];
      end;
   end;

   for i := 3 downto 1 do
      for r := 0 to i - 1 do
      begin
         factor := rows[r, i] / rows[i, i];
         for c := 4 to 7 do rows[r, c] := rows[r, c] - factor * rows[i, c];
      end;

   Result._2D[0, 0] := rows[0, 4] / rows[0, 0];
   Result._2D[0, 1] := rows[0, 5] / rows[0, 0];
   Result._2D[0, 2] := rows[0, 6] / rows[0, 0];
   Result._2D[0, 3] := rows[0, 7] / rows[0, 0];

   Result._2D[1, 0] := rows[1, 4] / rows[1, 1];
   Result._2D[1, 1] := rows[1, 5] / rows[1, 1];
   Result._2D[1, 2] := rows[1, 6] / rows[1, 1];
   Result._2D[1, 3] := rows[1, 7] / rows[1, 1];

   Result._2D[2, 0] := rows[2, 4] / rows[2, 2];
   Result._2D[2, 1] := rows[2, 5] / rows[2, 2];
   Result._2D[2, 2] := rows[2, 6] / rows[2, 2];
   Result._2D[2, 3] := rows[2, 7] / rows[2, 2];

   Result._2D[3, 0] := rows[3, 4] / rows[3, 3];
   Result._2D[3, 1] := rows[3, 5] / rows[3, 3];
   Result._2D[3, 2] := rows[3, 6] / rows[3, 3];
   Result._2D[3, 3] := rows[3, 7] / rows[3, 3];
end;

function MatrixTranspose(const stMatrix : TMatrix): TMatrix;
begin
   Result._2D[0, 0] := stMatrix._2D[0, 0];
   Result._2D[0, 1] := stMatrix._2D[1, 0];
   Result._2D[0, 2] := stMatrix._2D[2, 0];
   Result._2D[0, 3] := stMatrix._2D[3, 0];

   Result._2D[1, 0] := stMatrix._2D[0, 1];
   Result._2D[1, 1] := stMatrix._2D[1, 1];
   Result._2D[1, 2] := stMatrix._2D[2, 1];
   Result._2D[1, 3] := stMatrix._2D[3, 1];

   Result._2D[2, 0] := stMatrix._2D[0, 2];
   Result._2D[2, 1] := stMatrix._2D[1, 2];
   Result._2D[2, 2] := stMatrix._2D[2, 2];
   Result._2D[2, 3] := stMatrix._2D[3, 2];

   Result._2D[3, 0] := stMatrix._2D[0, 3];
   Result._2D[3, 1] := stMatrix._2D[1, 3];
   Result._2D[3, 2] := stMatrix._2D[2, 3];
   Result._2D[3, 3] := stMatrix._2D[3, 3];
end;

function MatrixIdentity(): TMatrix;
begin
   Result := MatrixScale(Point3(1.0,1.0,1.0));
end;

function MatrixScale(const fVec : TPoint3): TMatrix; overload;
begin
   Result._2D[0, 0] := fVec.x;
   Result._2D[0, 1] := 0.0;
   Result._2D[0, 2] := 0.0;
   Result._2D[0, 3] := 0.0;

   Result._2D[1, 0] := 0.0;
   Result._2D[1, 1] := fVec.y;
   Result._2D[1, 2] := 0.0;
   Result._2D[1, 3] := 0.0;

   Result._2D[2, 0] := 0.0;
   Result._2D[2, 1] := 0.0;
   Result._2D[2, 2] := fVec.z;
   Result._2D[2, 3] := 0.0;

   Result._2D[3, 0] := 0.0;
   Result._2D[3, 1] := 0.0;
   Result._2D[3, 2] := 0.0;
   Result._2D[3, 3] := 1.0;
end;

function MatrixTranslate(const fVec : TPoint3): TMatrix;
begin
   Result := MatrixIdentity();
   Result._1D[12] := fVec.x;
   Result._1D[13] := fVec.y;
   Result._1D[14] := fVec.z;
end;

function MatrixRotate(angle : Single; const fAxis : TPoint3): TMatrix;
var axis_norm, x, y, z, sin_angle, cos_angle : Single;
begin
   axis_norm := sqrt(fAxis.x * fAxis.x + fAxis.y * fAxis.y + fAxis.z * fAxis.z);
   x := fAxis.x / axis_norm;
   y := fAxis.y / axis_norm;
   z := fAxis.z / axis_norm;
   sin_angle := sin(angle*Pi/180.0);
   cos_angle := cos(angle*Pi/180.0);

   Result._2D[0][0] := (1.0 - x * x) * cos_angle + x * x;
   Result._2D[0][1] := z * sin_angle + x * y * (1.0 - cos_angle);
   Result._2D[0][2] := x * z * (1.0 - cos_angle) - y * sin_angle;
   Result._2D[0][3] := 0.0;

   Result._2D[1][0] := x * y * (1.0 - cos_angle) - z * sin_angle;
   Result._2D[1][1] := (1.0 - y * y) * cos_angle + y * y;
   Result._2D[1][2] := y * z * (1.0 - cos_angle) + x * sin_angle;
   Result._2D[1][3] := 0.0;

   Result._2D[2][0] := x * z * (1.0 - cos_angle) + y * sin_angle;
   Result._2D[2][1] := y * z * (1.0 - cos_angle) - x * sin_angle;
   Result._2D[2][2] := (1.0 - z * z) * cos_angle + z * z;
   Result._2D[2][3] := 0.0;

   Result._2D[3][0] := 0.0;
   Result._2D[3][1] := 0.0;
   Result._2D[3][2] := 0.0;
   Result._2D[3][3] := 1.0;
end;

function MatrixBillboard(const stMatrix : TMatrix): TMatrix;
begin
   Result := MatrixIdentity();
   Result._2D[3, 0] := stMatrix._2D[3, 0];
   Result._2D[3, 1] := stMatrix._2D[3, 1];
   Result._2D[3, 2] := stMatrix._2D[3, 2];
   Result._2D[0, 3] := stMatrix._2D[0, 3];
   Result._2D[1, 3] := stMatrix._2D[1, 3];
   Result._2D[2, 3] := stMatrix._2D[2, 3];
   Result._2D[3, 3] := stMatrix._2D[3, 3];
end;

function MatrixSub(stLeftMatrix, stRightMatrix : TMatrix): TMatrix;
var i: Integer;
begin
   Result := MatrixIdentity();
   for i := 0 to 15 do
   begin
      Result._1D := stLeftMatrix._1D - stRightMatrix._1D;
   end;
end;

function MatrixAdd(stLeftMatrix, stRightMatrix : TMatrix): TMatrix;
var i: Integer;
begin
   Result := MatrixIdentity();
   for i := 0 to 15 do
   begin
      Result._1D := stLeftMatrix._1D + stRightMatrix._1D;
   end;
end;

function MatrixMul(stLeftMatrix, stRightMatrix : TMatrix): TMatrix;
var i,j,k: Integer;
begin
   Result := Matrix;
   for i := 0 to 3 do
      for j := 0 to 3 do
         for k := 0 to 3 do
                Result._2D[j] := Result._2D[j] + stLeftMatrix._2D[k] * stRightMatrix._2D[k][j];
end;

function MatrixSub(stLeftMatrix: TMatrix; right: Single): TMatrix;
var i: Integer;
begin
   Result := MatrixIdentity();
   for i := 0 to 15 do
   begin
      Result._1D := stLeftMatrix._1D - right;
   end;
end;

function MatrixAdd(stLeftMatrix: TMatrix; right: Single): TMatrix;
var i: Integer;
begin
   Result := MatrixIdentity();
   for i := 0 to 15 do
   begin
      Result._1D := stLeftMatrix._1D + right;
   end;
end;

function MatrixDiv(stLeftMatrix: TMatrix; right: Single): TMatrix;
var i: Integer;
begin
   Result := MatrixIdentity();
   for i := 0 to 15 do
   begin
      Result._1D := stLeftMatrix._1D / right;
   end;
end;

function MatrixMul(stLeftMatrix: TMatrix; right: Single): TMatrix;
var i: Integer;
begin
   Result := MatrixIdentity();
   for i := 0 to 15 do
   begin
      Result._1D := stLeftMatrix._1D * right;
   end;
end;

{$IF CompilerVersion >= 20}

constructor TTransformStack.Create;
begin
   inherited;
   stack := TStack<TMatrix>.Create();
end;

constructor TTransformStack.Create(const base_transform: TMatrix);
begin
   Create;
   stack.Push(base_transform);
end;

procedure TTransformStack.Push;
begin
   stack.Push(stack.Peek());
end;

procedure TTransformStack.Pop;
begin
if stack.Count > 1 then
   stack.Pop();
end;

function TTransformStack.Top: TMatrix;
begin
    Result := stack.Peek();
end;

procedure TTransformStack.Mult1(const transform: TMatrix);
begin
   stack.Push(MatrixMul(stack.Pop, transform));
end;

procedure TTransformStack.Mult2(const transform: TMatrix);
begin
   stack.Push(MatrixMul(transform, stack.Pop));
end;

{$ELSE}

constructor TTransformStack.Create;
begin
   inherited;
    SetLength(stack, 0);
end;

constructor TTransformStack.Create(const base_transform: TMatrix);
begin
   Create;
   SetLength(stack, 1);
   stack[0] := base_transform;
end;

procedure TTransformStack.Mult1(const transform: TMatrix);
begin
   stack[High(stack)] := MatrixMul(stack[High(stack)], transform);
end;

procedure TTransformStack.Mult2(const transform: TMatrix);
begin
   stack[High(stack)] := MatrixMul(transform, stack[High(stack)]);
end;

procedure TTransformStack.Pop;
begin
if(Length(stack) > 1)
   SetLength(stack, Length(stack) - 1);
end;

procedure TTransformStack.Push;
begin
   SetLength(stack, Length(stack) + 1);
   stack[High(stack)] := stack[High(stack) - 1];
end;

function TTransformStack.Top: TMatrix;
begin
   Result := stack[High(stack)];
end;

{$IFEND}

function EngWindow(): TEngWindow; overload;
begin
   Result.uiWidth         := 800;
   Result.uiHeight         := 600;
   Result.bFullScreen      := false;
   Result.bVSync         := false;
   Result.uiSamplesCount   := 1;
   Result.stFlags         := EWF_DEFAULT;
end;

function EngWindow(uiWidth, uiHeight : Integer; bFullScreen : Boolean; bVSync : Boolean = false; uiSamplesCount : Cardinal = 1; stFlags :{ENG_WINDOW_FLAGS}Integer = EWF_DEFAULT): TEngWindow; overload;
begin
   Result.uiWidth         := uiWidth;
   Result.uiHeight         := uiHeight;
   Result.bFullScreen      := bFullScreen;
   Result.bVSync         := bVSync;
   Result.uiSamplesCount   := uiSamplesCount;
   Result.stFlags         := stFlags;
end;

begin
end.

в выделеном месте ругаеться!!! в чем проблема??

Оффлайн akl

  • Живу на форуме
  • *******
  • Сообщений: 8114
  • не шарю ваще
Re: Чёита??
« Ответ #1 : Апреля 25, 2012, 13:54:26 »
это матрица
 :neo:

Оффлайн T.w.i.$.t Автор темы

  • Завсегдатай
  • ***
  • Сообщений: 275
  • ТрЭшТроЛь
Re: Чёита??
« Ответ #2 : Апреля 26, 2012, 10:59:03 »
чё нет программеров? :o

Оффлайн eViLL

  • Завсегдатай
  • ***
  • Сообщений: 406
Re: Чёита??
« Ответ #3 : Апреля 26, 2012, 11:39:01 »
Цитировать
Length(stack) - 1
попробуй присвоить переменной и эту переменную в
Цитировать
SetLength
подсовывать.
хотя на самом деле

Оффлайн Surch

  • Меценат
  • *****
  • Сообщений: 755
Re: Чёита??
« Ответ #4 : Апреля 26, 2012, 11:42:20 »
Цитировать
неправильно набрана команда запуска
попробуйте ещё разок
Из ответа советских эвм неумелым студентам :hmmm:

Оффлайн Gladiatorrr

  • Ветеран форума
  • ******
  • Сообщений: 6337
  • Иди, побюнгай.
Re: Чёита??
« Ответ #5 : Апреля 26, 2012, 11:57:43 »
Мне понравился смайлик в середине кода, вот этот  8)

Оффлайн akl

  • Живу на форуме
  • *******
  • Сообщений: 8114
  • не шарю ваще
Re: Чёита??
« Ответ #6 : Апреля 26, 2012, 15:59:56 »
это что, цвет № 8 так через электронный мозг ГП преломился? :D

Оффлайн Marv1n

  • Завсегдатай
  • ***
  • Сообщений: 380
Re: Чёита??
« Ответ #7 : Апреля 26, 2012, 16:50:56 »
Ты там деепричастие запятыми не выделил