Page 1 of 1

glFrustum selfmade?! [solved]

Posted: Tue Aug 23, 2005 7:55 pm
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

Posted: Wed Aug 24, 2005 9:56 am
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)
:?:

Posted: Wed Aug 24, 2005 10:40 am
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.

Posted: Wed Aug 24, 2005 3:44 pm
by Franky
Better

Code: Select all

Dim Frustum_Matrix.f(3, 3) 
instead of

Code: Select all

Dim Frustum_Matrix.f(4, 4) 
;)

Posted: Wed Aug 24, 2005 3:55 pm
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.