here’s what I’m trying to do, I want to have a rectangle gradually bend 45 degrees left and then gradually bend 45 degrees right… I have a bend variable that goes from 0 to 45 back to 0 to -45 back to 0 and so on…
My original idea was to build a rectangle using multiple 4 point polygons, and depending on the variables make the z and x coordinates change depending on the bend… I haven’t been able to make anything decent looking or simulating a bend…
any ideas on an algorithm that could work for this or maybe an easier method ?
Assuming rw, and rh for rectangle width and height. “angle” is the bend variable in radians.
glBegin(GL_POLYGON);
glPoint2f(0,0); //bottom left
glPoint2f(rw,0); //bottom right
glPoint2f(rw + rh * sin(angle), rh); //top right
glPoint2f(0 + rh * sin(angle), rh); //top left
glEnd();
This will give a parallelogram, with equal opposite sides. When angle is 0, it is a rectangle. When angle is pi/4, (45 degrees), it is slanted to the right; is -pi/4, (-45 degrees), it is slanted to the left.
ive now managed to create the arrow with several pieces, and somewhat simulate the bending in it real-time… It still isn’t as good looking as I want but It’s a start.
To make a jello-like rectangle, you can use that single quad bending-code to create a series of stacked rectangles.
In the code angle brackets indicate positions, and addition is in position space; The angle array contains the angle for each slice. sh is the hieght of each slice.
//sh = rh / (last-first+1);
bottomleft = <0,0>;
bottomright = <rw, 0>;
for i = first to last
offset = <sh*sin(angle[i]), sh >;
topright = bottomright + offset;
topleft = bottomleft + offset;
DrawRectangle(bottomleft, bottomright, topright, topleft);
bottomleft = topleft; bottomright = topright;
//endloop