Author Topic: rotation problem (it moves)  (Read 11250 times)

Offline theFALCO

  • byte
  • *
  • Posts: 39
    • View Profile
rotation problem (it moves)
« on: December 12, 2006, 08:24:21 pm »
I'm rotating my cube like so:
Code: [Select]
               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?

Offline cyberkilla

  • float
  • ****
  • Posts: 413
    • View Profile
    • http://futurerp.net
rotation problem (it moves)
« Reply #1 on: December 12, 2006, 08:43:39 pm »
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

Offline theFALCO

  • byte
  • *
  • Posts: 39
    • View Profile
rotation problem (it moves)
« Reply #2 on: December 12, 2006, 08:53:04 pm »
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)

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
rotation problem (it moves)
« Reply #3 on: December 12, 2006, 08:53:56 pm »
Hee hee, cyberkilla is right. Translating is when you want to move.

Offline cyberkilla

  • float
  • ****
  • Posts: 413
    • View Profile
    • http://futurerp.net
rotation problem (it moves)
« Reply #4 on: December 12, 2006, 09:02:46 pm »
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

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
rotation problem (it moves)
« Reply #5 on: December 12, 2006, 09:07:28 pm »
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

Offline cyberkilla

  • float
  • ****
  • Posts: 413
    • View Profile
    • http://futurerp.net
rotation problem (it moves)
« Reply #6 on: December 12, 2006, 09:12:54 pm »
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

Offline theFALCO

  • byte
  • *
  • Posts: 39
    • View Profile
rotation problem (it moves)
« Reply #7 on: December 12, 2006, 09:48:32 pm »
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();

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
rotation problem (it moves)
« Reply #8 on: December 12, 2006, 09:56:25 pm »
I am very clueless on the reply, but anyway! I think that this may help?

Object3D.rotateMesh()
Quote
Rotates 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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
rotation problem (it moves)
« Reply #9 on: December 12, 2006, 09:57:16 pm »
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.

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
rotation problem (it moves)
« Reply #10 on: December 12, 2006, 10:02:16 pm »
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..

Offline theFALCO

  • byte
  • *
  • Posts: 39
    • View Profile
rotation problem (it moves)
« Reply #11 on: December 13, 2006, 03:57:24 pm »
oh, yes I see it in the FPS example
Code: [Select]
     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

Offline theFALCO

  • byte
  • *
  • Posts: 39
    • View Profile
rotation problem (it moves)
« Reply #12 on: December 13, 2006, 08:29:12 pm »
nope, still have problems  :(

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
rotation problem (it moves)
« Reply #13 on: December 13, 2006, 10:23:04 pm »
Of which kind?

Offline theFALCO

  • byte
  • *
  • Posts: 39
    • View Profile
rotation problem (it moves)
« Reply #14 on: December 14, 2006, 07:43:11 pm »
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: