Author Topic: Rotation Issue  (Read 2759 times)

Offline AGP

  • quad
  • ******
  • Posts: 1515
    • View Profile
Rotation Issue
« on: February 01, 2012, 06:03:12 am »
Egon, I know you don't believe this, but somewhere jpct has a rotation bug (when I want to rotate an object around its center). Even Paul has said he's run into this in the past. My solution usually is to add a dummy object as follows. But in this case, even this is failing me.

Code: [Select]
Object3D dummyCenter = Object3D.createDummyObj();
dummyCenter.addChild(groundModel);
while (whatever) {
      userInput();
      draw();//DRAW THE FRAME
      follow();//POSITION THE CAMERA
      dummyCenter.rotateAxis(dummyCenter.getYAxis(), .02f);//groundModel.rotateY() DOESN'T WORK EITHER AND groundModel IS AT SimpleVector.ORIGIN (THEN TRANSLATED DOWN ON Y ONLY)

Offline AGP

  • quad
  • ******
  • Posts: 1515
    • View Profile
Re: Rotation Issue
« Reply #1 on: February 01, 2012, 06:21:11 am »
By the way, doing
Code: [Select]
groundModel.setRotationPivot(SimpleVector.ORIGIN);
moveTo(groundModel, SimpleVector.ORIGIN);
groundModel.translate(0, 350, 0);

then
groundModel.rotateY(x, y, z);
also doesn't solve it.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: Rotation Issue
« Reply #2 on: February 01, 2012, 07:13:02 am »
You are right...i don't believe this. Rotations are well defined matrix operations. I don't see what should be wrong with them. Also, "doesn't work" is very vague...what should it do and what does it do instead?

Offline AGP

  • quad
  • ******
  • Posts: 1515
    • View Profile
Re: Rotation Issue
« Reply #3 on: February 01, 2012, 03:14:13 pm »
I know I'm right because we've had this discussion before. It doesn't spin around its own axis as it should.

Offline AGP

  • quad
  • ******
  • Posts: 1515
    • View Profile
Re: Rotation Issue
« Reply #4 on: February 01, 2012, 03:16:23 pm »
I think the problem with this discussion is semantics: the problem is noticeable on rotations, but it is not on the rotation itself. It's likely on the position of the pivot (and calcCenter() doesn't help). Then again, if it were just the object's pivot, rotating the dummy would probably do it.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: Rotation Issue
« Reply #5 on: February 01, 2012, 03:27:43 pm »
Even the dummy has pivot and a position, so setting the dummy at the position of the actual pivot wouldn't change anything. I've still no idea what you want you to do and what the actual outcome is. IF there is some problem, i need a test case. Then again, almost every application is a test case and i've never seen anything go wrong with this...

Offline Marlon

  • int
  • **
  • Posts: 74
    • View Profile
    • Forgotten Elements Action MMORPG
Re: Rotation Issue
« Reply #6 on: February 01, 2012, 03:28:56 pm »
I don't get your problem here.
1. What do you want to achieve? Do you want to rotate around the Y Axis?
2. I had similar problems with the PivotPoint. While debugging my program the PivotPoint was always set to (0,0,0). Sometimes I get confused with object and world space and different matrixes.
3. When I use rotateY() on a desired object, it works. When I want to rotate with an absolute value I use object3D.clearRotation() and then object.rotateY().
www.forgottenelements.com
Free Action JAVA MMORPG

Offline AGP

  • quad
  • ******
  • Posts: 1515
    • View Profile
Re: Rotation Issue
« Reply #7 on: February 01, 2012, 03:46:32 pm »
I didn't set the position of the dummy, I just created one at the world origin and added the object to be rotated as its child. I want an object that rotates around its center. The dummy solution usually works (if I recall, it was Paul who suggested it to me), but not in this case.

Marlon:
1) I want to rotate an object along the Y axis around its center. Most of the time that's not a problem, but it sometimes is.
2) This isn't the case here.
3) Also not the case, as the object has to contantly spin.

Offline Marlon

  • int
  • **
  • Posts: 74
    • View Profile
    • Forgotten Elements Action MMORPG
Re: Rotation Issue
« Reply #8 on: February 01, 2012, 03:53:32 pm »
1) I want to rotate an object along the Y axis around its center. Most of the time that's not a problem, but it sometimes is.
...
3) Also not the case, as the object has to contantly spin.

I think this is the case. If you want to constantly spin your object (like a wheel), just call Object3D.rotateY(small float value) every frame and watch the wheel spinning.

Sorry, when I totally miss the point, but with the help of this method I created spinning objects with success.
www.forgottenelements.com
Free Action JAVA MMORPG

Offline AGP

  • quad
  • ******
  • Posts: 1515
    • View Profile
Re: Rotation Issue
« Reply #9 on: February 01, 2012, 03:59:15 pm »
I refer you to my 1.

Egon, would you like a test case?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: Rotation Issue
« Reply #10 on: February 01, 2012, 05:01:56 pm »
Yes, but i'm not sure if this isn't just a case of false expectations. The rotation pivot (or the center) of any mesh as calculated by build isn't guaranteed to be the center that you have in mind. It's based on a simple calculation that averages the positions of all vertices in a mesh. For the sphere, this is almost perfect. For more complex objects, this might be good enough but not perfect.

Offline AGP

  • quad
  • ******
  • Posts: 1515
    • View Profile
Re: Rotation Issue
« Reply #11 on: February 01, 2012, 05:08:51 pm »
You know what the weirdest thing is? This problem happened when I stopped rotating particular object (an OBJ file) into the X/Y plane (remember that game I made in which, because of my inexperience some six or seven years ago and 3DS's orientation, everything was done in the X/Y plane?). I'm e-mailing you the test case now.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: Rotation Issue
« Reply #12 on: February 01, 2012, 05:46:38 pm »
It's really simply to solve. Don't use any dummy objects and stuff, just rotateY around the origin and all is fine:

Code: [Select]
                groundModel.setRotationPivot(SimpleVector.ORIGIN);
moveTo(groundModel, SimpleVector.ORIGIN);
keepGoing = true;
while (keepGoing) {
draw();
groundModel.rotateY(-.02f);
try {
Thread.sleep(10);
} catch (InterruptedException e) {
System.err.println("Trouble sleeping: " + e.getMessage());
}
}


However, using this model, it doesn't look 100% right if you are taking the seats as a reference (it does look right if you use that structure in the center though), simply because the seats are not correctly aligned with center structure. While the center is point symmetric, the seats are not. So even if everything is setup correctly, the seats move on some ellipsoid path simply because they form an ellipsoid and not circle.

Offline AGP

  • quad
  • ******
  • Posts: 1515
    • View Profile
Re: Rotation Issue
« Reply #13 on: February 01, 2012, 05:50:10 pm »
If you looked at my code, you saw that rotateY was there. The center piece was rotating out of control for me (I don't really care about the seats' rotation as I know the model is asymmetrical).

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: Rotation Issue
« Reply #14 on: February 01, 2012, 06:13:32 pm »
No, you had some rotation around the dummy's y-axis...i didn't really follow that code. Always keep in mind that even when using a dummy (which isn't needed here), the rotation pivot of the child object still has influence on the rotations of that object. Rotations are a really good example of garbage-in/garbage-out...but you can be pretty sure that the code itself that does them is correct. After all, in most cases it's done by the GPU anyway.