PDA

View Full Version : Simple 3d Graphing Program



rpminihan
10-16-2002, 09:11 AM
Hello,

I'm trying to learn/use opengl to write an application that will build a 3d graph that can be rotated. The graph needs to be generated from a simple dataset. Can anyone point me to some sample code to do this? I am trying to graph scans from a ground penetrating radar product. Thanks in advance for any advice.

delic
10-16-2002, 09:35 AM
data point graph or a surface plot??


points:
while(!infile.eof() && i<MAXPOINTS*3){
infile>>vertices[i]>>vertices[i+1]>>vertices[i+2];
i+=3;
indices[j]=j++;
}
icount=j;
infile.close();
//Render data points
glPointSize(1);
glColor3f(1.0f, 0.0f, 1.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,vertices); //Veritices xyz values were input in initialize routine
glDrawElements(GL_POINTS,icount,GL_UNSIGNED_INT,in dices);


Surface:
You would want to draw tetrahedras or quads instead of using vertices. You can use use GL_QUADS instead of GL_POINTS in the drawelements function above.

Rotating:
Set some theta's using the mouse or keyborad keys and then call the following in the display function..
glRotatef(Xtheta,1,0,0); //Rotate about the x axis
glRotatef(Ytheta,0,1,0); //Rotate about the y axis
glRotatef(Ztheta,0,0,1); //Rotate about the z axis
glScalef(scale,scale,scale); //Scale the data point data points



[This message has been edited by delic (edited 10-16-2002).]

rpminihan
10-16-2002, 09:47 AM
Surface plot I believe. http://www.opengl.org/discussion_boards/ubb/smile.gif I have discrete data points, but I want them all connected. The values in the data file are, x pos, y pos, z pos, and signal strength, which I want to be represented by color.

delic
10-16-2002, 09:50 AM
you would also have to scale the "z value" and then assign each point a color value via the scale. Not hard but a pain.

If it is an even n x m x-y matrix creating the tets or quads isnt that bad but if the x and y's are scattered it would be a pain also. Maybe someone knows a good way to do this..

Sorry i dont have any code like that though..



[This message has been edited by delic (edited 10-16-2002).]

rpminihan
10-16-2002, 09:52 AM
Thanks so much! I'll have to play with this a bit. But thanks again for the help.

delic
10-16-2002, 10:02 AM
you would also have to scale the "z value" and then assign each point a color value via the scale. Not hard but a pain.

Sorry i dont have any code like that though..

rpminihan
10-16-2002, 10:11 AM
X and Y are a regular grid. Will always be rectangular. They represent physical positions. Z is a time value that I want to map to depth. The last value is a signal strength value that I need to map a color to. The idea is to have the colors flow smoothly between actual data points.

delic
10-16-2002, 10:45 AM
the smooth color flow is not a problem at all. Opengl will interpolate the color of the vertices of the tetradedra (3 pts) or quad(4pts). So assuming you have a tetrahedra if you assing each point to be red,green, and blue respectively you will get 1 triangle with each point red,green, and blue but the actual face of the triangle will consist of many shades of colors interpolated from the 3 vertices.

Assigning indices and forming which points will form which triangle. Since your case is a structured regualr matrix you might look into drawing GL_TRIANGLE_STRIP or GL_QUAD_STRIP . THis will avert some of the work.