khdani's picture

3D Plot Help

I want to plot surface graph, the graph is XYZ points.
I tried using LINE_STRIP but the graph looks wiredframe, how can i make it look more solid?

Thank You


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

The basic primitive in 3d graphics is the triangle, so you'll need to specify TRIANGLES as the drawing mode. Check this page for a great explanation of how different primitives work.

khdani's picture

I tried TRIANGLES, LINES, QUADS, it gives me the same result with slight difference.
I saw screenshots of very beautyful surface plottings, how do they that?

objarni's picture

1. Imagine a x,y grid of points.
2. Now imagine plotting points at the coordinates given by (x, y, z) where z = f(x,y)
3. Now you have the "structure" of the graph - it's vertices.
4. You want to connect these (x,y,z) points together using triangles.
5. Think of one grid cell, having four (x,y) corners making it a square:
a b
c d
6. You could draw this square using two triangles adb and acd.
7. The vertice coordinates a, b, c, d can be computed using your four corners (x,y) and the function z=f(x,y)
8. Draw the two triangles using GL_TRIANGLES primitives
9. Repeat for each grid cell!

You may want to color different corners of the triangles using for example the z value for the corner. Adding lighting and normals at each vertice using glNormal would further enhance the visual appeal of the graph.

Good luck

khdani's picture

Thank You Objarni,
I'll try that!
Should I use any textures?
I also read about Bezier surfaces, would it be better to use it ?

the Fiddler's picture

First, try creating the surface without any textures/lighting etc. Once that is working correctly start adding features until you manage to achieve the appearance you'd like (both textures and lighting follow the same basic principles as described by objarni).

Beziers are a little more complicated - they are a mathematical representation of the surface, so you first have to "evaluate" the points of the surface (at a desired level of detail) and then connect these points to form triangles. In other words, you'll need to build upon the part you are working on right now. :)

Start from the basics and work up - this is quite a fascinating topic!

khdani's picture

Thank You!

khdani's picture

Thank you the Fiddler and Objarni for your help, I've managed to plot solid 3D surface, with nice lightings.

Thank you!

objarni's picture

You have a screenshot for us ;) ?

khdani's picture

With pleasure :)




objarni's picture