Rotation Issue

Started by AGP, February 01, 2012, 06:03:12 AM

Previous topic - Next topic

AGP

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.


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)

AGP

By the way, doing

groundModel.setRotationPivot(SimpleVector.ORIGIN);
moveTo(groundModel, SimpleVector.ORIGIN);
groundModel.translate(0, 350, 0);

then
groundModel.rotateY(x, y, z);

also doesn't solve it.

EgonOlsen

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?

AGP

I know I'm right because we've had this discussion before. It doesn't spin around its own axis as it should.

AGP

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.

EgonOlsen

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...

Marlon

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

AGP

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.

Marlon

Quote from: AGP on February 01, 2012, 03:46: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

AGP

I refer you to my 1.

Egon, would you like a test case?

EgonOlsen

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.

AGP

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.

EgonOlsen

It's really simply to solve. Don't use any dummy objects and stuff, just rotateY around the origin and all is fine:


                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.

AGP

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).

EgonOlsen

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.