Author Topic: Can't Rotate an Object By Its Center  (Read 3675 times)

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Can't Rotate an Object By Its Center
« on: August 11, 2009, 12:05:01 am »
I tried everything both in MAX and in my program. The 3dsmax pivot is at the very center of the object and I get the desired effect on MAX, but Object3D.rotateAxis(Object3D.getZAxis(), float) simply won't rotate my model exactly in its center. I even tried writing a VertexController to get the objectspace center then apply to that the object's world transformation and set the object's new center, but that failed as well! Is it my code or is it jpct's?

Code: [Select]
currentMission.groundModel.build();
SimpleVector newCenter = new VertexController(currentMission.groundModel).getCenter();
newCenter.matMul(currentMission.groundModel.getWorldTransformation());
currentMission.groundModel.setCenter(newCenter);

// camera.setPosition(newCenter);
// camera.moveCamera(Camera.CAMERA_MOVEOUT, 10f);

while (currentMission.missionName.equals("Mission Briefing Room")) {
keyboardAndJoystick();
draw();
currentMission.groundModel.rotateAxis(currentMission.groundModel.getZAxis(), .02f);

//       currentMission.groundModel.rotateZ(.02f);
// awtGlCanvas.getGraphics().drawLine(this.getWidth()/2, 0, this.getWidth()/2, this.getHeight());
// awtGlCanvas.getGraphics().drawLine(0, this.getHeight()/2, this.getWidth(), this.getHeight()/2);
if (!paused) {}
try {
Thread.sleep(50);
}
catch (InterruptedException e) {System.err.println("Trouble sleeping: "+e.getMessage());}
}

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Can't Rotate an Object By Its Center
« Reply #1 on: August 11, 2009, 01:33:54 am »
I have also had numerous problems with pivots (mostly with mult-object models, though).  The thing that often helps is to ensure that both the object's center (or the part you want to rotate around) is at the origin in your Max scene, and then with "Affect Pivot Only" on, move the pivot to the origin as well (must also be done for each sub-object if there are more than one).  I have had a few cases where this didn't fix the pivot problem, though and I had to tinker around forever to try and make it work.  Sounds like you might have one of those cases on your hands.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Can't Rotate an Object By Its Center
« Reply #2 on: August 11, 2009, 01:46:03 am »
If all else fails, you could resort to the "child of a dummy object" method.  That's where you make your object the child of a dummy object, translate it, then rotate the dummy instead of the child.  I've had to use this method a couple of times.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Can't Rotate an Object By Its Center
« Reply #3 on: August 11, 2009, 03:00:03 am »
Mine used to have multiple parts, but I attached everything together to try to avoid it. It's at the origin in MAX, and I reset XForm. I'll try the child thing and write back, thanks for the suggestion.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Can't Rotate an Object By Its Center
« Reply #4 on: August 11, 2009, 03:04:29 am »
Awesome, Paul, the dummy thing worked. Thanks a lot.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Can't Rotate an Object By Its Center
« Reply #5 on: August 11, 2009, 11:05:04 am »
Do whatever works for, but keep in mind that setCenter DOESN'T set the rotation pivot. I guess that this caused your initial problem. If you want to set the rotation pivot don't use setCenter but setRotationPivot instead. However, if it works with the dummy object, that's fine too.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Can't Rotate an Object By Its Center
« Reply #6 on: August 11, 2009, 07:59:19 pm »
That wasn't the initial problem, that was one attempted solution. Wasn't even the first attempt either.