|
48 | 48 | // A velocity vector property will give us the entity's speed and direction at any given time.
|
49 | 49 | var velocityVectorProperty = new Cesium.VelocityVectorProperty(position, false);
|
50 | 50 | var velocityVector = new Cesium.Cartesian3();
|
51 |
| -// Store the wheel's rotation over time in a SampledProperty. |
52 |
| -var wheelAngleProperty = new Cesium.SampledProperty(Number); |
53 |
| -var wheelAngle = 0; |
54 | 51 |
|
55 | 52 | var numberOfSamples = 100;
|
56 | 53 | for (var i = 0; i <= numberOfSamples; ++i) {
|
|
61 | 58 | var locationFactor = Math.pow(factor, 2);
|
62 | 59 | var location = Cesium.Cartesian3.lerp(startPosition, endPosition, locationFactor, new Cesium.Cartesian3());
|
63 | 60 | position.addSample(time, location);
|
64 |
| - // Rotate the wheels based on how fast the vehicle is moving at each timestep. |
65 |
| - velocityVectorProperty.getValue(time, velocityVector); |
66 |
| - var metersPerSecond = Cesium.Cartesian3.magnitude(velocityVector); |
67 |
| - var wheelRadius = 0.52;//in meters. |
68 |
| - var circumference = Math.PI * wheelRadius * 2; |
69 |
| - var rotationsPerSecond = metersPerSecond / circumference; |
70 |
| - |
71 |
| - wheelAngle += ((Math.PI * 2 * totalSeconds) / numberOfSamples) * rotationsPerSecond; |
72 |
| - wheelAngleProperty.addSample(time, wheelAngle); |
73 | 61 | }
|
74 | 62 |
|
75 | 63 | function updateSpeedLabel(time, result) {
|
|
80 | 68 | return kmPerHour + ' km/hr';
|
81 | 69 | }
|
82 | 70 |
|
| 71 | +var scratchJulianDate = new Cesium.JulianDate(); |
| 72 | + |
| 73 | +var wheelAngleProperty = new Cesium.CallbackProperty(function (time, result) { |
| 74 | + // In order to compute the angle of the wheel at any given time, |
| 75 | + // we need to take samples of velocity from the start position |
| 76 | + // all the way up to the current time. |
| 77 | + var start = viewer.clock.startTime; |
| 78 | + var secondsUpToNow = Cesium.JulianDate.secondsDifference(time, start); |
| 79 | + |
| 80 | + if (secondsUpToNow == 0) { |
| 81 | + return 0; |
| 82 | + } |
| 83 | + |
| 84 | + var timeStep = 0.016;//Take 60 velocity samples per second. |
| 85 | + var numberOfAngleSamples = secondsUpToNow / timeStep; |
| 86 | + |
| 87 | + var wheelAngle = 0; |
| 88 | + for (var i = 0; i <= numberOfAngleSamples; ++i) { |
| 89 | + var factor = (i / numberOfAngleSamples); |
| 90 | + var currentTime = Cesium.JulianDate.addSeconds(start, factor * secondsUpToNow, scratchJulianDate); |
| 91 | + // Get the velocity at this sampled time. |
| 92 | + velocityVectorProperty.getValue(currentTime, velocityVector); |
| 93 | + var metersPerSecond = Cesium.Cartesian3.magnitude(velocityVector); |
| 94 | + var wheelRadius = 0.52;//in meters. |
| 95 | + var circumference = Math.PI * wheelRadius * 2; |
| 96 | + var rotationsPerSecond = metersPerSecond / circumference; |
| 97 | + |
| 98 | + wheelAngle += ((Math.PI * 2 * secondsUpToNow) / numberOfAngleSamples) * rotationsPerSecond; |
| 99 | + } |
| 100 | + |
| 101 | + return wheelAngle; |
| 102 | + |
| 103 | +}, false); |
| 104 | + |
83 | 105 | var rotationProperty = new Cesium.CallbackProperty(function(time, result) {
|
84 | 106 | return Cesium.Quaternion.fromAxisAngle(Cesium.Cartesian3.UNIT_X, wheelAngleProperty.getValue(time), result);
|
85 | 107 | }, false);
|
|
100 | 122 | orientation : new Cesium.VelocityOrientationProperty(position), // Automatically set the vehicle's orientation to the direction it's facing.
|
101 | 123 | model : {
|
102 | 124 | uri : '../../../../Apps/SampleData/models/GroundVehicle/GroundVehicle.glb',
|
103 |
| - minimumPixelSize : 128, |
104 |
| - maximumScale : 20000, |
105 | 125 | runAnimations : false,
|
106 | 126 | nodeTransformations : nodeTransformations
|
107 | 127 | },
|
|
0 commit comments