iliasr

09-24-2012, 07:36 AM

Hello to all OpenGL-ers,

I am a complete beginner to OpenGL or to any graphics programming whatsoever, and as such I need some help...

I am drawing a quadratic curve that connects two shapes, as shown in the picture below:

https://lh3.googleusercontent.com/-K8h_9OuEZeM/UGBeX5ADHZI/AAAAAAAAAf8/8FYosgQqg3I/s144/gl.jpg

The curve connecting the two shapes is quadratic, drawn with the following JOGL code:

// Draw quad curve between two points (x1, y1) and (x2, y2).

double x0, y0; // Predefined curve control point

double angle; // Pre-calculated angle of rotation

double a = -y0 / (x0 * x0);

gl.glPushMatrix();

gl.glTranslated(x1, y1, 0);

gl.glRotated(Math.toDegrees(angle), 0, 0, 1);

// Draw curve

gl.glBegin(GL.GL_LINE_STRIP);

double x, y;

for (x = 0; x < d; x += 1) {

y = a * (x - x0) * (x - x0) + y0; // Quad curve

gl.glVertex2d(x, y);

}

gl.glEnd();

gl.glPopMatrix();

The two points (x1, y1) and (x2, y2) are the two centers of the shapes 1 and 2 of the figure. What I want to do now is draw an arrow at the point where the curve meets the square, i.e. I want to draw this curve to represent a directed edge, if this was a graph. The two shapes are drawn independently in another location in my source code.

However I feel that I am doing/thinking this wrong, since I am unable to find a way to draw the arrow. I have tried calculating the distance of each point of the curve (as I draw it) from the center of the square (including the distance of the border of the square) and then keeping the last point that touches the square's border, but this gets messed up because of all the transformations, since the square is drawn without any transformations.

What am I doing wrong? Please ask if something is not clear enough!

I am a complete beginner to OpenGL or to any graphics programming whatsoever, and as such I need some help...

I am drawing a quadratic curve that connects two shapes, as shown in the picture below:

https://lh3.googleusercontent.com/-K8h_9OuEZeM/UGBeX5ADHZI/AAAAAAAAAf8/8FYosgQqg3I/s144/gl.jpg

The curve connecting the two shapes is quadratic, drawn with the following JOGL code:

// Draw quad curve between two points (x1, y1) and (x2, y2).

double x0, y0; // Predefined curve control point

double angle; // Pre-calculated angle of rotation

double a = -y0 / (x0 * x0);

gl.glPushMatrix();

gl.glTranslated(x1, y1, 0);

gl.glRotated(Math.toDegrees(angle), 0, 0, 1);

// Draw curve

gl.glBegin(GL.GL_LINE_STRIP);

double x, y;

for (x = 0; x < d; x += 1) {

y = a * (x - x0) * (x - x0) + y0; // Quad curve

gl.glVertex2d(x, y);

}

gl.glEnd();

gl.glPopMatrix();

The two points (x1, y1) and (x2, y2) are the two centers of the shapes 1 and 2 of the figure. What I want to do now is draw an arrow at the point where the curve meets the square, i.e. I want to draw this curve to represent a directed edge, if this was a graph. The two shapes are drawn independently in another location in my source code.

However I feel that I am doing/thinking this wrong, since I am unable to find a way to draw the arrow. I have tried calculating the distance of each point of the curve (as I draw it) from the center of the square (including the distance of the border of the square) and then keeping the last point that touches the square's border, but this gets messed up because of all the transformations, since the square is drawn without any transformations.

What am I doing wrong? Please ask if something is not clear enough!