1
0

AuraMetaEntity.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #region Header
  28. // AuraMetaEntity.cs created with MonoDevelop
  29. // User: bongiojp at 3:03 PM 8/6/2008
  30. //
  31. // To change standard headers go to Edit->Preferences->Coding->Standard Headers
  32. //
  33. #endregion Header
  34. using System;
  35. using System.Collections.Generic;
  36. using System.Drawing;
  37. using OpenMetaverse;
  38. using Nini.Config;
  39. using OpenSim.Framework;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.Framework.Scenes;
  42. using OpenSim.Region.Physics.Manager;
  43. using log4net;
  44. namespace OpenSim.Region.OptionalModules.ContentManagement
  45. {
  46. public class AuraMetaEntity : PointMetaEntity
  47. {
  48. #region Constructors
  49. //transparency of root part, NOT particle system. Should probably add support for changing particle system transparency.
  50. public AuraMetaEntity(Scene scene, Vector3 groupPos, float transparency, Vector3 color, Vector3 scale)
  51. : base(scene, groupPos, transparency)
  52. {
  53. SetAura(color, scale);
  54. }
  55. public AuraMetaEntity(Scene scene, UUID uuid, Vector3 groupPos, float transparency, Vector3 color, Vector3 scale)
  56. : base(scene, uuid, groupPos, transparency)
  57. {
  58. SetAura(color, scale);
  59. }
  60. #endregion Constructors
  61. #region Private Methods
  62. private float Average(Vector3 values)
  63. {
  64. return (values.X + values.Y + values.Z)/3f;
  65. }
  66. #endregion Private Methods
  67. #region Public Methods
  68. public void SetAura(Vector3 color, Vector3 scale)
  69. {
  70. SetAura(color, Average(scale) * 2.0f);
  71. }
  72. public void SetAura(Vector3 color, float radius)
  73. {
  74. SceneObjectPart From = m_Entity.RootPart;
  75. //m_log.Debug("[META ENTITY] BEFORE: radius = " + radius);
  76. float burstRadius = 0.1f;
  77. Primitive.ParticleSystem.SourcePattern patternFlags = Primitive.ParticleSystem.SourcePattern.None;
  78. float age = 1.5f;
  79. float burstRate = 0.4f;
  80. if (radius >= 8.0f)
  81. {
  82. //float sizeOfObject = radius / 2.0f;
  83. burstRadius = (radius - 8.0f)/3f;
  84. burstRate = 1.5f;
  85. radius = 7.99f;
  86. patternFlags = Primitive.ParticleSystem.SourcePattern.Explode;
  87. age = 4.0f;
  88. }
  89. SetAura(From, color, radius, burstRadius, age, burstRate, patternFlags);
  90. }
  91. public void SetAura(SceneObjectPart From, Vector3 color, float radius, float burstRadius, float age, float burstRate, Primitive.ParticleSystem.SourcePattern patternFlags)
  92. {
  93. Primitive.ParticleSystem prules = new Primitive.ParticleSystem();
  94. //prules.PartDataFlags = Primitive.ParticleSystem.ParticleDataFlags.Emissive |
  95. // Primitive.ParticleSystem.ParticleDataFlags.FollowSrc; //PSYS_PART_FLAGS
  96. //prules.PartDataFlags = Primitive.ParticleSystem.ParticleDataFlags.Beam |
  97. // Primitive.ParticleSystem.ParticleDataFlags.TargetPos;
  98. prules.PartStartColor.R = color.X; //PSYS_PART_START_COLOR
  99. prules.PartStartColor.G = color.Y;
  100. prules.PartStartColor.B = color.Z;
  101. prules.PartStartColor.A = 0.5f; //PSYS_PART_START_ALPHA, transparency
  102. prules.PartEndColor.R = color.X; //PSYS_PART_END_COLOR
  103. prules.PartEndColor.G = color.Y;
  104. prules.PartEndColor.B = color.Z;
  105. prules.PartEndColor.A = 0.5f; //PSYS_PART_END_ALPHA, transparency
  106. /*prules.PartStartScaleX = 0.5f; //PSYS_PART_START_SCALE
  107. prules.PartStartScaleY = 0.5f;
  108. prules.PartEndScaleX = 0.5f; //PSYS_PART_END_SCALE
  109. prules.PartEndScaleY = 0.5f;
  110. */
  111. prules.PartStartScaleX = radius; //PSYS_PART_START_SCALE
  112. prules.PartStartScaleY = radius;
  113. prules.PartEndScaleX = radius; //PSYS_PART_END_SCALE
  114. prules.PartEndScaleY = radius;
  115. prules.PartMaxAge = age; //PSYS_PART_MAX_AGE
  116. prules.PartAcceleration.X = 0.0f; //PSYS_SRC_ACCEL
  117. prules.PartAcceleration.Y = 0.0f;
  118. prules.PartAcceleration.Z = 0.0f;
  119. prules.Pattern = patternFlags; //PSYS_SRC_PATTERN
  120. //prules.Texture = UUID.Zero;//= UUID //PSYS_SRC_TEXTURE, default used if blank
  121. prules.BurstRate = burstRate; //PSYS_SRC_BURST_RATE
  122. prules.BurstPartCount = 2; //PSYS_SRC_BURST_PART_COUNT
  123. //prules.BurstRadius = radius; //PSYS_SRC_BURST_RADIUS
  124. prules.BurstRadius = burstRadius; //PSYS_SRC_BURST_RADIUS
  125. prules.BurstSpeedMin = 0.001f; //PSYS_SRC_BURST_SPEED_MIN
  126. prules.BurstSpeedMax = 0.001f; //PSYS_SRC_BURST_SPEED_MAX
  127. prules.MaxAge = 0.0f; //PSYS_SRC_MAX_AGE
  128. //prules.Target = To; //PSYS_SRC_TARGET_KEY
  129. prules.AngularVelocity.X = 0.0f; //PSYS_SRC_OMEGA
  130. prules.AngularVelocity.Y = 0.0f;
  131. prules.AngularVelocity.Z = 0.0f;
  132. prules.InnerAngle = 0.0f; //PSYS_SRC_ANGLE_BEGIN
  133. prules.OuterAngle = 0.0f; //PSYS_SRC_ANGLE_END
  134. prules.CRC = 1; //activates the particle system??
  135. From.AddNewParticleSystem(prules);
  136. }
  137. #endregion Public Methods
  138. }
  139. }