MikaFil commited on
Commit
cfc39a2
·
verified ·
1 Parent(s): 7501d3b

Update tooltips.js

Browse files
Files changed (1) hide show
  1. tooltips.js +20 -13
tooltips.js CHANGED
@@ -173,19 +173,26 @@ export async function initializeTooltips(options) {
173
  const rotation = tempEnt.getRotation();
174
  const forward = new pc.Vec3();
175
  rotation.transformVector(pc.Vec3.FORWARD, forward);
176
- const tgtYaw = Math.atan2(-forward.x, -forward.z) * pc.math.RAD_TO_DEG;
 
 
177
  const yawQuat = new pc.Quat().setFromEulerAngles(0, -tgtYaw, 0);
178
  const rotNoYaw = new pc.Quat().mul2(yawQuat, rotation);
179
  const fNoYaw = new pc.Vec3();
180
  rotNoYaw.transformVector(pc.Vec3.FORWARD, fNoYaw);
181
- const tgtPitch = Math.atan2(fNoYaw.y, -fNoYaw.z) * pc.math.RAD_TO_DEG;
182
  tempEnt.destroy();
183
 
184
- // Target state:
185
- const endPivot = targetPos.clone();
186
- const endYaw = tgtYaw;
187
- const endPitch = tgtPitch;
188
- const endDist = desiredDistance;
 
 
 
 
 
189
 
190
  let elapsed = 0;
191
  const orgPivot = startPivot.clone();
@@ -205,7 +212,7 @@ export async function initializeTooltips(options) {
205
  const t = Math.min(elapsed / duration, 1);
206
 
207
  // Interpolate pivot (vector lerp)
208
- const newPivot = new pc.Vec3().lerp(orgPivot, endPivot, t);
209
  orbitCam.pivotPoint.copy(newPivot);
210
 
211
  // Interpolate yaw/pitch/distance (simple lerp)
@@ -213,12 +220,12 @@ export async function initializeTooltips(options) {
213
  const newPitch = pc.math.lerp(orgPitch, endPitch, t);
214
  const newDist = pc.math.lerp(orgDist, endDist, t);
215
 
216
- orbitCam._targetYaw = newYaw;
217
- orbitCam._yaw = newYaw;
218
- orbitCam._targetPitch = newPitch;
219
- orbitCam._pitch = newPitch;
220
  orbitCam._targetDistance = newDist;
221
- orbitCam._distance = newDist;
222
 
223
  orbitCam._updatePosition();
224
 
 
173
  const rotation = tempEnt.getRotation();
174
  const forward = new pc.Vec3();
175
  rotation.transformVector(pc.Vec3.FORWARD, forward);
176
+ // Raw yaw and pitch from tempEnt
177
+ let tgtYaw = Math.atan2(-forward.x, -forward.z) * pc.math.RAD_TO_DEG;
178
+ // Compute pitch (the _calcPitch logic):
179
  const yawQuat = new pc.Quat().setFromEulerAngles(0, -tgtYaw, 0);
180
  const rotNoYaw = new pc.Quat().mul2(yawQuat, rotation);
181
  const fNoYaw = new pc.Vec3();
182
  rotNoYaw.transformVector(pc.Vec3.FORWARD, fNoYaw);
183
+ let tgtPitch = Math.atan2(fNoYaw.y, -fNoYaw.z) * pc.math.RAD_TO_DEG;
184
  tempEnt.destroy();
185
 
186
+ // Adjust yaw to follow the shortest path from current yaw to target yaw
187
+ const currentYaw = startYaw;
188
+ let deltaYaw = tgtYaw - currentYaw;
189
+ // Wrap into [-180, +180]
190
+ deltaYaw = ((deltaYaw + 180) % 360) - 180;
191
+ const endYaw = currentYaw + deltaYaw;
192
+
193
+ // For pitch, since it’s usually within [-90, +90], direct assignment is fine
194
+ const endPitch = tgtPitch;
195
+ const endDist = desiredDistance;
196
 
197
  let elapsed = 0;
198
  const orgPivot = startPivot.clone();
 
212
  const t = Math.min(elapsed / duration, 1);
213
 
214
  // Interpolate pivot (vector lerp)
215
+ const newPivot = new pc.Vec3().lerp(orgPivot, targetPos, t);
216
  orbitCam.pivotPoint.copy(newPivot);
217
 
218
  // Interpolate yaw/pitch/distance (simple lerp)
 
220
  const newPitch = pc.math.lerp(orgPitch, endPitch, t);
221
  const newDist = pc.math.lerp(orgDist, endDist, t);
222
 
223
+ orbitCam._targetYaw = newYaw;
224
+ orbitCam._yaw = newYaw;
225
+ orbitCam._targetPitch = newPitch;
226
+ orbitCam._pitch = newPitch;
227
  orbitCam._targetDistance = newDist;
228
+ orbitCam._distance = newDist;
229
 
230
  orbitCam._updatePosition();
231