aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/General/PrimitiveBaseShape.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/General/PrimitiveBaseShape.cs')
-rw-r--r--OpenSim/Framework/General/PrimitiveBaseShape.cs224
1 files changed, 224 insertions, 0 deletions
diff --git a/OpenSim/Framework/General/PrimitiveBaseShape.cs b/OpenSim/Framework/General/PrimitiveBaseShape.cs
new file mode 100644
index 0000000..1799fb8
--- /dev/null
+++ b/OpenSim/Framework/General/PrimitiveBaseShape.cs
@@ -0,0 +1,224 @@
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*/
28
29using System.Xml.Serialization;
30using libsecondlife;
31using libsecondlife.Packets;
32
33namespace OpenSim.Framework
34{
35 public enum ProfileShape : byte
36 {
37 Circle = 0,
38 Square = 1,
39 IsometricTriangle = 2,
40 EquilateralTriangle = 3,
41 RightTriangle = 4,
42 HalfCircle = 5
43 }
44
45 public enum HollowShape : byte
46 {
47 Same = 0,
48 Circle = 16,
49 Square = 32,
50 Triangle = 48
51 }
52
53 public enum PCodeEnum : byte
54 {
55 Primitive = 9,
56 Avatar = 47
57 }
58
59 public enum Extrusion : byte
60 {
61 Straight = 16,
62 Curve1 = 32,
63 Curve2 = 48,
64 Flexible = 128
65 }
66
67 public class PrimitiveBaseShape
68 {
69 private static byte[] m_defaultTextureEntry;
70
71 public byte PCode;
72 public ushort PathBegin;
73 public ushort PathEnd;
74 public byte PathScaleX;
75 public byte PathScaleY;
76 public byte PathShearX;
77 public byte PathShearY;
78 public sbyte PathSkew;
79 public ushort ProfileBegin;
80 public ushort ProfileEnd;
81 public LLVector3 Scale;
82 public byte PathCurve;
83 public byte ProfileCurve;
84 public ushort ProfileHollow;
85 public sbyte PathRadiusOffset;
86 public byte PathRevolutions;
87 public sbyte PathTaperX;
88 public sbyte PathTaperY;
89 public sbyte PathTwist;
90 public sbyte PathTwistBegin;
91 public byte[] TextureEntry; // a LL textureEntry in byte[] format
92 public byte[] ExtraParams;
93
94 public ProfileShape ProfileShape
95 {
96 get
97 {
98 return (ProfileShape)(ProfileCurve & 0xf);
99 }
100 set
101 {
102 byte oldValueMasked = (byte)(ProfileCurve & 0xf0);
103 ProfileCurve = (byte)(oldValueMasked | (byte)value);
104 }
105 }
106
107 [XmlIgnore]
108 public HollowShape HollowShape
109 {
110 get
111 {
112 return (HollowShape)(ProfileHollow & 0xf0);
113 }
114 set
115 {
116 byte oldValueMasked = (byte)(ProfileHollow & 0xf0);
117 ProfileHollow = (byte)(oldValueMasked | (byte)value);
118 }
119 }
120
121 public LLVector3 PrimScale
122 {
123 get
124 {
125 return this.Scale;
126 }
127 }
128
129 static PrimitiveBaseShape()
130 {
131 m_defaultTextureEntry = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-9999-000000000005")).ToBytes();
132 }
133
134 public PrimitiveBaseShape()
135 {
136 PCode = (byte)PCodeEnum.Primitive;
137 ExtraParams = new byte[1];
138 TextureEntry = m_defaultTextureEntry;
139 }
140
141 //void returns need to change of course
142 public virtual void GetMesh()
143 {
144
145 }
146
147 public PrimitiveBaseShape Copy()
148 {
149 return (PrimitiveBaseShape)this.MemberwiseClone();
150 }
151 }
152
153 public class GenericShape : PrimitiveBaseShape
154 {
155 public GenericShape()
156 : base()
157 {
158
159 }
160 }
161
162 public class BoxShape : PrimitiveBaseShape
163 {
164 public BoxShape()
165 : base()
166 {
167 PathCurve = (byte)Extrusion.Straight;
168 ProfileShape = ProfileShape.Square;
169 PathScaleX = 100;
170 PathScaleY = 100;
171 }
172
173 public BoxShape(float side)
174 : this()
175 {
176 SetSide(side);
177 }
178
179 public void SetSide(float side)
180 {
181 Scale = new LLVector3(side, side, side);
182 }
183
184 public static BoxShape Default
185 {
186 get
187 {
188 BoxShape boxShape = new BoxShape();
189
190 boxShape.SetSide(0.5f);
191
192 return boxShape;
193 }
194 }
195 }
196 public class CylinderShape : PrimitiveBaseShape
197 {
198 public CylinderShape()
199 : base()
200 {
201 PathCurve = (byte)Extrusion.Straight;
202 ProfileShape = ProfileShape.Circle;
203 PathScaleX = 100;
204 PathScaleY = 100;
205 }
206
207 public CylinderShape(float radius, float heigth)
208 : this()
209 {
210 SetRadius(radius);
211 SetHeigth(heigth);
212 }
213
214 private void SetHeigth(float heigth)
215 {
216 Scale.Z = heigth;
217 }
218
219 private void SetRadius(float radius)
220 {
221 Scale.X = Scale.Y = radius * 2f;
222 }
223 }
224}