Model orientation/rotation

961 views
Skip to first unread message

Sergio Flores

unread,
Oct 8, 2014, 3:18:07 PM10/8/14
to cesiu...@googlegroups.com
I'm trying to rotate a model around its Y axis.
All code that I see setting a model position uses Cesium.Transforms.eastNorthUpToFixedFrame()
I though about multiplying the result of that with a rotation matrix, but rotation matrices are 3x3 and this returns a 4x4 matrix.

So I tried using the following code:

var rotMat = Cesium.Matrix3.fromRotationY(this._rotation);           
targetObject.modelMatrix = Cesium.Matrix4.fromRotationTranslation(rotMat, this._position, this._transformMatrix);

"this._rotation" is in radians, however the rotations look completly wrong.
Is there another way to do this?

Patrick Cozzi

unread,
Oct 9, 2014, 7:47:31 AM10/9/14
to cesiu...@googlegroups.com
Hi Sergio,

Once you have the 4x4 rotation matrix, multiple it with the east-north-up matrix.  In your code, _transformMatrix is just getting overwritten.  See https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Core/Matrix4.js#L1271

Patrick

Sergio Flores

unread,
Oct 9, 2014, 9:50:20 AM10/9/14
to cesiu...@googlegroups.com
Thanks Patrick, I changed the code a bit and it now works.
However it seems there isnt any method to transform a Matrix3 to Matrix4, as required for the matrix mult.

This is my working code in case anyone needs:

            var rotation = Cesium.Matrix3.fromRotationZ(this._rotation);                       
            var rotMat = new Cesium.Matrix4(rotation[0], rotation[3], rotation[6], 0.0,
                               rotation[1], rotation[4], rotation[7], 0.0,
                               rotation[2], rotation[5], rotation[8], 0.0,
                                       0.0,         0.0,         0.0,           1.0);
                                      
            var posMat =  Cesium.Transforms.eastNorthUpToFixedFrame(this._position);                                      
           
            targetObject.modelMatrix = Cesium.Matrix4.multiply(posMat, rotMat, this._transformMatrix);            

Patrick Cozzi

unread,
Oct 9, 2014, 9:52:25 AM10/9/14
to cesiu...@googlegroups.com
Sergio,

Use fromRotationTranslation with Cesium.Cartesian3.ZERO for the translation parameter:


Patrick

--
You received this message because you are subscribed to a topic in the Google Groups "cesium-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cesium-dev/Yv49L4K2xeo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages