View Full Version : Cutting thru a model

I have sent this to the beginner section but I guess there's no one expert enough to give me an answer. Here I am sending the same thing to the advanced users.

I am trying to clip a plane which is not perpendicular to the x,y or z.What I actually want to do is to clip a 3D cylinder like slizing a pizza. I am particularly confuse with the equation parameter of glClipPlane() or is there any other method that I can use? Any feedback is very much appreciated..

Suf.

I think glClipPlane is by far the best way to do this. The equation parameter is simply the normal vector of the clipping plane from what I remember.

Do you mind giving me an example please? I am not sure how I can actually slize a chunk of a cylinder by specifying Ax+By+Cz+D for the equation parameter.It's all pretty new to me.

[This message has been edited by Suf (edited 07-23-2002).]

The plane equation is

Ax+By+Cz+D=0

ie. a point <x,y,z> on the plane satisfies the above equation.

As it turns out, the coefficients (A,B,C) specify the normal of the plane. Now, if you want to construct a plane with a specific orientation and a point on that plane, you subsitute the coefficients ABC for the normal and solve for D with xyz being the point on the plane.

For example:

suppose you want a plane with normal <1 2 3> that passes through the point <4 5 6>:

the plane equation is

1x + 2y + 3z + D = 0

for some D. but we know that 4 5 6 must satisify this equation (not because it has to, but because we want it to:-) so

1.4 + 2.5 + 3.6 + D =0

D=-32

and thus the coeffients of the plane are

(1 2 3 -32)

cheers

John

gumby

07-23-2002, 05:41 PM

Clip planes are of infinite extent, aren't they? That will make it hard cut just a section out of your cylinder.

bensch128

07-23-2002, 09:24 PM

I have an Idea that should work:

(Using clipplanes (1, -1, 0) and (-1, -1, 0)

and center = (4, 5, 6))

Render the pizza twice:

1) with a clipplane

(1, -1, 0) d = -(1*4 + -1*5 + 0*6) == 1 ->

(1, -1, 0, 1) as first clipplane equ.

and then

2) eith a clipplane:

(-1, -1, 0) d = -(-1*4 + -1*5 + 0*6) == 9 ->

(-1, -1, 0, 9) as the second clipplane equ.

Voila, a pizza with a 90deg chunk taken out.

Ben Schleimer

If I wish to cut with an interval of 30 degrees out of the 360degrees chunk and display the remaining chunk as(330 degrees then 300 degrees then 270degrees etc), how is that possible. Somehow the clipping plane must start from the origin and cut the structure either at only positive(or negative) x or y.

My inefficient alternative is by using a circle algorithm and cut the slices from front or back by the means of specifying the number of points and alternating between GL_LINE_LOOP and GL_LINE_STRIP. As you guys are well aware of, it is inefficient especially when there are a lot of circles to be drawn on top of each other.

Suf.

bensch128

07-24-2002, 09:36 AM

Suf,

I think if you want to cut a 30 degree chunk out of your pizza with the first clip plane at 0 degrees,

then the first clipplane normal should be (1, 0, -1) (calculate d depending on the position of the object)

and then the 2nd clipplane normal should be

(-sin(30*DegToRad), 0, cos(30*DegToRad)).

This will make sure the vertices in the (1, 0, -1) halfplane are rendered and vertices in the other halfplane are rendered.

You'll have to experiment, but it should work.

Ben

Ben,

Thanks for the help. It works! and I really appreciate it. There's also another scenario that I am thinking of. What if, the portion of pizza that we wish to display is 330degrees? How is that possible as glClipPlane() cuts an infinite length.

Kind regards,

Suf.

Niftybitz

07-30-2002, 04:39 AM

The funny thing about clip-planes is that you can do almost everything with only for example a clip-plane that lies in the x/z plane. The fact is that with a simple glRotatef() your clip-plane is also rotated. So you can even move the plane up and down by using glTranslatef(). The fact that this works is that a clip-plane has effect on the current modelview matrix. So no fancy formulas. It's very simple. If you can't get it to work, tell me and i'll give you a simple example.

Ciao,

Niftybitz.

Niftybitz,

Thanks for the feedback but I don't still understand how we can display 3/4 of a pizza on the screen. I have used glClipPlane and the best that I could show is only 1/2 of the pizza.

Suf

fresh

07-30-2002, 12:16 PM

To draw 2/3 of the pizza you could render the model twice with two different clip plane. You could also use the stencil buffer, render the invisible 1/3, then render the whole model with stencil testing. What you're proposing to do can't be done in one pass with clip planes.

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