PDA

View Full Version : Regularly Fluctuated Polygon



ikabod00
02-11-2007, 11:21 AM
I am unsure as to how to create a regularly fluctuated polygon in OpenGL. I need to create just a basic one for an assignment for a class. It doesn't need to be anything fancy. Some help would be much appreciated, thanks. :)

dorbie
02-11-2007, 07:58 PM
http://nehe.gamedev.net/lesson.asp?index=01

ikabod00
02-12-2007, 07:08 AM
I have looked around NeHe before. I was unable to find anything about regularly fluctuated polygons. Perhaps I missed it, if its there, could you like me directly. Thanks

plasmonster
02-12-2007, 07:12 AM
What's a fluctuated polygon?

Once you define it precisely, it'll be a beam reach for the homeland :-)

(Note that no one here is going to do your homework for you.)

ikabod00
02-12-2007, 07:41 AM
Oh, I dont' want anyone to do my homework. I am just looking for some help in drawing. I just need to draw one, to show problems with rendering it. A regularly fluctuate polygon is kinda like this:


_/\/\/\/\/\/\_

that would be a side view of one

songho
02-13-2007, 09:38 AM
You may use a periodic function (sine or triangle) to compute amplitute (height) of a vertex.

The equation to compute height look like this;

output = amp * FUNC( freq * ( time - phase ) ) + offset

where amp is amplitude of wave
FUNC() is one of wave functions (sine, triangle, saw...)
freq is frequency of wave
phase is the horizontal shift
offset is vertical shiftHere is an example using above equation. To make it simple, let's use amp=1, freq=1, offset=0, and time =0. Now, the equation is just FUNC(-phase), which means you need calculate only phase.

Let's say 10 points are laid in a row, for instance, 0, 1, 2, 3, ... 8, 9. And I want to make a triangular wave with these 10 points

* * *
********** => * * * * *
* *The wavelength of the above triangle wave is 4 units, therefore, you can get the phase (horizontal shift) by dividing wavelength;
0/4, 1/4, 2/4, 3/4, ... 8/4, 9/4.

These are input arguments of FUNC(), And here is the body of FUNC() look like;

// factor the phase, so the value is fit between 0~1.
float factor = phase - (int)phase;

// describe only triangle wave here
if(factor < 0.25f) // 0 ~ 0.25
output = 4 * factor;
else if(timeFact < 0.75f) // 0.25 ~ 0.75
output = 2 - (4 * factor);
else // 0.75 ~ 1
output = 4 * factor - 4;With above FUNC(), you can the final height values;
OUTPUT: 0, 1, 0, -1, 0, 1, 0, -1, 0, 1

I am not sure my description is enough to understand, so feel free to ask further questions.

ikabod00
02-13-2007, 10:04 AM
Nope, that was easy enough to understand. I will look into that, and see if I can make that work. Thanks alot. :)