MikaFil commited on
Commit
8b43a88
·
verified ·
1 Parent(s): 42ab40f

Update deplacement_dans_env/ctrl_camera_pr_env.js

Browse files
deplacement_dans_env/ctrl_camera_pr_env.js CHANGED
@@ -266,20 +266,6 @@ var OrbitCameraInputMouse = pc.createScript('orbitCameraInputMouse');
266
  OrbitCameraInputMouse.attributes.add('orbitSensitivity', { type: 'number', default: 0.3, title: 'Orbit Sensitivity' });
267
  OrbitCameraInputMouse.attributes.add('distanceSensitivity', { type: 'number', default: 0.4, title: 'Distance Sensitivity' });
268
 
269
- // --- helper: recenter pivot on current camera view target (camPos + forward * distance)
270
- OrbitCameraInputMouse.prototype._recenterPivotToCamera = function () {
271
- var oc = this.orbitCamera;
272
- if (!oc) return;
273
- var camPos = this.entity.getPosition().clone();
274
- var q = new pc.Quat().setFromEulerAngles(oc._pitch, oc._yaw, 0);
275
- var f = new pc.Vec3(); q.transformVector(pc.Vec3.FORWARD, f);
276
- var newPivot = camPos.clone().add(f.mulScalar(oc._distance));
277
- oc._pivotPoint.copy(newPivot);
278
- oc._removeInertia();
279
- oc._updatePosition();
280
- this.entity.setPosition(camPos);
281
- };
282
-
283
  OrbitCameraInputMouse.prototype.initialize = function () {
284
  this.orbitCamera = this.entity.script.orbitCamera;
285
 
@@ -346,15 +332,9 @@ OrbitCameraInputMouse.prototype.pan = function (screenPoint) {
346
 
347
  OrbitCameraInputMouse.prototype.onMouseDown = function (event) {
348
  switch (event.button) {
349
- case pc.MOUSEBUTTON_LEFT:
350
- this.panButtonDown = true;
351
- break;
352
  case pc.MOUSEBUTTON_MIDDLE:
353
- case pc.MOUSEBUTTON_RIGHT:
354
- // <<< recenter orbit pivot when starting mouse orbit
355
- this._recenterPivotToCamera();
356
- this.lookButtonDown = true;
357
- break;
358
  }
359
  };
360
 
@@ -426,20 +406,6 @@ var OrbitCameraInputTouch = pc.createScript('orbitCameraInputTouch');
426
  OrbitCameraInputTouch.attributes.add('orbitSensitivity', { type: 'number', default: 0.6, title: 'Orbit Sensitivity' });
427
  OrbitCameraInputTouch.attributes.add('distanceSensitivity', { type: 'number', default: 0.5, title: 'Distance Sensitivity' });
428
 
429
- // --- helper: recenter pivot on touch orbit start
430
- OrbitCameraInputTouch.prototype._recenterPivotToCamera = function () {
431
- var oc = this.orbitCamera;
432
- if (!oc) return;
433
- var camPos = this.entity.getPosition().clone();
434
- var q = new pc.Quat().setFromEulerAngles(oc._pitch, oc._yaw, 0);
435
- var f = new pc.Vec3(); q.transformVector(pc.Vec3.FORWARD, f);
436
- var newPivot = camPos.clone().add(f.mulScalar(oc._distance));
437
- oc._pivotPoint.copy(newPivot);
438
- oc._removeInertia();
439
- oc._updatePosition();
440
- this.entity.setPosition(camPos);
441
- };
442
-
443
  OrbitCameraInputTouch.prototype.initialize = function () {
444
  this.orbitCamera = this.entity.script.orbitCamera;
445
  this.lastTouchPoint = new pc.Vec2();
@@ -477,8 +443,6 @@ OrbitCameraInputTouch.prototype.calcMidPoint = function (pointA, pointB, result)
477
  OrbitCameraInputTouch.prototype.onTouchStartEndCancel = function (event) {
478
  var touches = event.touches;
479
  if (touches.length === 1) {
480
- // <<< recenter orbit pivot when starting a one-finger orbit
481
- this._recenterPivotToCamera();
482
  this.lastTouchPoint.set(touches[0].x, touches[0].y);
483
  } else if (touches.length === 2) {
484
  this.lastPinchDistance = this.getPinchDistance(touches[0], touches[1]);
@@ -575,9 +539,9 @@ OrbitCameraInputTouch.prototype.onTouchMove = function (event) {
575
  };
576
 
577
  // =================== Orbit Camera Input Keyboard ========================
578
- // Mappages :
579
  // - Flèches : déplacement avant/arrière & droite/gauche dans le repère de la caméra (3D)
580
- // - Ctrl+flèches : orbiter autour du pivot (clamps actifs)
581
  // - Maj+flèches : rotation libre sur place (pas de limites yaw/pitch)
582
  var OrbitCameraInputKeyboard = pc.createScript('orbitCameraInputKeyboard');
583
 
@@ -609,14 +573,15 @@ OrbitCameraInputKeyboard.prototype.update = function (dt) {
609
 
610
  // -------- Ctrl + flèches : ORBITER autour du pivot (clamp actif) --------
611
  if (ctrl && (up || dn || lt || rt)) {
612
- var yawDir = (rt ? 1 : 0) - (lt ? 1 : 0);
613
- var pitchDir = (up ? 1 : 0) - (dn ? 1 : 0);
614
 
615
  if (yawDir !== 0) {
616
  this.orbitCamera.yaw = this.orbitCamera.yaw + yawDir * this.orbitYawSpeedDeg * dt;
617
  }
618
 
619
  if (pitchDir !== 0) {
 
620
  var currPitch = this.orbitCamera.pitch;
621
  var currYaw = this.orbitCamera.yaw;
622
  var currDist = this.orbitCamera.distance;
@@ -690,11 +655,11 @@ OrbitCameraInputKeyboard.prototype.update = function (dt) {
690
  if (moveRight !== 0) delta.add(right.mulScalar(moveRight * speedR * dt));
691
 
692
  if (delta.lengthSq() > 0) {
693
- // Respecte minY : camY_new = camY_cur + delta.y
694
  var currCamY = this.orbitCamera.worldCameraYForPivot(this.orbitCamera._pivotPoint);
695
  var minY = this.orbitCamera.minY;
696
  if (currCamY + delta.y < minY) {
697
- delta.y = minY - currCamY; // ajuste juste ce qu'il faut
698
  }
699
  this.orbitCamera._pivotPoint.add(delta);
700
  }
 
266
  OrbitCameraInputMouse.attributes.add('orbitSensitivity', { type: 'number', default: 0.3, title: 'Orbit Sensitivity' });
267
  OrbitCameraInputMouse.attributes.add('distanceSensitivity', { type: 'number', default: 0.4, title: 'Distance Sensitivity' });
268
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  OrbitCameraInputMouse.prototype.initialize = function () {
270
  this.orbitCamera = this.entity.script.orbitCamera;
271
 
 
332
 
333
  OrbitCameraInputMouse.prototype.onMouseDown = function (event) {
334
  switch (event.button) {
335
+ case pc.MOUSEBUTTON_LEFT: this.panButtonDown = true; break;
 
 
336
  case pc.MOUSEBUTTON_MIDDLE:
337
+ case pc.MOUSEBUTTON_RIGHT: this.lookButtonDown = true; break;
 
 
 
 
338
  }
339
  };
340
 
 
406
  OrbitCameraInputTouch.attributes.add('orbitSensitivity', { type: 'number', default: 0.6, title: 'Orbit Sensitivity' });
407
  OrbitCameraInputTouch.attributes.add('distanceSensitivity', { type: 'number', default: 0.5, title: 'Distance Sensitivity' });
408
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409
  OrbitCameraInputTouch.prototype.initialize = function () {
410
  this.orbitCamera = this.entity.script.orbitCamera;
411
  this.lastTouchPoint = new pc.Vec2();
 
443
  OrbitCameraInputTouch.prototype.onTouchStartEndCancel = function (event) {
444
  var touches = event.touches;
445
  if (touches.length === 1) {
 
 
446
  this.lastTouchPoint.set(touches[0].x, touches[0].y);
447
  } else if (touches.length === 2) {
448
  this.lastPinchDistance = this.getPinchDistance(touches[0], touches[1]);
 
539
  };
540
 
541
  // =================== Orbit Camera Input Keyboard ========================
542
+ // Mappages demandés :
543
  // - Flèches : déplacement avant/arrière & droite/gauche dans le repère de la caméra (3D)
544
+ // - Ctrl+flèches : orbiter autour du pivot
545
  // - Maj+flèches : rotation libre sur place (pas de limites yaw/pitch)
546
  var OrbitCameraInputKeyboard = pc.createScript('orbitCameraInputKeyboard');
547
 
 
573
 
574
  // -------- Ctrl + flèches : ORBITER autour du pivot (clamp actif) --------
575
  if (ctrl && (up || dn || lt || rt)) {
576
+ var yawDir = (rt ? 1 : 0) - (lt ? 1 : 0); // droite = +1, gauche = -1
577
+ var pitchDir = (up ? 1 : 0) - (dn ? 1 : 0); // haut = +1, bas = -1
578
 
579
  if (yawDir !== 0) {
580
  this.orbitCamera.yaw = this.orbitCamera.yaw + yawDir * this.orbitYawSpeedDeg * dt;
581
  }
582
 
583
  if (pitchDir !== 0) {
584
+ // on laisse le clamp faire son travail via le setter
585
  var currPitch = this.orbitCamera.pitch;
586
  var currYaw = this.orbitCamera.yaw;
587
  var currDist = this.orbitCamera.distance;
 
655
  if (moveRight !== 0) delta.add(right.mulScalar(moveRight * speedR * dt));
656
 
657
  if (delta.lengthSq() > 0) {
658
+ // Respecte minY : camY_new = camY_cur + delta.y (car yaw/pitch/distance inchangés)
659
  var currCamY = this.orbitCamera.worldCameraYForPivot(this.orbitCamera._pivotPoint);
660
  var minY = this.orbitCamera.minY;
661
  if (currCamY + delta.y < minY) {
662
+ delta.y = minY - currCamY; // on limite juste ce qu'il faut
663
  }
664
  this.orbitCamera._pivotPoint.add(delta);
665
  }