CylinderGeometryLibrary-8c0fda9f.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * Cesium - https://github.com/CesiumGS/cesium
  3. *
  4. * Copyright 2011-2020 Cesium Contributors
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * Columbus View (Pat. Pend.)
  19. *
  20. * Portions licensed separately.
  21. * See https://github.com/CesiumGS/cesium/blob/master/LICENSE.md for full licensing details.
  22. */
  23. define(['exports', './Math-61ede240'], function (exports, _Math) { 'use strict';
  24. /**
  25. * @private
  26. */
  27. var CylinderGeometryLibrary = {};
  28. /**
  29. * @private
  30. */
  31. CylinderGeometryLibrary.computePositions = function(length, topRadius, bottomRadius, slices, fill){
  32. var topZ = length * 0.5;
  33. var bottomZ = -topZ;
  34. var twoSlice = slices + slices;
  35. var size = (fill) ? 2 * twoSlice : twoSlice;
  36. var positions = new Float64Array(size*3);
  37. var i;
  38. var index = 0;
  39. var tbIndex = 0;
  40. var bottomOffset = (fill) ? twoSlice*3 : 0;
  41. var topOffset = (fill) ? (twoSlice + slices)*3 : slices*3;
  42. for (i = 0; i < slices; i++) {
  43. var angle = i / slices * _Math.CesiumMath.TWO_PI;
  44. var x = Math.cos(angle);
  45. var y = Math.sin(angle);
  46. var bottomX = x * bottomRadius;
  47. var bottomY = y * bottomRadius;
  48. var topX = x * topRadius;
  49. var topY = y * topRadius;
  50. positions[tbIndex + bottomOffset] = bottomX;
  51. positions[tbIndex + bottomOffset + 1] = bottomY;
  52. positions[tbIndex + bottomOffset + 2] = bottomZ;
  53. positions[tbIndex + topOffset] = topX;
  54. positions[tbIndex + topOffset + 1] = topY;
  55. positions[tbIndex + topOffset + 2] = topZ;
  56. tbIndex += 3;
  57. if (fill) {
  58. positions[index++] = bottomX;
  59. positions[index++] = bottomY;
  60. positions[index++] = bottomZ;
  61. positions[index++] = topX;
  62. positions[index++] = topY;
  63. positions[index++] = topZ;
  64. }
  65. }
  66. return positions;
  67. };
  68. exports.CylinderGeometryLibrary = CylinderGeometryLibrary;
  69. });