• Create Account

### #ActualJevi

Posted 25 October 2012 - 07:58 PM

to do rotations, you have to translate the object to its rotational origin, called a PIVOT position, then rotate it there, and translate it back!
if your object is a box created at (0,0) and all the way to (1,1), you have to translate it to (-0.5, -0.5) to rotate it around itself
however, if your box was created from (-0.5, -0.5) to (0.5, 0.5) you can rotate it immediately, because its rotational origin is now (0, 0) from the start, if you wanted to rotate it around itself!

3ds max (or any other 3d CAD) is a great tool to visualize how this works

to do the same thing with your model, you need to know its dimensions, and then its half-sizes, then translate it backwards so that the object is positioned with (0, 0) at the center of the object, then rotate it there (if that's what you wanted to do)

from looking at the ship creation code from the link.. its hard for me to understand how exactly it is created, except to say i never would be doing it that way myself :S
i'm sure theres some logic to it though!

Ok so now the rotation works correctly. I translate back to the starting x,y rotate it there but how do i move the ship to where the current x,y are?

And yes my code may be a little confusing but its hard to stay true to object oriented programming when all the OGL tutorials I have found don't seem to code with that convention...

This is my modified code

@Override
public void render(Graphics g)
{
glPushMatrix();
glBegin(GL_POINTS);
glVertex2f(x, y);
glEnd();
glTranslatef(startx, starty, 0);
glRotatef(angle, 0, 0, 1);
glTranslatef(-startx, -starty, 0);
g.drawLines();
glPopMatrix();
}


### #2Jevi

Posted 25 October 2012 - 07:54 PM

to do rotations, you have to translate the object to its rotational origin, called a PIVOT position, then rotate it there, and translate it back!
if your object is a box created at (0,0) and all the way to (1,1), you have to translate it to (-0.5, -0.5) to rotate it around itself
however, if your box was created from (-0.5, -0.5) to (0.5, 0.5) you can rotate it immediately, because its rotational origin is now (0, 0) from the start, if you wanted to rotate it around itself!

3ds max (or any other 3d CAD) is a great tool to visualize how this works

to do the same thing with your model, you need to know its dimensions, and then its half-sizes, then translate it backwards so that the object is positioned with (0, 0) at the center of the object, then rotate it there (if that's what you wanted to do)

from looking at the ship creation code from the link.. its hard for me to understand how exactly it is created, except to say i never would be doing it that way myself :S
i'm sure theres some logic to it though!

Ok so now the rotation works correctly. I translate back to the starting x,y rotate it there but how do i move the ship to where the current x,y are?

This is my modified code

@Override
public void render(Graphics g)
{
glPushMatrix();
glBegin(GL_POINTS);
glVertex2f(x, y);
glEnd();
glTranslatef(startx, starty, 0);
glRotatef(angle, 0, 0, 1);
glTranslatef(-startx, -starty, 0);
g.drawLines();
glPopMatrix();
}


### #1Jevi

Posted 25 October 2012 - 07:53 PM

to do rotations, you have to translate the object to its rotational origin, called a PIVOT position, then rotate it there, and translate it back!
if your object is a box created at (0,0) and all the way to (1,1), you have to translate it to (-0.5, -0.5) to rotate it around itself
however, if your box was created from (-0.5, -0.5) to (0.5, 0.5) you can rotate it immediately, because its rotational origin is now (0, 0) from the start, if you wanted to rotate it around itself!

3ds max (or any other 3d CAD) is a great tool to visualize how this works

to do the same thing with your model, you need to know its dimensions, and then its half-sizes, then translate it backwards so that the object is positioned with (0, 0) at the center of the object, then rotate it there (if that's what you wanted to do)

from looking at the ship creation code from the link.. its hard for me to understand how exactly it is created, except to say i never would be doing it that way myself :S
i'm sure theres some logic to it though!

Ok so now i translate back to the starting x,y rotate it there but how do i move the ship to where the current x,y are?

This is my modified code

@Override
public void render(Graphics g)
{