Rajawali / RajawaliVuforia

Rajawali + Vuforia Augmented Reality
Other
227 stars 108 forks source link

Wrong rotation with negative scale objects #36

Closed efrencampillo closed 9 years ago

efrencampillo commented 10 years ago

I detected a new issue, for some 3d models, example md2, that are loaded in Y negative axis, you need to sale it with Y=-1 to see it right. but when you put the orientation to this kind of objects that are in negative scale, the rotation gets wrong results. I debugged this into the library, and found the wrong result in method Object3d.render()->calculateModelMatrix(parentMatrix);

in this method Object3D i found: mMMatrix.identity().translate(mPosition).scale(mScale).multiply(mRotationMatrix); when mScale contains a negative value, gets wrong directions.

i think this can be solved changing the loaded axis, to not modify the operations, because this works fine when are positive scales. i want to avoid the negative scales, but objects are loaded in y axis inverted.

has anyone an idea how to fix it?

ToxicBakery commented 10 years ago

Why not pre invert the models on the Y? I believe this is actually an OpenGL issue with the coordinate system but it may be an issue with the particular parser you are using.

efrencampillo commented 10 years ago

unfortunally, models are shared with other platforms, Android receives the same model and i cannot modify the models. I inverted the scale in Y with mymodel.setScale(1,-1,1); right when load the object with loaderMD2, but after put this, orientation rotates wrong; if i leave the scale in positive values, it rotates fine, but model seems wrong. thats is because i ask about change the coordinate system to load with correct Y axis, i'm using v0.9 tag rajawali lib.

ToxicBakery commented 10 years ago

Then you may want to alter the parser being used to store the inverse of the Y coordinates which should be pretty straight forward. I assume it is the OBJ parser?

ToxicBakery commented 10 years ago

I'm a bit confused, LoaderMD2 is part of Rajawali trunk and not v0.9.

As a shortcut, I believe you would get the desired result if you wrap the object in an Object3D instance.

parsedModel.setScaleY(-1);
BaseObject3D modelContainer = new BaseObject3D();
modelContainer.isContainer(true);
modelContainer.addChild(parsedModel);

Something like that should allow you to invert the model and maintain the desired rotation I believe. If it is still backwards, this would allow you to pre rotate the internal model to the proper orientation and apply all future orientation changes to the container.

efrencampillo commented 10 years ago

that was i made originaly, setScale(), and setScaleY() only chage the mScale Vector, that is used to multiply by rotation matrix, and that cause the wrong rotation. I'll try to change the axis in LoaderMD2.java:222 : float scaleY = is.readFloat();

i'm thinking that this part can change the values without the scale.

efrencampillo commented 10 years ago

that fix, don't solve my problem, it load the object in right way, but when i put in orientation from vuforia, it puts at inverse direction, in place that see the object from far to you, you see the object from you to far.

is there any way to change that orientation? only in z axis?

MasDennis commented 9 years ago

Closing this issue because it is a v0.9 issue which isn't supported in RajawaliVuforia.