glFrustum selfmade?! [solved]

Advanced game related topics
DarkDragon
Addict
Addict
Posts: 2348
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

glFrustum selfmade?! [solved]

Post by DarkDragon »

Hello,

Well I've searched google and the forums for an answer, but I didn't get an answer. In the MSDN/OpenGL Platform SDK Help I saw that it is multiplying the Projection Matrix with this one:

Image
f = zFar
n = zNear
l = left
r = right
t = top
b = bottom

Ok, I've done so:

Code: Select all

Procedure glFrustum(Left.f, Right.f, Bottom.f, Top.f, Near.f, Far.f)
  Dim Frustum_Matrix.f(4, 4)
  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 * ((Far+Near)/(Far-Near))
  Frustum_Matrix(3, 2) = -1 * ((2.0*Far*Near)/(Far-Near))
  Frustum_Matrix(2, 3) = -1.0
  glMultMatrixf_(@Frustum_Matrix(0, 0))
EndProcedure
But the matrix doesn't seem to be the same as I get from the real glFrustum(needs glWrapper):

Code: Select all

Procedure glFrustum(Left.f, Right.f, Bottom.f, Top.f, Near.f, Far.f)
  Dim Frustum_Matrix.f(4, 4)
  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 * ((Far+Near)/(Far-Near))
  Frustum_Matrix(3, 2) = -1 * ((2.0*Far*Near)/(Far-Near))
  Frustum_Matrix(2, 3) = -1.0
  glMultMatrixf_(@Frustum_Matrix(0, 0))
  Text.s = "The matrix we calculated:"+#LF$
  Text.s + "("+StrF(Frustum_Matrix(0, 0), 2)+", "+StrF(Frustum_Matrix(1, 0), 2)+", "+StrF(Frustum_Matrix(2, 0), 2)+", "+StrF(Frustum_Matrix(3, 0), 2)+")" + #LF$
  Text.s + "("+StrF(Frustum_Matrix(0, 1), 2)+", "+StrF(Frustum_Matrix(1, 1), 2)+", "+StrF(Frustum_Matrix(2, 1), 2)+", "+StrF(Frustum_Matrix(3, 1), 2)+")" + #LF$
  Text.s + "("+StrF(Frustum_Matrix(0, 2), 2)+", "+StrF(Frustum_Matrix(1, 2), 2)+", "+StrF(Frustum_Matrix(2, 2), 2)+", "+StrF(Frustum_Matrix(3, 2), 2)+")" + #LF$
  Text.s + "("+StrF(Frustum_Matrix(0, 3), 2)+", "+StrF(Frustum_Matrix(1, 3), 2)+", "+StrF(Frustum_Matrix(2, 3), 2)+", "+StrF(Frustum_Matrix(3, 3), 2)+")" + #LF$ + #LF$
  glGetFloatv_(#GL_PROJECTION_MATRIX, @Frustum_Matrix(0, 0))
  Text.s + "The matrix multiplied with the current projection matrix:"+#LF$
  Text.s + "("+StrF(Frustum_Matrix(0, 0), 2)+", "+StrF(Frustum_Matrix(1, 0), 2)+", "+StrF(Frustum_Matrix(2, 0), 2)+", "+StrF(Frustum_Matrix(3, 0), 2)+")" + #LF$
  Text.s + "("+StrF(Frustum_Matrix(0, 1), 2)+", "+StrF(Frustum_Matrix(1, 1), 2)+", "+StrF(Frustum_Matrix(2, 1), 2)+", "+StrF(Frustum_Matrix(3, 1), 2)+")" + #LF$
  Text.s + "("+StrF(Frustum_Matrix(0, 2), 2)+", "+StrF(Frustum_Matrix(1, 2), 2)+", "+StrF(Frustum_Matrix(2, 2), 2)+", "+StrF(Frustum_Matrix(3, 2), 2)+")" + #LF$
  Text.s + "("+StrF(Frustum_Matrix(0, 3), 2)+", "+StrF(Frustum_Matrix(1, 3), 2)+", "+StrF(Frustum_Matrix(2, 3), 2)+", "+StrF(Frustum_Matrix(3, 3), 2)+")" + #LF$ + #LF$
  glLoadIdentity_()
  glFrustum__(Left, Right, Bottom, Top, Near, Far)
  glGetFloatv_(#GL_PROJECTION_MATRIX, @Frustum_Matrix(0, 0))
  Text.s + "The matrix we get from the real glFrustum:"+#LF$
  Text.s + "("+StrF(Frustum_Matrix(0, 0), 2)+", "+StrF(Frustum_Matrix(1, 0), 2)+", "+StrF(Frustum_Matrix(2, 0), 2)+", "+StrF(Frustum_Matrix(3, 0), 2)+")" + #LF$
  Text.s + "("+StrF(Frustum_Matrix(0, 1), 2)+", "+StrF(Frustum_Matrix(1, 1), 2)+", "+StrF(Frustum_Matrix(2, 1), 2)+", "+StrF(Frustum_Matrix(3, 1), 2)+")" + #LF$
  Text.s + "("+StrF(Frustum_Matrix(0, 2), 2)+", "+StrF(Frustum_Matrix(1, 2), 2)+", "+StrF(Frustum_Matrix(2, 2), 2)+", "+StrF(Frustum_Matrix(3, 2), 2)+")" + #LF$
  Text.s + "("+StrF(Frustum_Matrix(0, 3), 2)+", "+StrF(Frustum_Matrix(1, 3), 2)+", "+StrF(Frustum_Matrix(2, 3), 2)+", "+StrF(Frustum_Matrix(3, 3), 2)+")" + #LF$ + #LF$
  MessageRequester("", Text)
EndProcedure
:roll: Thanks for any help on this. The reason why I try to get this work: linux. I don't know how to convert floats to double in c or asm and I don't know how to compile a userlib with linux's compilers. And anyway it would be interessting to see how this works.

[EDIT]
Problem fixed.
Correct code:

Code: Select all

Procedure glFrustum(Left.f, Right.f, Bottom.f, Top.f, Near.f, Far.f)
  Dim Frustum_Matrix.f(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
  glMultMatrixf_(@Frustum_Matrix(0, 0))
EndProcedure
Last edited by DarkDragon on Wed Aug 24, 2005 3:46 pm, edited 2 times in total.
bye,
Daniel
User avatar
HeX0R
Addict
Addict
Posts: 1226
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Post by HeX0R »

I have totally no idea about all of this 3D-things, but shouldn't this:

Code: Select all

Frustum_Matrix(1, 2) = (Top+Bottom)/(Top-Bottom)
be

Code: Select all

Frustum_Matrix(1, 2) = (Top+Bottom)/(Top-Near)
:?:
DarkDragon
Addict
Addict
Posts: 2348
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

HeX0R wrote:I have totally no idea about all of this 3D-things, but shouldn't this:

Code: Select all

Frustum_Matrix(1, 2) = (Top+Bottom)/(Top-Bottom)
be

Code: Select all

Frustum_Matrix(1, 2) = (Top+Bottom)/(Top-Near)
:?:
Well I've corrected the array a bit(the code I gave you was a bit changed when I experimented with it), but what is wrong now the DGL Wiki or the OpenGL Platform SDK? In the OpenGL Platform SDK is it -Left and in DGL Wiki is with -Near.

[EDIT]
Problem solved: (4, 4) at the definition has to be (3, 3) that can happen if you are programming such things late at the evening.
Last edited by DarkDragon on Wed Aug 24, 2005 3:45 pm, edited 1 time in total.
bye,
Daniel
Franky
Enthusiast
Enthusiast
Posts: 213
Joined: Sat Apr 26, 2003 2:58 pm

Post by Franky »

Better

Code: Select all

Dim Frustum_Matrix.f(3, 3) 
instead of

Code: Select all

Dim Frustum_Matrix.f(4, 4) 
;)
Give Up everything but trying!
DarkDragon
Addict
Addict
Posts: 2348
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

Franky wrote:Better

Code: Select all

Dim Frustum_Matrix.f(3, 3) 
instead of

Code: Select all

Dim Frustum_Matrix.f(4, 4) 
;)
Yes, thanks for the help.
bye,
Daniel
Post Reply