How to make a 3d model rotate and face camera?

I have a moving camera which stops at some point (changes depending on the scenario) and then a 3d model is added to the center of the scene for few seconds. I want this 3d model to face my camera. Now the problem is that i don’t know in which directions the camera will be looking at when it stops, therefore I can’t hard code the model matrix of the 3d object. How can i calculate the model matrix so that my 3d model faces my camera whenever its added to the scene?

I am using this code:

var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(cartesian3);
var model = scene.primitives.add(Cesium.Model.fromGltf({
    url : '../../Models/xyz.gltf',
    modelMatrix : modelMatrix


So you don’t need this to update and follow the camera as it moves, just when it stops correct?

I don’t think there is a built in way to do this using Cesium, so you’ll need to do a little math:

  • You should be able to get the vector along which the model should be looking by subtracting the camera position (Camera.positionWC) from the model’s position
  • Figure out the axis of rotation and the angle of the rotation, then create a Quaternion using Quaternion.fromAxisAngle.
  • Use that value, along with the position as the translation to create the Matrix using Matrix4.fromTranslationQuaternionRotationScale
    Thanks, hope that helps!