Archived

This topic is now archived and is closed to further replies.

problem with auxSolidCylinder()

This topic is 5573 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, I have problem using auxSolidCylinder(GLdouble radius, GLdouble lenght) function. I want to draw cylinder between two points, let say vectors u(x1,y1,z1) and v(x2,y2,z2). Calculating the lenght is easy, but I can''t figure out how to translate and rotate the cylinder. If I just call the function, the cylinder is drawn along the Y-axis starting from (1,0,0). Any suggestions/ideas/references would be highly appreciated! Thanks, -----

Share this post


Link to post
Share on other sites
I''m not exactly sure what your problem is... You are just calling the function, correct? Have you used glRotate() and/or glTranslate()? A glRotate(90,0,1,0) should solve your problem; or is your problem something else?

I asked one of the Black Robes why the Deceiver wasn''t going to stay to defend the dam, and he tersely replied: "He goes to warn the Emperor; moving through odd angles, faster than any man, and if unobserved, much faster than that."

Elemental Engine: ryan_lurvey.tripod.com/engine.html

Share this post


Link to post
Share on other sites
He means he needs the calculations for figuring out the rotation values, no matter what the 2 points are. You can''t just glRotate(90,0,1,0) to get from u(372, 832.63, 93) to (0, 342, 20.04)

There''s some trig stuff involved with that. I lost the function I used to use for this sort of stuff. I think it was something like float yRot = atan( u(x1), v(x2) ); glRotatef(yRot, 0, 1, 0); and then you''d repeat it for the other axis. I''ll edit this if I can remember better or get around to trying it out.

Sorry I can''t offer anything else, perhaps someone older who actually knows this stuff properly can help you.

------------
MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155
"It''s all part of the conspiracy of conspirators conspiring to conspire their own conspiracies..."

Share this post


Link to post
Share on other sites
That''s right. I don''t know how to calculate the angles which
I use to rotate around each axis. If I know the algorithm, I
can write the code myself

Thanks anyway,
-----

quote:
Original post by LockePick
He means he needs the calculations for figuring out the rotation values, no matter what the 2 points are. You can''t just glRotate(90,0,1,0) to get from u(372, 832.63, 93) to (0, 342, 20.04)

There''s some trig stuff involved with that. I lost the function I used to use for this sort of stuff. I think it was something like float yRot = atan( u(x1), v(x2) ); glRotatef(yRot, 0, 1, 0); and then you''d repeat it for the other axis. I''ll edit this if I can remember better or get around to trying it out.

Sorry I can''t offer anything else, perhaps someone older who actually knows this stuff properly can help you.

------------
MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155
"It''s all part of the conspiracy of conspirators conspiring to conspire their own conspiracies..."


Share this post


Link to post
Share on other sites
Well, I'll have a go (can't promise this'll work)

We have points A and B and want a cylinder to connect the two points. Assumin CA and CB are the central points of the two ends of the cylinder then:

y z
^ ^
| B |
| / | B
| / | /
|A |A
+---->x +---->x

(diagrams to help me figure this out)
angle between AB and y-axis = atan((Bx - Ax) / (By - Ay)).
angle between AB and z-axis = atan((Bx - Ax) / (Bz - Az)).

You'll also be affected by quadrants:

first quadrant ((Bx - Ax) >= 0, (By - Ay) >= 0):
angle between AB and y-axis = atan((Bx - Ax) / (By - Ay)).

second quadrant ((Bx - Ax) >= 0, (By - Ay) < 0):
angle between AB and y-axis = PI + atan((Bx - Ax) / (By - Ay)).

third quadrant ((Bx - Ax) < 0, (By - Ay) < 0):
angle between AB and y-axis = PI + atan((Bx - Ax) / (By - Ay)).

fourth quadrant ((Bx - Ax) < 0, (By - Ay) >= 0):
angle between AB and y-axis = (2 * PI) + atan((Bx - Ax) / (By - Ay)).

(also for z axis)

So, to rotate the cylinder correctly to join A(Ax, Ay, Az) and B(Bx, By, Bz):

    
float angleY;
float angleZ;

// calculate angleY

if (By - Ay == 0)
angleY = PI / 2;
else
angleY = atan((Bx - Ax) / (By - Ay));
if (By - Ay < 0)
angleY += PI;

// calculate angleZ

if (Bz - Az == 0)
angleZ = PI / 2;
else
angleZ = atan((Bx - Ax) / (Bz - Az));
if (Bz - Az < 0)
angleZ += PI;

// apply rotations

// this should rotate around Z-axis

glRotatef(angleY, 0, 0, 1);
// this should rotate around Y-axis

glRotatef(angleZ, 0, 1, 0);


I'll be very surprised if that works because I haven't tested it, but give it a go and see what it does!

Enigma

edit: blasted tags!

[edited by - Enigma on September 13, 2002 5:27:28 PM]

Share this post


Link to post
Share on other sites
1) Don''t use auxSolidCylinder or any aux functions from the glaux library. See "Don''t use the glaux" at http://www.mfcogl.com/

2) I put up a tutorial and demo with source code exactly about what you want to do, drawing cylinder between two points at

http://www.mfcogl.com/OpenGL%20-%20draw%20cylinder%20between%202%20pts.htm

It is in MFC but all the OpenGL code is valid. Just cut and paste in the framework of your choice, but please pass the word and get rid of the glaux header.

Share this post


Link to post
Share on other sites
Thanks a lot for your tutorial and demo. It helped me to
understand how exactly it works (especially the math part).

About the glaux library, I didn''t know it is no longer
supported. There are still some applications that use that
library, and I just "grabbed" auxSolidCylinder() because
it seemed to be easy to use.

Thanks again,
-----

quote:
Original post by j p
1) Don''t use auxSolidCylinder or any aux functions from the glaux library. See "Don''t use the glaux" at http://www.mfcogl.com/

2) I put up a tutorial and demo with source code exactly about what you want to do, drawing cylinder between two points at

http://www.mfcogl.com/OpenGL%20-%20draw%20cylinder%20between%202%20pts.htm

It is in MFC but all the OpenGL code is valid. Just cut and paste in the framework of your choice, but please pass the word and get rid of the glaux header.




Share this post


Link to post
Share on other sites
I didn''t have time to test your code, but there is a nice tutorial and demo below, you might take a look at that site.

Thanks anyway,
-----

quote:
Original post by Enigma
Well, I''ll have a go (can''t promise this''ll work)

We have points A and B and want a cylinder to connect the two points. Assumin CA and CB are the central points of the two ends of the cylinder then:

y z
^ ^
| B |
| / | B
| / | /
|A |A
+---->x +---->x

(diagrams to help me figure this out)
angle between AB and y-axis = atan((Bx - Ax) / (By - Ay)).
angle between AB and z-axis = atan((Bx - Ax) / (Bz - Az)).

You''ll also be affected by quadrants:

first quadrant ((Bx - Ax) >= 0, (By - Ay) >= 0):
angle between AB and y-axis = atan((Bx - Ax) / (By - Ay)).

second quadrant ((Bx - Ax) >= 0, (By - Ay) < 0):
angle between AB and y-axis = PI + atan((Bx - Ax) / (By - Ay)).

third quadrant ((Bx - Ax) < 0, (By - Ay) < 0):
angle between AB and y-axis = PI + atan((Bx - Ax) / (By - Ay)).

fourth quadrant ((Bx - Ax) < 0, (By - Ay) >= 0):
angle between AB and y-axis = (2 * PI) + atan((Bx - Ax) / (By - Ay)).

(also for z axis)

So, to rotate the cylinder correctly to join A(Ax, Ay, Az) and B(Bx, By, Bz):


      
float angleY;
float angleZ;

// calculate angleY

if (By - Ay == 0)
angleY = PI / 2;
else
angleY = atan((Bx - Ax) / (By - Ay));
if (By - Ay < 0)
angleY += PI;

// calculate angleZ

if (Bz - Az == 0)
angleZ = PI / 2;
else
angleZ = atan((Bx - Ax) / (Bz - Az));
if (Bz - Az < 0)
angleZ += PI;

// apply rotations

// this should rotate around Z-axis

glRotatef(angleY, 0, 0, 1);
// this should rotate around Y-axis

glRotatef(angleZ, 0, 1, 0);


I''ll be very surprised if that works because I haven''t tested it, but give it a go and see what it does!

Enigma

edit: blasted tags!

[edited by - Enigma on September 13, 2002 5:27:28 PM]

Share this post


Link to post
Share on other sites