Ok... changing strategy...

Started by
16 comments, last by white skies 18 years, 12 months ago
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]
Advertisement
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]
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.
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]
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...)
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 <
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.
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])

This topic is closed to new replies.

Advertisement