Can't Rotate an Object By Its Center

Started by AGP, August 11, 2009, 12:05:01 AM

Previous topic - Next topic

AGP

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?


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());}
}

paulscode

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.

paulscode

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.

AGP

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.

AGP

Awesome, Paul, the dummy thing worked. Thanks a lot.

EgonOlsen

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.

AGP

That wasn't the initial problem, that was one attempted solution. Wasn't even the first attempt either.