View Full Version : glutDisk Rotation problem...
12-05-2011, 02:00 PM
Hi, i'm beginner in OpenGL coding. I have one mini problem.
I create my own gluDisk.
But i need it set to ground = horizontally(now is vertically)
glRotatef(90, x1, y1, z1);
But it isn't work... :(
12-05-2011, 03:19 PM
But it isn't work..
That does not tell us how it is not working, making it difficult to decide what the problem could be.
What are the values of x1, y1, z1, in other words: around what axis are you rotating?
In general I'd say it is the right approach to have a function that generates geometry in a given way and then transform it into the needed position/orientation. However, since you are writing the function yourself, you should be able to create the vertices in the x/z plane (I'm guessing that is what you mean by ground) instead of the x/y plane.
12-06-2011, 04:57 AM
x1, y1, z1 = Position of Mouse... is for terrain mapping...
Look screen in first post...and after: http://www.sdilej.eu/pics/69721aa237608b423b635945d430e561.png
12-06-2011, 06:56 AM
Sorry for next posts...
In 90 degress....some bug...now it must be horizontally...but isn't
12-06-2011, 08:37 AM
Don't rotate around the mouse position vector. You probably want to translate to the mouse position to put the disk shape in the right position, but to orient it you need to rotate around an axis that puts it in the same coordinate plane as the ground.
To find that you need two pieces of information: the coordinate plane your function draws the disc shape in (looks like it's x/y, but can you confirm please?). The other is the plane you wan to rotate into, i.e. the plane that matches the ground at the mouse position.
If your ground is flat, it probably lies in a coordinate plane (x/z ?) itself and you just need to rotate around the x axis. If the ground is not flat you need the normal of the ground at the mouse position and then find a rotation that makes your disk shape's normal match the ground normal. Your favourite search engine should be able to find you a suitable algorithm to compute such a rotation.
12-06-2011, 09:08 AM
void renderDisk(float x1, float y1, float z1, float x2,float y2, float z2, float radius,int subdivisions,GLUquadricObj *quadric)
float vx = x2-x1;
float vy = y2-y1;
float vz = z2-z1;
//handle the degenerate case of z1 == z2 with an approximation
if( vz == 0.0f )
vz = .0001f;
float v = sqrt( vx*vx + vy*vy + vz*vz );
float ax = 57.2957795f*acos( vz/v );
if ( vz < 0.0f )
ax = -ax;
float rx = -vy*vz;
float ry = vx*vz;
//draw the quadric
glTranslatef(x1, y1, z1);
glRotatef(ax, rx, ry, 0.1);
gluDisk(quadric, radius - 0.25, radius + 5.0, subdivisions, 5);
void renderDisk_convenient(float x, float y, float z, float radius,int subdivisions)
//the same quadric can be re-used for drawing many objects
// Mouse opacity
glColor4f( 0.0f, 7.5f, 0.0f, 0.5f );
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.