spherePanel.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2. module BABYLON.GUI {
  3. /**
  4. * Class used to create a container panel deployed on the surface of a sphere
  5. */
  6. export class SpherePanel extends VolumeBasedPanel {
  7. protected _mapGridNode(control: Control3D, nodePosition: Vector3) {
  8. let newPos = this._sphericalMapping(nodePosition);
  9. let mesh = control.mesh;
  10. if (!mesh) {
  11. return;
  12. }
  13. switch (this.orientation) {
  14. case Container3D.FACEORIGIN_ORIENTATION:
  15. mesh.lookAt(new BABYLON.Vector3(-newPos.x, -newPos.y, -newPos.z));
  16. break;
  17. case Container3D.FACEORIGINREVERSED_ORIENTATION:
  18. mesh.lookAt(new BABYLON.Vector3(newPos.x, newPos.y, newPos.z));
  19. break;
  20. case Container3D.FACEFORWARD_ORIENTATION:
  21. mesh.lookAt(new BABYLON.Vector3(0, 0, 1));
  22. break;
  23. case Container3D.FACEFORWARDREVERSED_ORIENTATION:
  24. mesh.lookAt(new BABYLON.Vector3(0, 0, -1));
  25. break;
  26. }
  27. control.position = newPos;
  28. }
  29. private _sphericalMapping(source: Vector3)
  30. {
  31. let newPos = new Vector3(0, 0, this.radius);
  32. let xAngle = (source.y / this.radius);
  33. let yAngle = -(source.x / this.radius);
  34. Matrix.RotationYawPitchRollToRef(yAngle, xAngle, 0, Tmp.Matrix[0]);
  35. return Vector3.TransformNormal(newPos, Tmp.Matrix[0]);
  36. }
  37. }
  38. }