rotation problem (it moves)

Started by theFALCO, December 12, 2006, 08:24:21 PM

Previous topic - Next topic

theFALCO

I'm rotating my cube like so:
               if(right) {
                   cube.rotateY(0.01f);
                   cube.translate(cube.getYAxis());
               }


when I rotate it, it moves down (while rotating), and when I rotate it the similar way with the X axis it moves right (while rotating).

any idea why it acts like that and how to fix it?

cyberkilla

If you just want it to rotate, I am pretty sure you dont need
the last line of code.

Maybe I don't get what your trying to do;)
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

theFALCO

yes but then it rotates very strange... from the begining while rotating up/down it behaves as it shoul - it changes it's pitch, when i turn it 90 deg to the right/left then up/down makes it to roll (become like up side down)

Mizuki Takase

Hee hee, cyberkilla is right. Translating is when you want to move.

cyberkilla

So it rotates but not around its center of origin?
Is this the problem?
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

Mizuki Takase

Object3D does have a function called setOrigin(SimpleVector)... Maybe you need to do that first... I am not sure~~ Maybe cube.setOrigin(new SimpleVector(0,0,0)); But then again, I always thought that this origin should be the default...

[edit]Oh right! I remember looking at your code, you did change the origin of your cube after creation... Maybe you should remove that line from your code and see what happens? I still do not know why you would have that problem since you did set it to 0,0,0

cyberkilla

Well, im guessing thats the problem.

When the object is created, the center of the bounding box appears to be set
as the origin.
Thats the assumption im working on anyway;)
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

theFALCO

i have created 4 balls: up, down, left and right to visualize it better

what i see is that it seems like it's rotating around the same unchangable axis... what I mean is when the cube rotates, the pivot, axis or whatever it is, doesn't (the cube rotates using some global axis, not it's local) so when it becomes "from the left side" it is rotated as thought it's side was the front... or like so

maybe I forgot something like: cube.recalculateThePivotAndOtherRotationStuffSoThatYouDontHaveProblemsRotatingThisCubeThatYouWasSoHappyAbout();

Mizuki Takase

I am very clueless on the reply, but anyway! I think that this may help?

Object3D.rotateMesh()
QuoteRotates the raw mesh data using the rotation matrix specified for this object.

You use that after you set the rotation.. There is also a translateMesh(), but that's out of topic...

EgonOlsen

First of all, there's a method called setRotationPivot() to set the...rotation pivot  :wink: By default, this is set to the calculated center of the object, which is the average of its vertices. For a cube, it's the center.

The rotate?-methods are rotating around a fixed axis, that's correct. If you don't want that, you may use the rotateAxis()-method instead and feed it with the axis you want to rotate around. That should work.

Mizuki Takase

The god has spoken and now I am enlightened... I know that someday, whenever I get serious with game programming, I will need to know that... Thanks..

theFALCO

oh, yes I see it in the FPS example
     if (left) {
        camera.rotateAxis(camera.getBack().getYAxis(), -TURN_SPEED);
        playerDirection.rotateY(-TURN_SPEED);
     }
     if (right) {
        camera.rotateAxis(camera.getBack().getYAxis(), TURN_SPEED);
        playerDirection.rotateY(TURN_SPEED);
     }

I'll try it

theFALCO


EgonOlsen


theFALCO

this is the starting position:

this shows that from this orientation the up/down rotation is good:

but when I turn left (the ball is one of those four balls which I added for better orientation):

the up/down rotation looks like this: