HullTriangle.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* The MIT License
  2. *
  3. * Copyright (c) 2010 Intel Corporation.
  4. * All rights reserved.
  5. *
  6. * Based on the convexdecomposition library from
  7. * <http://codesuppository.googlecode.com> by John W. Ratcliff and Stan Melax.
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Diagnostics;
  30. namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet
  31. {
  32. public class HullTriangle : int3
  33. {
  34. public int3 n = new int3();
  35. public int id;
  36. public int vmax;
  37. public float rise;
  38. private List<HullTriangle> tris;
  39. public HullTriangle(int a, int b, int c, List<HullTriangle> tris)
  40. : base(a, b, c)
  41. {
  42. this.tris = tris;
  43. n = new int3(-1, -1, -1);
  44. id = tris.Count;
  45. tris.Add(this);
  46. vmax = -1;
  47. rise = 0.0f;
  48. }
  49. public void Dispose()
  50. {
  51. Debug.Assert(tris[id] == this);
  52. tris[id] = null;
  53. }
  54. public int neib(int a, int b)
  55. {
  56. int i;
  57. for (i = 0; i < 3; i++)
  58. {
  59. int i1 = (i + 1) % 3;
  60. int i2 = (i + 2) % 3;
  61. if ((this)[i] == a && (this)[i1] == b)
  62. return n[i2];
  63. if ((this)[i] == b && (this)[i1] == a)
  64. return n[i2];
  65. }
  66. Debug.Assert(false);
  67. return -1;
  68. }
  69. public void setneib(int a, int b, int value)
  70. {
  71. int i;
  72. for (i = 0; i < 3; i++)
  73. {
  74. int i1 = (i + 1) % 3;
  75. int i2 = (i + 2) % 3;
  76. if ((this)[i] == a && (this)[i1] == b)
  77. {
  78. n[i2] = value;
  79. return;
  80. }
  81. if ((this)[i] == b && (this)[i1] == a)
  82. {
  83. n[i2] = value;
  84. return;
  85. }
  86. }
  87. }
  88. }
  89. }