www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: AGP on February 01, 2012, 06:03:12 am

Title: Rotation Issue
Post by: AGP 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)
Title: Re: Rotation Issue
Post by: AGP 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.
Title: Re: Rotation Issue
Post by: EgonOlsen 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?
Title: Re: Rotation Issue
Post by: AGP 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.
Title: Re: Rotation Issue
Post by: AGP 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.
Title: Re: Rotation Issue
Post by: EgonOlsen 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...
Title: Re: Rotation Issue
Post by: Marlon 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().
Title: Re: Rotation Issue
Post by: AGP 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.
Title: Re: Rotation Issue
Post by: Marlon 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.
Title: Re: Rotation Issue
Post by: AGP on February 01, 2012, 03:59:15 pm
I refer you to my 1.

Egon, would you like a test case?
Title: Re: Rotation Issue
Post by: EgonOlsen 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.
Title: Re: Rotation Issue
Post by: AGP 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.
Title: Re: Rotation Issue
Post by: EgonOlsen 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.
Title: Re: Rotation Issue
Post by: AGP 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).
Title: Re: Rotation Issue
Post by: EgonOlsen 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.
Title: Re: Rotation Issue
Post by: AGP on February 01, 2012, 07:13:14 pm
Look at the commented-out stuff, which I left there on purpose. I'm going to move on to the Overlay thing and get back to this later. :- ) I'm sending you a test case soon.
Title: Re: Rotation Issue
Post by: EgonOlsen on February 01, 2012, 07:25:06 pm
Maybe you never had the working combination by accident in with all these different approaches. That's why i simply scratched the code and started new as simple as it gets...which works fine.
Title: Re: Rotation Issue
Post by: AGP on February 01, 2012, 07:33:46 pm
That was new, man, I just wrote it. I did try with rotateY() alone. I will send you a video with the e-mail about the Overlay.
Title: Re: Rotation Issue
Post by: EgonOlsen on February 01, 2012, 09:35:19 pm
Please try this jar to see if it fixes the Overlay problem: http://jpct.de/download/beta/jpct.jar (http://jpct.de/download/beta/jpct.jar)

It seems to be caused by camera matrices that are not 100% orthogonal, which might be the case due to the interpolation and some rounding/accuracy errors with floating point values. I think i've fixed this now by using another matrix invert method in the Overlay, but i don't get how such small differences in the matrix' values might have had such an impact. Anyway, give it a try and tell me if it works.

Edit: Wrong stuff removed...
Title: Re: Rotation Issue
Post by: AGP on February 01, 2012, 09:41:27 pm
But I'm using your KeyMapper on the gameloop. Is there some leftover mouse stuff?
Title: Re: Rotation Issue
Post by: EgonOlsen on February 01, 2012, 09:43:53 pm
But I'm using your KeyMapper on the gameloop. Is there some leftover mouse stuff?
No, i'm an idiot...never mind, all is well... ;)
Title: Re: Rotation Issue
Post by: AGP on February 01, 2012, 09:44:46 pm
: -)

I think you've fixed as I haven't seen the problem in a while. Thanks a lot.