Rotating entity

Ive imported a model using the javascript API and it seems to sit correctly with the Y as the up axis as shown below…

I want to now rotate the model around the Y axis to fit it into place correctly and I found this snippet of code to assist me with this- I have commented it out so you can see the code im referencing…

However after running the code my model doesnt rotate as expected in fact rotating around any of the axis doesnt work as expected, it feels very unintuitive using this method. What am I doing wrong or is there a better way to do this?

I believe that is because you’re rotating in world space. Your rotation axis should be the normal on the ellipsoid at your model’s position. Try doing the following

const axis = viewer.scene.globe.ellipsoid.getGeodeticSurfaceNormal(entity.position, new Cesium.Cartesian3())

I didn’t test this, but it’s how I rotate things.

Hey Dan,

Thanks for chiming in man. Your answer was interesting way to tackle the problem, certainly makes sense what you are trying to achieve but apparently however getGeodeticSurfaceNormal() isnt a valid function. Not sure why Im getting that, maybe the API has been updated?

After doing a little bit more digging around I have found a solution. Im using the orientation attribute to set the orientation on creation like so:

const orientation = Cesium.Transforms.headingPitchRollQuaternion(position, new Cesium.HeadingPitchRoll(305, 0, 0));

This is exactly what I am after.

1 Like