OpenGL-Ersatz-Funktionen

Fragen und Bugreports zur PureBasic 4.0-Beta.
DarkDragon
Beiträge: 6267
Registriert: 29.08.2004 08:37
Computerausstattung: Hoffentlich bald keine mehr
Kontaktdaten:

OpenGL-Ersatz-Funktionen

Beitrag von DarkDragon »

Hallo,

Da es viele Fehler gibt, die das Nutzen von glFrustum, glOrtho, gluPerspective, gluOrtho2D unmöglich machen hab ich euch hier ein paar Ersatzfunktionen:

Code: Alles auswählen

Procedure glFrustum(Left.d, Right.d, Bottom.d, Top.d, Near.d, Far.d)
  Protected Dim Frustum_Matrix.d(3, 3)
  Frustum_Matrix(0, 0) = (2.0 * Near)/(Right-Left)
  Frustum_Matrix(1, 1) = (2.0 * Near)/(Top-Bottom)
  Frustum_Matrix(2, 0) = (Right+Left)/(Right-Left)
  Frustum_Matrix(2, 1) = (Top+Bottom)/(Top-Bottom)
  Frustum_Matrix(2, 2) = -1.0 * ((Far+Near)/(Far-Near))
  Frustum_Matrix(3, 2) = -1.0 * ((2.0*Far*Near)/(Far-Near))
  Frustum_Matrix(2, 3) = -1.0
  ProcedureReturn glMultMatrixd_(@Frustum_Matrix(0, 0))
EndProcedure

Procedure gluPerspective(Fov.d, Ratio.d, Near.d, Far.d)
  L_Dummy.f
  Fov = (Fov/180)*3.14159
  Define.d Left, Right, Top, Bottom
  L_Dummy = Tan(Fov*0.5)
  L_Dummy * Near
  Top = L_Dummy
  Bottom = -L_Dummy
  Left = Bottom * Ratio
  Right = Top * Ratio
  ProcedureReturn glFrustum(Left, Right, Bottom, Top, Near, Far)
EndProcedure

Procedure glOrtho(Left.d, Right.d, Bottom.d, Top.d, Near.d, Far.d)
  Protected Dim Ortho_Matrix.d(3, 3)
  Ortho_Matrix(0, 0) =  2.0/(Right-Left  )
  Ortho_Matrix(1, 1) =  2.0/(Top  -Bottom)
  Ortho_Matrix(2, 2) = -2.0/(Far  -Near  )
  Ortho_Matrix(3, 3) = 1.0
  Ortho_Matrix(3, 0) = -1.0*(Right+Left)/(Right-Left)
  Ortho_Matrix(3, 1) = -1.0*(Top+Bottom)/(Top-Bottom)
  Ortho_Matrix(3, 2) = -1.0*(Far+Near  )/(Far-Near  )
  ProcedureReturn glMultMatrixd_(@Ortho_Matrix(0, 0))
EndProcedure

Procedure gluOrtho2D(Left.d, Right.d, Bottom.d, Top.d)
  ProcedureReturn glOrtho(Left.d, Right.d, Bottom.d, Top.d, -1.0, 1.0)
EndProcedure
Angenommen es gäbe einen Algorithmus mit imaginärer Laufzeit O(i * n), dann gilt O((i * n)^2) = O(-1 * n^2) d.h. wenn man diesen Algorithmus verschachtelt ist er fertig, bevor er angefangen hat.