• Advertisement
Sign in to follow this  

Ok... changing strategy...

This topic is 4680 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Due to the fact that i'm having trouble with implementing the bezier surface, not understanding it completely and of course because openGL probably implemented it better than i can right now, I decided to implement only what i really need. :) Suppose you have initial control points of a bezier surface. You move one of the control points, let's say 1 units up, and the other control points move as well. Is there any way I can get the coordinates of the control points after the change? ( sorry if I'm starting/continuing to bother you...) As far as i understand, all i need to do is to calculate the correct bernstein function for this point... But what shuld the parameters be? Thanks:) [Edited by - white skies on April 27, 2005 11:28:57 AM]

Share this post


Link to post
Share on other sites
Advertisement
sorry if i came across harsh in your previous thread.

i misread your last post, i thought you were saying you did already understand it, which i found rahter arrogant, but you said you were simply trying to understand it.

my bad completely.

first, you should get straight: what do you really want?

ive tried to explain you to this before, and so have others, but let me try again. moving one controlpoint is as easy as changing its coordinate. this will not affect the other controlpoints, and neither should it. you want the other controlpoints to move? well, do so. they are not going to do so automaticly. what do you expect them to move to anyway? you move one, and the others automaticly take the shape of a bunny? a giraffe? none of that makes sense, since these control points cant guess what you want them to do, unless you tell them explicitly by just setting their position.

there is not much more i can do to help you now is to once again empathize the importance of understanding how beziers work and what they do before trying to use them for things they cant do, like reading your mind and knowing where you want them to go for instance.

search for the phrase 'bezier casteljeau step'. thinking of beziers that way is much more inituative than in terms of bernstein polynomals. and remember: the control points are the input, the surface is the output. while changing one controlpoint does affect the entire surface, it doesnt change the other controlpoints.

Share this post


Link to post
Share on other sites
Ok... so I guess what i'm looking for is the new intersection points of the lines in the grid, right?
they DO change, i'm not imagining it, right? at least i hope i'm not ;)
is there an algorithm for doing that?

Share this post


Link to post
Share on other sites
Not only is there an algorithm for finding points on the surface, but it has a name! It's called "Bezier". It's quite famous.

Your question is strangely surreal - could you explain what you are trying to do at a higher level, and perhaps then we can offer more help?

Share this post


Link to post
Share on other sites
I have a surface which i want to change, and some control points.
I want to keep drawing the control points on the intersections of the lines, no matter what changes to the surface are made.

Share this post


Link to post
Share on other sites
Quote:
Original post by white skies
I have a surface which i want to change, and some control points.
I want to keep drawing the control points on the intersections of the lines, no matter what changes to the surface are made.


oh! the lines!

uhm, wait... what lines?

Share this post


Link to post
Share on other sites
The time has come to set down some common ground :)

Bezier curve = curve defined by a set of control points
Mesh = bunch of triangles with vertices
Grid = bunch of interconnected nodes

OpenGL = graphics library which likes to draw approximations to a bezier curve by representing a discrete set of points on the curve as nodes in a grid, and then filling it in with triangles. This means that the vertices of the triangles correspond exactly to the nodes in the grid. The control points, in nearly all circumstances, will not.

Now, using that vocabulary, ask it a third time [wink]

Share this post


Link to post
Share on other sites
I guess what i have is a mesh (although i see no signs of triangles, but i use "glEvalMesh" so it has to be it :) ),
I also have control points which define it.
in the beggining the mesh looks something like this:

|--|---|---|---|---|
|--|---|---|---|---|
|--|---|---|---|---|
|--|---|---|---|---|
|--|---|---|---|---|
|--|---|---|---|---|
|--|---|---|---|---|

At first The control points stands exactly in the intersection points.
But if i move one of the control points - the mesh will change and so will the
intersection points.
What i want to do is to get the intersection points coordinates in order to draw there red circles for example.[smile]

Share this post


Link to post
Share on other sites
OK :o)

If you really want a red circle, as part of your game, I recommend implementing the besier function yourself and working them out, especially since this means you can have the same number of points being rendered regardless of the accuracy of the rendering.

If you just want something you can see for debugging purposes, which seems more likely, I suggest you render the grid like normal, and then do a bit of magic with OpenGL:


<draw curve>();

glDepthFunc(GL_LEQ);
glDisable(GL_LIGHTING);
glColor4f(1, 1, 1, 1);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINES);

<draw curve>();

glDepthFunc(GL_LESS);
glEnable(GL_LIGHTING);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);



I may have got some variables wrong there - Im doing it off the top of my head, and GL_LINES, GL_FILL, GL_LEQ and GL_LESS may all be the wrong names - look them functions up in the red book or something :)

This won't draw circles, but it will draw outlines around all of your polygons, so you will be able to see where the intersections are.

I hope that's helpful. It may be possible to do a polygon mode of GL_POINTS too, in which case a suitable point size would give you exactly the result you asked for :)

Another thing is, the glDepthFunc here is still obeying the basic rules of depth tests, so some points will be hidden behind things. For debugging, it is sometimes good to disable depth testing completely.

Hope that helps, once you've finished digesting it [grin]

Share this post


Link to post
Share on other sites
Quote:

I want to keep drawing the control points on the intersections of the lines, no matter what changes to the surface are made.


Quote:
Original post by white skies
I meant the bezier curves :)
My surface is made from a grid of curves (which are straight at first)

let me tell you this one more time, read slowly:

you CANT draw the control points on the intersections of the bezier curves, because thats not where they are located. you could draw a circle there, but then it wouldnt be the controlpoint.

in degenerate cases, such as a flat surface, the controlpoints might lie on the surface, but usually, they will not.

ill say it once again: first try to understand before you use them. just grab a piece of paper and draw out a couple of decasteljeau steps.

Share this post


Link to post
Share on other sites
Quote:
you CANT draw the control points on the intersections of the bezier curves, because thats not where they are located. you could draw a circle there, but then it wouldnt be the controlpoint.


I got it, I really don't know why i kept calling them controlpoints. all i meant was to draw the red circles on the intersections... [smile]

Share this post


Link to post
Share on other sites
Quote:
Not only is there an algorithm for finding points on the surface, but it has a name! It's called "Bezier". It's quite famous.


Quote:
If you really want a red circle, as part of your game, I recommend implementing the besier function yourself and working them out


Ok... you've got me confused...
is there an algorithm that gives us intersection points?
Or i have to implement the whole process in order to get them? [smile]
(hoping this is my last question... I guess you're tired of this...)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Implementing Bezier surfaces can be non-trivial. If you're the least bit uncertain about the basics of Bezier curves and surfaces, I would suggest starting at the beginning.

One good way to get started might be to make a simple 2d quadratic Bezier curve demo where you can move the control points around and see the results. It really might help clear things up.

A quadratic Bezier curve is of the form:

P(t) = (1-t)2p0+2(1-t)tp1+t2p2

p0, p1, and p2 are your control points. Although you can certainly move them, at any one time they are constants in the equation. t is your variable - you plug it into the function and out comes a point. Using this information you could write a simple evaluation function, like this:

Vector2 EvaluateBezier(Vector2 p[3], float t)
{
float omt = 1.0f-t;
return omt*omt*p[0]+2.0f*omt*t*p[1]+t*t*p[2];
}

The curve is defined for all values of t, but typically we just use the portion in the range [0, 1]. If you look at the equation, you might note that P(0) = p0, and P(1) = p2. This is an important property of Bezier curves; they pass through their end control points (although in general not through the middle control points).

So the next step is to draw the curve. In theory we'd like to plot a point for each value of t (an infinite number) in the range [0, 1]. That would be a perfect representation of the curve. In practice we obviously have to approximate the curve, usually with lines drawn between points evaluated at some interval. You just have to decide how many segments you want to split the curve up into. It might look something like this:

// p[], the array of control points, already exists or is an input parameter
int numSegments = 16; // Or whatever you want
std::vector verts(numSegments + 1);
float t = 0.0f;
float step = 1.0f / (float)numSegments;
for (int i = 0; i <

Share this post


Link to post
Share on other sites
Pft...that was me. Here's the equation with proper formatting:

P(t) = (1-t)2p0+2(1-t)tp1+t2p2

Also the last part got cut off. If you're interested in the rest, let me know and I'll try to recreate it.

Share this post


Link to post
Share on other sites
Damn it! I did it! [smile]
It was so much simpler than i had thought of... I tried to build a spaceship when all i needed was a bike...
How did i do it:
I wanted to get the intersections of the bezier curves in my mesh , right?
so, f(s,t) - which is the bernstein function of the mesh traverses the mesh.
since i knew the intersection points are at t=i/m_width, s=j/m_height all i needed to do is to get the correct bernstein value for the specific point!

and once again, thanks to all you guys who helped!
(and to those who wanted but couldn't [smile])

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement