rotating vertices

Started by
20 comments, last by L. Spiro 10 years, 6 months ago


So rotate it around 0,0,0

Then scale it if needed

Then translate it to xyz, then it looks like it rotated around itself. Though the center of the vertices/the center of the spaceships model must be around 0,0,0, in terms of vertices.


well I tried rotating then translating but it does not move up or down.

Advertisement

I am reading the opengl superbible 4th ed. it is a really good read.

well I am only doing what tatuk was suggesting

Not exactly. I meant something like this:


void DrawShip(float x, float y, float z, float rotation) { // rotation in degrees
    glPushMatrix();

	float radr = 0.017453292519943295 * rotatation; // convert rotation from degrees to radians

        float temp = x;
	x = x * cosf( radr ) - y * sinf( radr );
	y = temp * sinf( radr ) + y * cosf( radr );

    // First translate to the wanted position
    glTranslatef(x, y, z);

    // Then render the shape of the object, you have already translated and rotated it to the right place
    glBegin(GL_LINE_LOOP);
    glVertex3f(0.0f,-0.25f,0.0f);
    glVertex3f(-0.25f,-0.5f,0.0f);
    glVertex3f(-0.5f,-0.5f,0.0f);
    glVertex3f(-0.0f,0.5f,0.0f);
    glVertex3f(0.5f,-0.5f,0.0f);
    glVertex3f(0.25f,-0.5f,0.0f);
    glVertex3f(0.0f,-0.25f,0.0f);
    glEnd();
    glPopMatrix();

well I tried the above code but it does not rotate, here is my code,

void DrawShip(GLfloat x,GLfloat y,GLfloat z,GLfloat rotation,GLfloat color)
{
glPushMatrix();
 
float radr = 0.017453292519943295 * rotation; // convert rotation from degrees to radians
 
float temp = x;
x = x * cosf( radr ) - y * sinf( radr );
y = temp * sinf( radr ) + y * cosf( radr );
 
// First translate to the wanted position
glTranslatef(x, y, z);
glColor3f(color,0.0f,0.0f);
 
// Then render the shape of the object, you have already translated and rotated it to the right place
glBegin(GL_LINE_LOOP);
glVertex3f(0.0f,-0.25f,0.0f);
glVertex3f(-0.25f,-0.5f,0.0f);
glVertex3f(-0.5f,-0.5f,0.0f);
glVertex3f(-0.0f,0.5f,0.0f);
glVertex3f(0.5f,-0.5f,0.0f);
glVertex3f(0.25f,-0.5f,0.0f);
glVertex3f(0.0f,-0.25f,0.0f);
glEnd();
glPopMatrix();
}

well what *does* happen? something's *got* to happen because you're changing the x,y,z position (by a rotation matrix) ... are you even supplying new `rotation` values? it has to gradually increase from 0->360

well I tried sponji code but it still does not rotate around a its central axis after I move it up or down.

That is because he did it in the wrong order.

void DrawShip(float x, float y, float z, float rotation) {
    glPushMatrix();

    // First rotate.
    glRotatef(rotation, 0.0f, 0.0f, 1.0f);

    // THEN translate.
    glTranslatef(x, y, z);

    // Then render the shape of the object, you have already translated and rotated it to the right place
    glBegin(GL_LINE_LOOP);
    glVertex3f(0.0f,-0.25f,0.0f);
    glVertex3f(-0.25f,-0.5f,0.0f);
    glVertex3f(-0.5f,-0.5f,0.0f);
    glVertex3f(-0.0f,0.5f,0.0f);
    glVertex3f(0.5f,-0.5f,0.0f);
    glVertex3f(0.25f,-0.5f,0.0f);
    glVertex3f(0.0f,-0.25f,0.0f);
    glEnd();
    glPopMatrix();
}
Case close problem solved stop using trigonometry manually.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

well spiro I did what you said and it moves up and down, but it still rotates around the center of the screen, but does not rotate around the center of the shape. sorry spiro but I am trying. I commend you, you are a very bright person.

Show your code.

I get the feeling you mixed what I posted with the math you have been trying to use.

The solution is my post, the whole post, and nothing but the post, so help me Todd.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

well I tried sponji code but it still does not rotate around a its central axis after I move it up or down.

That is because he did it in the wrong order.

What, in wrong order? I don't understand, when would he even want to use the order you suggested? First translate, then rotate.

But still, I bet the problem is somewhere else. I think he isn't moving the object correctly, and that should be done outside the render function.

Derp


stop using trigonometry manually

He needs to. He wants to rotate AROUND a point. Not at the centerpoint which glRotatef() would do. tongue.png

This topic is closed to new replies.

Advertisement