Spaces:
Running
Running
Update tooltips.js
Browse files- 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;
|
| 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
|
| 168 |
-
//
|
| 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 |
-
|
| 176 |
-
const
|
| 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
|
| 184 |
-
|
| 185 |
tempEnt.destroy();
|
| 186 |
|
| 187 |
-
//
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 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,
|
| 218 |
orbitCam.pivotPoint.copy(newPivot);
|
| 219 |
|
| 220 |
-
// Interpolate yaw
|
| 221 |
-
const newYaw
|
| 222 |
-
// Interpolate pitch normally (no wrapping needed)
|
| 223 |
const newPitch = pc.math.lerp(orgPitch, endPitch, t);
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
orbitCam.
|
| 229 |
-
orbitCam.
|
| 230 |
-
orbitCam.
|
| 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 |
|