gluCylinder look at (solved)

Started by
21 comments, last by Zakwayda 18 years, 7 months ago
I did not think to convert them to degrees, even though it was right in front of my eyes. I am terribly sorry.

Thank you very much. It works perfectly!!

I have updated the screenshot from above to show that it works.

Edit:
If you want to be listed as a reference, please send me a private message.

[Edited by - taby on September 1, 2005 12:43:51 AM]
Advertisement
Great, I'm glad it works :)

(Are you sure you updated your image, though? It looks the same to me...)
I had to refresh my browser to see the new image.

I hope that the colouring system might be something novel for you.
Ah, there it is :) Very nice!
Quote:Original post by jyk
Quote:Someone also told me it would be easiest to convert the vector to Euler angles, but I'm not sure how to do that.
That was actually one of my initial suggestions. Here's an implementation:

*** Source Snippet Removed ***
Can't guarantee I got that right, but you might give it a try.


that takes care of yaw and pitch, but what about roll?
Quote:Original post by godecho
Quote:Original post by jyk
Quote:Someone also told me it would be easiest to convert the vector to Euler angles, but I'm not sure how to do that.
That was actually one of my initial suggestions. Here's an implementation:

*** Source Snippet Removed ***
Can't guarantee I got that right, but you might give it a try.


that takes care of yaw and pitch, but what about roll?



If you set it to some constant non-zero number, the cones will spin like ballerinas? :)
Quote:that takes care of yaw and pitch, but what about roll?
It's irrelevant. The problem as originally stated was to construct a rotation matrix to align the z axis with an arbitrary vector, for which there is no unique solution. We can however find a solution to the problem; to do so, we need only consider two rotation axes, not three.
Hi again,

I was wondering... what is the name of the law or identity or postulation or whatever it is that says that arctan can retrieve those angles?

Anyway, thanks again for your help jyk, the program is working beautifully.

Quote:I was wondering... what is the name of the law or identity or postulation or whatever it is that says that arctan can retrieve those angles?
It's basically just trigonometry. The c++ atan2() function takes the (possibly scaled) sine and cosine of an angle, and returns the angle. In programming terms, it's more useful than atan() because there are fewer degenerate cases.

To extract yaw and pitch from a direction vector, you can find the yaw by projecting the vector onto the 'ground' plane and using atan2(). For pitch, you form a triangle between the tip of the vector, the origin, and the projection of the tip onto the ground plane. Then you can use atan2() again to find the angle.

Since you've got everything working nicely, you probably won't want to hear this! But, if this were my program I'd actually use a different method than the one I gave you. The reason I posted the yaw/pitch method is that it's only a few lines of code, and you can use glRotate(). However, a more stable solution is to construct an orthonormal basis from the direction vector and submit it to OpenGL via glMultMatrix(). It wouldn't cost you anything to try it - you could just comment out the yaw/pitch version and substitute the orthonormal basis version, and see if it worked.

If you're interested, I could probably post some code for this other method later this evening.
I would be more than interested to know more about this type of thing. The better I understand it, the easier other things will come.

This topic is closed to new replies.

Advertisement