How to get a 3D model moving by CZML streaming?

Hi guys!

I have the following script in a html file:

    source.addEventListener("czml_message", function(event) {
        var jsonObject
        jsonObject = JSON.parse(;
        jsonObject = null;
        }, false);

It process everything from a CZML stream and shows in a Cesium viewer. One of this "everything" was a picture/billboard and worked fine only updating the position. Now I changed to a 3D model vehicle. Of course it is moving like a crab. And I know I must use some transform to fix it. But as I have the data coming from a CZML stream (therefore, no model entity) and CZML has no support for orientation yet (documentation says "TODO"), how can I do in order to have it updating position/orientation each event (50ms)?

I was thinking in create a entity with add method and, then, refers to the model each event. Is my thinking right? Or does it have a best way to do that?

CZML absolutely supports orientation and there’s no reason you can’t do what you want. What does your CZML look like? Is this some sort of realtime feed or simulation?

Hi Mathew!

I understood the note "TODO" at orientation descrpition ( as if the parameter is not supported. After see you message I conclude that only the comments must be written :slight_smile:

Yes, it is a real time feed. And actually I moved from 50ms to 120ms because I noted this update rate is better regarding the flickering.

Thank you for you answer. I will implement the orientation in czml and I will let you know about the results.

Thank you

Hi Matthew

I am still stuck on this. I just was able to start a code port to "C" from what Jonathan Carmack wrote in the last reply in!searchin/cesium-dev/pojo/cesium-dev/rHzL4jD4qfw/Tabu6FNijY0J

But I stuck on these lines:

UnitQuaternion yawQuaternion = new UnitQuaternion(Math.cos(longOffset),0.0,0.0,Math.sin(longOffset));
UnitQuaternion pitchQuaternion = new UnitQuaternion(Math.cos(latOffset),-Math.sin(latOffset),0.0,0.0);
return UnitQuaternion.multiply(yawQuaternion, pitchQuaternion);

Where is roll angle in these lines?
I already read the wikipedia about quaternions, but I didn't figured out how to generate the unit quaternion for CZML.

So, my questions still are:

1 - What should I store in axes 'field' in CZML?
2 - How to generate unitQuaternion field using Lon, lat, elevation, roll, pitch and yaw angles?

Do you have any suggestion or example?

Thank you

    1. No need to an axes field yet, orientation is always interpreted as earth fixed at this time.
  1. I don’t have a good canned answer, but this thread might help you:

Eventually we will support heading/pitch/roll directly from CZML, I just haven’t had any time to work on it recently.


I am implementing this software in C language and sending CZML through server-sent events. Now I can convert from Euler angles to unitQuaternion and pass to CZML. Even doing that the model is not properly oriented. Then I checked the thread you suggested and I could see others quaternions and transformations in order to take the current frame orientation and, then, rotate the system (Post 10/30/2014 by André Santos). Am I right? Should I do the same?

Thank you!

//Pitch->X axis, Yaw->Y axis (heading), Roll->Z axis
static void unitQuaternion(tF64 fPitch, tF64 fYaw, tF64 fRoll, tF64 *Quat)
// tF64 Quat[4]; /* Quat[0] -> X
// Quat[1] -> Y
// Quat[2] -> Z
// Quat[3] -> W */

    const float fSinPitch = sin(fPitch * 0.5);
    const float fCosPitch = cos(fPitch * 0.5);
    const float fSinYaw = sin(fYaw * 0.5);
    const float fCosYaw = cos(fYaw * 0.5);
    const float fSinRoll = sin(fRoll * 0.5);
    const float fCosRoll = cos(fRoll * 0.5);
    const float fCosPitchCosYaw = fCosPitch * fCosYaw;
    const float fSinPitchSinYaw = fSinPitch * fSinYaw;

    Quat[0] = fSinRoll * fCosPitchCosYaw - fCosRoll * fSinPitchSinYaw;
    Quat[1] = fCosRoll * fSinPitch * fCosYaw + fSinRoll * fCosPitch * fSinYaw;
    Quat[2] = fCosRoll * fCosPitch * fSinYaw - fSinRoll * fSinPitch * fCosYaw;
    Quat[3] = fCosRoll * fCosPitchCosYaw + fSinRoll * fSinPitchSinYaw;

Hello all!
Has someone already worked with this?


2 - How to generate unitQuaternion field using Lon, lat, elevation, roll, pitch and yaw angles?

If your model rotate but looks wrong angles, maybe you should consider your reference frame in the conversion from roll pitch yaw, into quaternion. like using “Cesium.Transforms.eastNorthUpToFixedFrame()” ?

Hi Narco, Matthew and everybody.

I wrote in C all the code in the snippet suggested by Matthew in

from André Santos post in 10/30/2014. All the calculations work fine. But in CZML we don't have "modelMatrix" property. Then I call

    quaternion_fromRotationMatrix(&totalRotation[0], &finalQuaternion);
    getUnitQuaternion(&finalQuaternion, &finalQuaternion);

and pass finalQuaternion to the CZML orientatioin field. I already tried others combinations, but with no success.

Do you have any idea where is my mistake?

Check the files:

Can you share an example of the final result. If not publicly you can send directly with me.

Hi Matthew, Narco, Mike and everyone.

Thank you for the support and ideas. And sorry delayed feedback.

I fixed my code. There was a bug in one of the functions. Now I have everything running. And I would like to share the results so that it can be useful for others.

See the attached files. They are a C version of this approach:

The ‘positionModel’ function receives the model position structure and outputs the quaternion used in CZML orientation.

Thank you very much!

transform.c (23.5 KB)

transform.h (2.83 KB)

glad to hear you figured it out and thank you for sharing