Graphic Algorithms for Wireframe

Hi,

I’m a begginner in OpenGL and I’m a doing a simple wireframe of an 3d object that has four points.

For example:

These are the x,y,z points I’m using for my object:

float [] x = {40.00f,40.00f,40.00f,10.00f};
float [] y = {-100.00f,100.00f,100.00f,170.00f};
float [] z = {0.00f,0.00f,0.00f,0.00f};

Now I need to connect these points using an array and I also need for these points to be generated through some mathematical equation or algorithm, while the object is being rotated. I’m using GL.GL_LINE_STRIP by the way.

My questions are:

Does any of you have any idea which graphic algorithm or equation I could use to generate the x,y,z points?

And can someone give me an idea as to how to set up a ‘for loop’ that would connect the horizonatal and vertical lines and points that form the object?

This wireframe is supposed to be based on the usage of graphic mathematicl algorithms, so I can’t use any of that fancy classes or such that would do most of the mathematical part for me.

Is there any site any of you could suggest that give great wireframe examples that use primarily graphic equations, or where I can find these graphical math equations?

Help!

Before I attempt to respond to your highly confusing
question (I am sorry, it could just be me…), let me
say that OpenGL will do most of the math that is
required for drawing things on the screen for you.
You, simply, put ogl to a particular “state” and if
the state is such, you provide vertex information
(coordinates for example) sequencially until you are
done drawing, and then swap the buffers so that what
you wanted drawn appears on the screen. This is how
things work in the most primative of cases. An example,
if you want a line to be drawn, you set the gl to the
state where it accepts vertex coordinates and start
making calls to the function that provides the data,
with the data as arguments (or a pointer to the
data as argument to the function). Now, to draw
anything, you need to think of how it will be drawn,
so if you were to draw a 3d object in space and
wanted it to appear as 'wireframe" you would simply
draw each of the lines separately – much like
drawing on paper, but the difference is that you
simple “order” the drawing operations and provide
data, and the drawing is done for you by the gl.

Look for something called “the Red Book” and read
the introductory chapter – you need to do this!
There are examples there to do far more advanced
things that you have requested in this posting.

Best of luck.

Hi,

I have the Red Book, version 1.2 though, but it isn’t helping me much with what I’m asking for.

I’m sorry if my question seems out of sorts.

What I mean is…for example, let’s say I want to smoothen and improve the rendering of my object. I would calculate the surface normals of my values by using a specific equation to do that.

That’s what I mean when I mean “the math” and the equations that go into generating the x,y,z points in my wireframe program.

I don’t know the name of the equation or how it looks like, but I think it looks something like this:

x=x*cos+z*sin
y = y 
z=-x*sin+z*cos

It doesn’t look right but I hope you recognize it because apperently for the project I’m doing, I need to use this equation for the ‘for loop’ I need to generate the points.

But I need to identify this equation and what it does, really. So can you help me?

I hope I was clearer…

I am afraid I do not understand exactly what you want,
but I have an idea to offer. If you want your shading
to be very smooth (in terms of lighting), then you
can recompute the per-vertex normals in a smart way
that will make shading appear smooth. It was mentioned
recently (again) in the forum somewhere. All you have
to do is create a new array of per-vertex normals
(so for every vertex you have a normal vector) and
first loop over all vertices and “accumulate” the
neighboring vectors component by component to the
new array. Then you normalize the vectors and these
new vectors should give you pretty damn smooth
shading.

On the other hand, if you have analytical expressions
for the vertex coordinate of the surface (i.e. your
surface is parametrized somehow) you can generate
smooth vectors in the same way you create vertices.

I do not think I can be of much more help.

Hello there,

I figured it out.

This is what I was trying to say:

This is the equation I was talking about. I think it’s the equation for the Matrix or whatever it’s called.

x2 = x1 cos O + z1 sin O
y2 = y1
z2 = - x1 sin O+ z1 cos O

O = deta or data, depending how you want to pronounce it…

I have a double array, one that tells me how many times I want to generate and wrap the points around and the other array is how many points I have.

The points are generated by dividing 360/number of times I want to generate points, and that would be my angle 360/20=18. Then I would use float radian = float Math.PI/180 within the forumula to convert the angle to radians and that would generate the points along the axises. Then I would use 2 for-loops, one to make vertical lines and the other to make horizontal lines for the wireframe.

So that’s what I meant by needing a math equation to generate the x,y,z points because without it, it won’t be able to rotate those points that are being called over and over again through the for loops. It was required in the project I was doing, just to get used to the idea of using that particular equation itself.

Oh well, just an explanation…

do you want to rotate the whole thing?
why not use glRotate?

I already have glRotate in my code and it’s not related to what my problem was. It’s another thing entirely. I won’t get into the details of it since I already got this part figured out.

Thanks anyway