czml orientation model from php

Hi,

I currently working in an application where I’m using CZML in streaming. This CZML is wrote in php and the problem that I have is when I try to orientate a model using unitQuaternion.

I used the following function in php to transform pitch roll and yaw in quaternions:

function toQuaternion($pitch, $roll, $yaw){

$t0 = cos($yaw * 0.5);

$t1 = sin($yaw * 0.5);

$t2 = cos($roll * 0.5);

$t3 = sin($roll * 0.5);

$t4 = cos($pitch * 0.5);

$t5 = sin($pitch * 0.5);

$q=;

$q = $t0 * $t2 * $t4 + $t1 * $t3 * $t5;//w

$q = $t0 * $t3 * $t4 - $t1 * $t2 * $t5;//x

$q = $t0 * $t2 * $t5 + $t1 * $t3 * $t4;//y

$q = $t1 * $t2 * $t4 - $t0 * $t3 * $t5;//z

    return $q;

}

``

but the resultant orientation is very random… and I don’t know how to solve it.

Thank you so much.

Hi there,

Your computation looks correct to me (assuming that your array syntax is correct, since I don’t use php – do you need to index?). So I’d say the issue is either with the php, or in how you write the resultant values to CZML. Here’s an example: https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/Orientation

Hope that helps,

  • Rachel

Yes, you are right, but I tried to put the values in the example X, Y, Z, W instead of the W, X, Y, Z and the result is equally random. In fact I only want rotate the yaw, but it seems rotate pitch roll and yaw. I think the problem could be that cesium generate this orientation related to the reference frame of the earth or something like this because the final orientation change if the model change his latitude and longitude … I do not know but I’m very lost .

Hi there,

Perhaps your results are just not in the format that Cesium expects? For instance, you could try inverting your results. Since your formula looks correct, I would recommend the next debugging step is compare the results of your computation to the Cesium euler to quaternion computation and see if you get the same output. Here’s a modification of a sandcastle example that prints the heading pitch roll then equivalent quaternion: http://cesiumjs.org/Cesium/Apps/Sandcastle/?src=Hello%20World.html&label=Showcases&gist=0b6b30d548db783ac3173473afe428b5

See line 125 onward.

Hope that helps!

  • Rachel

Well,

first of all, thank you for your example.

The next debugging step I did was take a czml sandcastle example and modify it like this:

/* degrees

heading :90

pitch : 0

roll : 0

*/

/* radians

heading :1.570796326794898

pitch :0

roll :0

*/

var x = 0;

var y = 0;

var z =-0.707106781186548;

var w = 0.7071067811865471;

var czml = [{

"id" : "document",

"name" : "CZML Model",

"version" : "1.0"

}, {

"id" : "aircraft model",

"name" : "Cesium Air",

 "orientation": {

    "unitQuaternion": [ x, y, z, w ]

},

"position" : {

    "cartographicDegrees" : [-77, 37, 10000]

},

"model": {

    "gltf" : "../../SampleData/models/CesiumAir/Cesium_Air.glb",

    "scale" : 2.0,

    "minimumPixelSize": 128

}

}];

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var dataSourcePromise = viewer.dataSources.add(Cesium.CzmlDataSource.load(czml));

dataSourcePromise.then(function(dataSource){

viewer.trackedEntity = dataSource.entities.getById('aircraft model');

}).otherwise(function(error){

window.alert(error);

});

``

the heading, roll and pitch was taken from your example with its x,y,z,w quaternions from the same example.

The result is the same that I get in my project. The orientation of the model is not the expected one.

Is very frustrating…

Thank you for your support

For the first time on cesium-dev, I think I can help. Well, actually the help comes by way of Scott Hunter and is therefore reliable.

There are two places to use unitQuaternion in Cesium.

The first, as you are doing here, is by way of the POSITION property which uses the earth fixed axis. So you will see the airplane stand straight-up on its tail at the equator and lie flat at the poles.

The second is through the NODE TRANSFORMATION property which uses the model's east-north-up axis for its rotation. Look here for the proper syntax (https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/Model). Or here is a snippet of code for sandcastle using Cesium-Man:

var czml = [{
    "id" : "document",
    "name" : "CZML Model",
    "version" : "1.0",
    "clock": {
        "interval": "2017-01-19T00:00:00Z/2017-01-19T23:59:59Z",
    }
}, {
    "id" : "model",
    "position" : {
        "cartographicDegrees" : [-77, 37, 100000]
    },
    "model": {
        "gltf" : "../../SampleData/models/CesiumMan/Cesium_Man.glb",
        "runAnimations":false,
        "nodeTransformations": {
            "Skeleton_arm_joint_R__2_": {
                "rotation": {
                    "unitQuaternion":[
                        "2017-01-19T14:00:00Z",0,0,0,1,
                        "2017-01-19T18:00:00Z",0,1,0,0,
                        "2017-01-19T22:00:00Z",0,0,0,1
                    ]
                }
            }
        }
    }
}];

var viewer = new Cesium.Viewer('cesiumContainer');
var promise = viewer.dataSources.add(Cesium.CzmlDataSource.load(czml));

promise.then(function(dataSource){
    viewer.trackedEntity = dataSource.entities.getById('model');
}).otherwise(function(error){
    window.alert(error);
});

Finally, search for this thread (different "unitQuaternion " behavior in CZML's "orientation" and "model>nodeTransformation") on this forum for Scott's explanation.

Best luck, erik

Ok thank you for your help, but where is this forum from Scott? and how can I get the node’s name that I want to rotate?

Ok, I found the way to find the node name, It is in the .dae file tagged with node. I test it in the sandcastle and it works!!! thank you erik ;). Know I’ll test it in my project.

Thank you so much for your help

Thanks for your help, Erik! Sergio, the post that he’s referencing is here: https://groups.google.com/d/msg/cesium-dev/rVruwReNyg8/47e_QFXUAwAJ

Hope that helps!

Thank all of you I just solved the problem with all your inputs. The key was:

  • put the orientation of the model as a rotation in the NODE TRANSFORMATION like erik wrote,

  • find the node name inside the gltf,

  • and the quaternion’s order X,Y,Z,W like Rachel comented.