PDA

View Full Version : glutDisk Rotation problem...

glararan
12-05-2011, 02:00 PM
Hi, i'm beginner in OpenGL coding. I have one mini problem.
I create my own gluDisk.
http://www.sdilej.eu/pics/274a90360f9c46e2eaf94e095e0b6223.png

But i need it set to ground = horizontally(now is vertically)

i trying

glRotatef(90, x1, y1, z1);
But it isn't work... :(

carsten neumann
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.

glararan
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

glararan
12-06-2011, 06:56 AM
Sorry for next posts...

In 90 degress....some bug...now it must be horizontally...but isn't
http://www.sdilej.eu/pics/146bda9dc51708da54b9249706f874fc.png
http://www.sdilej.eu/pics/e9c0553222219e0f8fd094d07f547ee8.png

carsten neumann
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.

glararan
12-06-2011, 09:08 AM
My code:

{
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;
glPushMatrix();

glTranslatef(x1, y1, z1);
glRotatef(ax, rx, ry, 0.1);

glPopMatrix();
}
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 );