BeamMetaEntity.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 OpenSim 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. // BeamMetaEntity.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.Environment.Interfaces;
  41. using OpenSim.Region.Environment.Scenes;
  42. using OpenSim.Region.Physics.Manager;
  43. using log4net;
  44. namespace OpenSim.Region.Environment.Modules.ContentManagement
  45. {
  46. public class BeamMetaEntity : PointMetaEntity
  47. {
  48. #region Constructors
  49. public BeamMetaEntity(Scene scene, Vector3 groupPos, float transparency, SceneObjectPart To, Vector3 color)
  50. : base(scene, groupPos, transparency)
  51. {
  52. SetBeamToUUID(To, color);
  53. }
  54. public BeamMetaEntity(Scene scene, UUID uuid, Vector3 groupPos, float transparency, SceneObjectPart To, Vector3 color)
  55. : base(scene, uuid, groupPos, transparency)
  56. {
  57. SetBeamToUUID(To, color);
  58. }
  59. #endregion Constructors
  60. #region Public Methods
  61. public void SetBeamToUUID(SceneObjectPart To, Vector3 color)
  62. {
  63. SceneObjectPart From = m_Entity.RootPart;
  64. //Scale size of particles to distance objects are apart (for better visibility)
  65. Vector3 FromPos = From.GetWorldPosition();
  66. Vector3 ToPos = From.GetWorldPosition();
  67. // UUID toUUID = To.UUID;
  68. float distance = (float) (Math.Sqrt(Math.Pow(FromPos.X-ToPos.X, 2) +
  69. Math.Pow(FromPos.X-ToPos.Y, 2) +
  70. Math.Pow(FromPos.X-ToPos.Z, 2)
  71. )
  72. );
  73. //float rate = (float) (distance/4f);
  74. float rate = 0.5f;
  75. float scale = (float) (distance/128f);
  76. float speed = (float) (2.0f - distance/128f);
  77. SetBeamToUUID(From, To, color, rate, scale, speed);
  78. }
  79. public void SetBeamToUUID(SceneObjectPart From, SceneObjectPart To, Vector3 color, float rate, float scale, float speed)
  80. {
  81. Primitive.ParticleSystem prules = new Primitive.ParticleSystem();
  82. //prules.PartDataFlags = Primitive.ParticleSystem.ParticleDataFlags.Emissive |
  83. // Primitive.ParticleSystem.ParticleDataFlags.FollowSrc; //PSYS_PART_FLAGS
  84. prules.PartDataFlags = Primitive.ParticleSystem.ParticleDataFlags.Beam |
  85. Primitive.ParticleSystem.ParticleDataFlags.TargetPos;
  86. prules.PartStartColor.R = color.X; //PSYS_PART_START_COLOR
  87. prules.PartStartColor.G = color.Y;
  88. prules.PartStartColor.B = color.Z;
  89. prules.PartStartColor.A = 1.0f; //PSYS_PART_START_ALPHA, transparency
  90. prules.PartEndColor.R = color.X; //PSYS_PART_END_COLOR
  91. prules.PartEndColor.G = color.Y;
  92. prules.PartEndColor.B = color.Z;
  93. prules.PartEndColor.A = 1.0f; //PSYS_PART_END_ALPHA, transparency
  94. prules.PartStartScaleX = scale; //PSYS_PART_START_SCALE
  95. prules.PartStartScaleY = scale;
  96. prules.PartEndScaleX = scale; //PSYS_PART_END_SCALE
  97. prules.PartEndScaleY = scale;
  98. prules.PartMaxAge = 1.0f; //PSYS_PART_MAX_AGE
  99. prules.PartAcceleration.X = 0.0f; //PSYS_SRC_ACCEL
  100. prules.PartAcceleration.Y = 0.0f;
  101. prules.PartAcceleration.Z = 0.0f;
  102. //prules.Pattern = Primitive.ParticleSystem.SourcePattern.Explode; //PSYS_SRC_PATTERN
  103. //prules.Texture = UUID.Zero;//= UUID //PSYS_SRC_TEXTURE, default used if blank
  104. prules.BurstRate = rate; //PSYS_SRC_BURST_RATE
  105. prules.BurstPartCount = 1; //PSYS_SRC_BURST_PART_COUNT
  106. prules.BurstRadius = 0.5f; //PSYS_SRC_BURST_RADIUS
  107. prules.BurstSpeedMin = speed; //PSYS_SRC_BURST_SPEED_MIN
  108. prules.BurstSpeedMax = speed; //PSYS_SRC_BURST_SPEED_MAX
  109. prules.MaxAge = 0.0f; //PSYS_SRC_MAX_AGE
  110. prules.Target = To.UUID; //PSYS_SRC_TARGET_KEY
  111. prules.AngularVelocity.X = 0.0f; //PSYS_SRC_OMEGA
  112. prules.AngularVelocity.Y = 0.0f;
  113. prules.AngularVelocity.Z = 0.0f;
  114. prules.InnerAngle = 0.0f; //PSYS_SRC_ANGLE_BEGIN
  115. prules.OuterAngle = 0.0f; //PSYS_SRC_ANGLE_END
  116. prules.CRC = 1; //activates the particle system??
  117. From.AddNewParticleSystem(prules);
  118. }
  119. #endregion Public Methods
  120. }
  121. }