MikaFil commited on
Commit
d5897af
·
verified ·
1 Parent(s): afc5b06

Update tooltips.js

Browse files
Files changed (1) hide show
  1. tooltips.js +25 -37
tooltips.js CHANGED
@@ -155,46 +155,37 @@ export async function initializeTooltips(options) {
155
  const targetPos = tooltipEnt.getPosition().clone();
156
  // Compute current state
157
  const startPivot = orbitCam.pivotPoint.clone();
158
- const startYaw = orbitCam._yaw; // current yaw in degrees
159
- const startPitch = orbitCam._pitch; // current pitch in degrees
160
- const startDist = orbitCam._distance; // current distance
161
 
162
  // Compute direction & candidate distance:
163
  const worldRadius = 0.5 * tooltipEnt.getLocalScale().x;
164
  const minZoom = orbitCam.distanceMin;
165
  const desiredDistance = Math.max(minZoom * 1.2, worldRadius * 4);
166
 
167
- // Compute raw desired yaw/pitch from camera pointing at targetPos
168
- // Create a temporary entity to compute the correct orientation
169
  const camWorldPos = cameraEntity.getPosition().clone();
170
  const tempEnt = new pc.Entity();
171
  tempEnt.setPosition(camWorldPos);
172
  tempEnt.lookAt(targetPos);
173
  const rotation = tempEnt.getRotation();
174
-
175
- // Use OrbitCamera's own _calcYaw to get a yaw in [-180, 180]
176
- const rawDesiredYaw = orbitCam._calcYaw(rotation);
177
-
178
- // Compute raw desired pitch using same approach as OrbitCamera._calcPitch
179
- const yawQuat = new pc.Quat().setFromEulerAngles(0, -rawDesiredYaw, 0);
180
  const rotNoYaw = new pc.Quat().mul2(yawQuat, rotation);
181
  const fNoYaw = new pc.Vec3();
182
  rotNoYaw.transformVector(pc.Vec3.FORWARD, fNoYaw);
183
- const rawDesiredPitch = Math.atan2(fNoYaw.y, -fNoYaw.z) * pc.math.RAD_TO_DEG;
184
-
185
  tempEnt.destroy();
186
 
187
- // Compute shortest-path delta for yaw: wrap difference into [-180, 180]
188
- let deltaYaw = rawDesiredYaw - startYaw;
189
- deltaYaw = ((deltaYaw + 180) % 360) - 180; // now in [-180, 180]
190
-
191
- // endYaw remains continuous: startYaw + deltaYaw (no further wrapping)
192
- const endYaw = startYaw + deltaYaw;
193
-
194
- // For pitch, we can assign rawDesiredPitch directly; it's within valid range
195
- const endPitch = rawDesiredPitch;
196
-
197
- const endDist = desiredDistance;
198
 
199
  let elapsed = 0;
200
  const orgPivot = startPivot.clone();
@@ -214,23 +205,20 @@ export async function initializeTooltips(options) {
214
  const t = Math.min(elapsed / duration, 1);
215
 
216
  // Interpolate pivot (vector lerp)
217
- const newPivot = new pc.Vec3().lerp(orgPivot, targetPos, t);
218
  orbitCam.pivotPoint.copy(newPivot);
219
 
220
- // Interpolate yaw numerically: since endYaw is continuous relative to startYaw
221
- const newYaw = pc.math.lerp(orgYaw, endYaw, t);
222
- // Interpolate pitch normally (no wrapping needed)
223
  const newPitch = pc.math.lerp(orgPitch, endPitch, t);
224
- // Interpolate distance
225
- const newDist = pc.math.lerp(orgDist, endDist, t);
226
-
227
- // Assign to orbitCam so that _updatePosition() uses them
228
- orbitCam._yaw = newYaw;
229
- orbitCam._targetYaw = endYaw;
230
- orbitCam._pitch = newPitch;
231
- orbitCam._targetPitch = endPitch;
232
  orbitCam._distance = newDist;
233
- orbitCam._targetDistance = endDist;
234
 
235
  orbitCam._updatePosition();
236
 
 
155
  const targetPos = tooltipEnt.getPosition().clone();
156
  // Compute current state
157
  const startPivot = orbitCam.pivotPoint.clone();
158
+ const startYaw = orbitCam._yaw;
159
+ const startPitch = orbitCam._pitch;
160
+ const startDist = orbitCam._distance;
161
 
162
  // Compute direction & candidate distance:
163
  const worldRadius = 0.5 * tooltipEnt.getLocalScale().x;
164
  const minZoom = orbitCam.distanceMin;
165
  const desiredDistance = Math.max(minZoom * 1.2, worldRadius * 4);
166
 
167
+ // Compute target yaw/pitch from camera pointing at targetPos
168
+ // Reuse reset logic: place a temp entity at camera’s current position, have it look at target
169
  const camWorldPos = cameraEntity.getPosition().clone();
170
  const tempEnt = new pc.Entity();
171
  tempEnt.setPosition(camWorldPos);
172
  tempEnt.lookAt(targetPos);
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
  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)
212
+ const newYaw = pc.math.lerp(orgYaw, endYaw, t);
 
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