djavan

01-27-2003, 05:57 AM

With many thanks for your reply,

My problem is that I am using VB and trying to apply glClipPlane to the Cube example (that I have got it from "Code Examples") but NOTHING HAPPENS!!

Based on the example (which is clipping the WireSphere), what I had to do was to add just two lines :

glClipPlane GL_CLIP_PLANE0, myPlane

glEnable GL_CLIP_PLANE0

with myPlane being an array initialized to :

1.0, 0.0, 0.0, -Wd2/2.0

in order to chop off half the cube on the X-Axis.

I've even tried all other three combinations of plus/minus on 1.0 and Wd2/2.0 and still NOTHING!

Can you please tell me what is missed out?

With my greatest appreciation.

Deiussum

01-27-2003, 11:18 AM

More code might be useful. You should also be aware of this:

From MSDN:

The glClipPlane function specifies a half-space using a four-component plane equation. When you call glClipPlane, equation is transformed by the inverse of the modelview matrix and stored in the resulting eye coordinates. Subsequent changes to the modelview matrix have no effect on the stored plane-equation components. If the dot product of the eye coordinates of a vertex with the stored plane equation components is positive or zero, the vertex is in with respect to that clipping plane. Otherwise, it is out.

Especially the part about the modelview matrix. What is your modelview matrix like at the time you call glClipPlane?

One other thing, when do you call that with respect to the window being initialized? It's been awhile since I worked with OpenGL in VB. I can't remember if the window context is initialized at the time of the Form_Load, yet or not. I do know that until there is an OpenGL context created, no OpenGL function will succeed.

[This message has been edited by Deiussum (edited 01-27-2003).]

djavan

01-27-2003, 12:56 PM

Thanks again for your kind help.

What I have is a simple 3D-Plotting program 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".

One thing worth noting is that even when I take this XYZ-Axis part out, the problem is still there: NO CLIPPING!

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

'****************************************

' Initialize the Clipping-Plane equations

'****************************************

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.

With my highest appreciation for your help.

Deiussum

01-28-2003, 04:45 AM

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

Here's yor problem. You are setting up the clip plane after you call the Quadratic function, which is doing your drawing. OpenGL is a state machine, which means that when you set the state, things done afterwards will take that state into effect. Since your clip planes aren't setup at the time of drawing, it doesn't affect anything.

However since it doesn't appear you disable them anywhere, I would guess that if you were to cause the scene to redraw itself (for instance resizing the window, minimizing, restoring, etc.) that you might see the effect of the clipping.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.