PDA

View Full Version : glClipPlane problem in VB



djavan
01-17-2003, 06:12 PM
Hi All!
I have a simple 3D-Plotting program (in VB) that draws 3 rectangles on X-Y, X-Z and Y-Z Planes respectively (Their corner cordinates are:
X-Y Rectangle: (0,0,0) - (10,20,0)
X-Z Rectangle: (0,0,0) - (10,0,10)
Y-Z Rectangle: (0,10,0) - (0,20,20)
(The point-coordinates and rectangle-connections are given via an Input-File)

In this program, I'm also doing XYZ-Rotation based on User-Input for which I am using glLookAt. Moreover, I am drawing a little XYZ-Axis on the bottom-left corner of the screen two show the current "rotation".
the SIMPLIFIED CODE of the PlotGraph subroutine which does the drawing is as follows:


Public Sub PlotGraph()
Dim W(3, 2) As Single
Dim p(2) As Single
Dim X, Y, Z As Single
Dim i, j, k, m As Integer
Dim A() As Byte
Dim s As String

'*****************************
' Setup the Clipping Equations
'*****************************
Dim xClip(3) As GLdouble
Dim yClip(3) As GLdouble
Dim zClip(3) As GLdouble
Dim xc, yc, zc As Variant

xc = Array(1#, 0#, 0#, -5#)
yc = Array(0#, 1#, 0#, -5#)
zc = Array(0#, 0#, 1#, -5#)

For i = 0 To 3
xClip(i) = xc(i): yClip(i) = yc(i): zClip(i) = zc(i)
Next

'***********************
'Initialize the Graphics
'***********************
glMatrixMode mmModelView
glLoadIdentity
glScalef 0.01, 0.01, 0.01

glClear clrColorBufferBit + clrDepthBufferBit

'********************************************
' Draw the XYZ-Axis at the bottom-left croner
'********************************************
glPushMatrix
glTranslatef -80, -60, 0

If xRot = 0 And zRot = 0 Then
gluLookAt xRot, yRot, zRot, 0#, 0#, 0#, 0#, 0#, 1#
Else
gluLookAt xRot, yRot, zRot, 0#, 0#, 0#, 0#, 1#, 0#
End If
glRGB 255, 0, 0
glBegin bmLines
glVertex3f 0, 0, 0
glVertex3f 10, 0, 0
glEnd
glPushMatrix
glTranslatef 10#, 0#, 0#
s = "X"
glListBase myFont - 32
ReDim A(0 To Len(s) + 1)
StringToByteArray A, s
glScalef 4#, 4#, 4#
glCallLists Len(s), GL_BYTE, A(0)
glPopMatrix

glRGB 0, 255, 0
glBegin bmLines
glVertex3f 0, 0, 0
glVertex3f 0, 10, 0
glEnd
glPushMatrix
glTranslatef 0#, 10#, 0#
s = "Y"
glListBase myFont - 32
ReDim A(0 To Len(s) + 1)
StringToByteArray A, s
glScalef 4#, 4#, 4#
glCallLists Len(s), GL_BYTE, A(0)
glPopMatrix

glRGB 0, 0, 255
glBegin bmLines
glVertex3f 0, 0, 0
glVertex3f 0, 0, 10
glEnd
glPushMatrix
glTranslatef 0#, 0#, 10#
s = "Z"
glListBase myFont - 32
ReDim A(0 To Len(s) + 1)
StringToByteArray A, s
glScalef 4#, 4#, 4#
glCallLists Len(s), GL_BYTE, A(0)
glPopMatrix

glPopMatrix
SwapBuffers frmDisplay.hDC
glFlush

'******************************
' Draw the Rectangles
'******************************
glPushMatrix

If xRot = 0 And zRot = 0 Then
gluLookAt xRot, yRot, zRot, 0#, 0#, 0#, 0#, 0#, 1#
Else
gluLookAt xRot, yRot, zRot, 0#, 0#, 0#, 0#, 1#, 0#
End If

glMatrixMode mmProjection

For i = 1 To bIndx
For j = 0 To 3
W(j, 0) = points(boxes(i, j), 0)
W(j, 1) = points(boxes(i, j), 1)
W(j, 2) = points(boxes(i, j), 2)
Next
Call Quadratic(W)
Next '1 to bIndx

glClipPlane cpClipPlane0, xClip
glEnable glcClipPlane0
glClipPlane cpClipPlane1, yClip
glEnable glcClipPlane1
glClipPlane cpClipPlane2, zClip
glEnable glcClipPlane2

glPopMatrix

SwapBuffers frmDisplay.hDC

glFlush

End Sub

Sub Quadratic(W() As Single)

glBegin GL_LINE_LOOP
glVertex3f W(0, 0), W(0, 1), W(0, 2)
glVertex3f W(1, 0), W(1, 1), W(1, 2)
glVertex3f W(2, 0), W(2, 1), W(2, 2)
glVertex3f W(3, 0), W(3, 1), W(3, 2)
glEnd
glBegin GL_QUADS
glVertex3f W(0, 0), W(0, 1), W(0, 2)
glVertex3f W(1, 0), W(1, 1), W(1, 2)
glVertex3f W(2, 0), W(2, 1), W(2, 2)
glVertex3f W(3, 0), W(3, 1), W(3, 2)
glEnd

End Sub

As it shows, I am using three 1D-Arrays (xClip, yClip & zClip) to clip the entire graph with three planes: X=5, Y=5 and Z=5 (or I am trying to!) BUT NOTHING EVER HAPPENS AT ALL!

My best guess is that I am missing some other "parts" (i.e. sub/func calls) and/or maybe the order/placement of my calls are not correct.

My greatest appreciation is attached