Change attachment point and rotate a cone

I am trying to display a cone in front of the pilot. I am using CylinderGraphics which works great but the cone is displayed around the pilot and oriented downwards. Is it possible to:

  1. Change the attachment point of the cone so that the pilot is at its tip and not in the middle?
  2. Rotate the cone 90 degrees? I’m using VelocityOrientationProperty for the orientation of the entity.

This is an example of how it currently looks at XCvid:

Anyone have a solution for this? I need to do something similar. Thanks for the question.

By default, the center of a CylinderGraphics will be the origin. When you want to use the top of a cylinder (or the “tip” of a cone, in your example) as some sort of a “reference point”, then you have to take this into account when computing the rotation- and translation matrices.

Assuming that you have a rotationMatrix for the orientation and a translationMatrix for the desired position, you can compute

  • a toOriginMatrix to move the center of the coordinate system to the top of the cylinder
  • a fromOriginMatrix to move the center of the coordinate system back

The final modelMatrix for the cylinder can then be computed like this:

  const modelMatrix = Cesium.Matrix4.clone(Cesium.Matrix4.IDENTITY);
  Cesium.Matrix4.multiply(modelMatrix, translationMatrix, modelMatrix);
  Cesium.Matrix4.multiply(modelMatrix, toOriginMatrix, modelMatrix);
  Cesium.Matrix4.multiply(modelMatrix, rotationMatrix, modelMatrix);
  Cesium.Matrix4.multiply(modelMatrix, fromOriginMatrix, modelMatrix);

An example can be found in the sandcastle that I posted in Create a cylinder at a coordinate and point at another coordinate - #2 by Marco13 . It offers a function that receives to points, and generates a cylinder between these points. (Applying arbitrary rotations could be done similarly)

1 Like