diff options
author | Dahlia Trimble | 2008-08-23 08:33:00 +0000 |
---|---|---|
committer | Dahlia Trimble | 2008-08-23 08:33:00 +0000 |
commit | df14889635cf0059b50b01a0b648de9ab92835a7 (patch) | |
tree | 50783c7c470a2ba46a96e769c5c14a1d4f0fb390 /OpenSim/Region/Physics/Meshing/PrimMesher.cs | |
parent | Some complex re-ordering to make prebuild do what needed to be done. (diff) | |
download | opensim-SC-df14889635cf0059b50b01a0b648de9ab92835a7.zip opensim-SC-df14889635cf0059b50b01a0b648de9ab92835a7.tar.gz opensim-SC-df14889635cf0059b50b01a0b648de9ab92835a7.tar.bz2 opensim-SC-df14889635cf0059b50b01a0b648de9ab92835a7.tar.xz |
some initial work on new prim meshing routines (incomplete)
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/PrimMesher.cs | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/Meshing/PrimMesher.cs b/OpenSim/Region/Physics/Meshing/PrimMesher.cs new file mode 100644 index 0000000..af39ce1 --- /dev/null +++ b/OpenSim/Region/Physics/Meshing/PrimMesher.cs | |||
@@ -0,0 +1,176 @@ | |||
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 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenSim.Framework; | ||
31 | using OpenSim.Region.Physics.Manager; | ||
32 | |||
33 | namespace OpenSim.Region.Physics.Meshing | ||
34 | { | ||
35 | public struct vertex | ||
36 | { | ||
37 | public float X; | ||
38 | public float Y; | ||
39 | public float Z; | ||
40 | |||
41 | public vertex(float x, float y, float z) | ||
42 | { | ||
43 | this.X = x; | ||
44 | this.Y = y; | ||
45 | this.Z = z; | ||
46 | } | ||
47 | } | ||
48 | |||
49 | public struct face | ||
50 | { | ||
51 | public int v1; | ||
52 | public int v2; | ||
53 | public int v3; | ||
54 | |||
55 | public face(int v1, int v2, int v3) | ||
56 | { | ||
57 | this.v1 = v1; | ||
58 | this.v2 = v2; | ||
59 | this.v3 = v3; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | internal struct Angle | ||
64 | { | ||
65 | internal float angle; | ||
66 | internal float X; | ||
67 | internal float Y; | ||
68 | |||
69 | internal Angle(float angle, float x, float y) | ||
70 | { | ||
71 | this.angle = angle; | ||
72 | this.X = x; | ||
73 | this.Y = y; | ||
74 | } | ||
75 | } | ||
76 | |||
77 | internal class AngleList | ||
78 | { | ||
79 | private float iX, iY; // intersection point | ||
80 | private void intersection( float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) | ||
81 | { // ref: http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/ | ||
82 | float denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1); | ||
83 | float uaNumerator = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3); | ||
84 | |||
85 | if (denom != 0.0) | ||
86 | { | ||
87 | float ua = uaNumerator / denom; | ||
88 | iX = x1 + ua * (x2 - x1); | ||
89 | iY = y1 + ua * (y2 - y1); | ||
90 | } | ||
91 | } | ||
92 | |||
93 | internal List<Angle> angles; | ||
94 | |||
95 | // this class should have a table of most commonly computed values | ||
96 | // instead of all the trig function calls | ||
97 | // most common would be for sides = 3, 4, or 24 | ||
98 | AngleList( int sides, float startAngle, float stopAngle ) | ||
99 | { | ||
100 | angles = new List<Angle>(); | ||
101 | double twoPi = System.Math.PI * 2.0; | ||
102 | double stepSize = twoPi / sides; | ||
103 | |||
104 | int startStep = (int) (startAngle / stepSize); | ||
105 | double angle = stepSize * startStep; | ||
106 | int step = startStep; | ||
107 | double stopAngleTest = stopAngle; | ||
108 | if (stopAngle < twoPi) | ||
109 | { | ||
110 | stopAngleTest = stepSize * (int)(stopAngle / stepSize) + 1; | ||
111 | if (stopAngleTest < stopAngle) | ||
112 | stopAngleTest += stepSize; | ||
113 | if (stopAngleTest > twoPi) | ||
114 | stopAngleTest = twoPi; | ||
115 | } | ||
116 | |||
117 | while (angle <= stopAngleTest) | ||
118 | { | ||
119 | Angle newAngle; | ||
120 | newAngle.angle = (float) angle; | ||
121 | newAngle.X = (float) System.Math.Cos(angle); | ||
122 | newAngle.Y = (float) System.Math.Sin(angle); | ||
123 | angles.Add(newAngle); | ||
124 | step += 1; | ||
125 | angle = stepSize * step; | ||
126 | } | ||
127 | |||
128 | if (startAngle > angles[0].angle) | ||
129 | { | ||
130 | Angle newAngle; | ||
131 | intersection(angles[0].X, angles[0].Y, angles[1].X, angles[1].Y, 0.0f, 0.0f, (float)Math.Cos(startAngle), (float)Math.Sin(startAngle)); | ||
132 | newAngle.angle = startAngle; | ||
133 | newAngle.X = iX; | ||
134 | newAngle.Y = iY; | ||
135 | angles[0] = newAngle; | ||
136 | } | ||
137 | |||
138 | int index = angles.Count - 1; | ||
139 | if (stopAngle < angles[index].angle) | ||
140 | { | ||
141 | Angle newAngle; | ||
142 | intersection(angles[index - 1].X, angles[index - 1].Y, angles[index].X, angles[index].Y, 0.0f, 0.0f, (float)Math.Cos(stopAngle), (float)Math.Sin(stopAngle)); | ||
143 | newAngle.angle = stopAngle; | ||
144 | newAngle.X = iX; | ||
145 | newAngle.Y = iY; | ||
146 | angles[index] = newAngle; | ||
147 | } | ||
148 | } | ||
149 | } | ||
150 | |||
151 | internal class PrimProfile | ||
152 | { | ||
153 | internal List<vertex> vertices; | ||
154 | internal List<face> faces; | ||
155 | |||
156 | PrimProfile() | ||
157 | { | ||
158 | vertices = new List<vertex>(); | ||
159 | faces = new List<face>(); | ||
160 | } | ||
161 | } | ||
162 | |||
163 | public class PrimMesher | ||
164 | { | ||
165 | public List<vertex> vertices; | ||
166 | public List<face> faces; | ||
167 | |||
168 | PrimMesher() | ||
169 | { | ||
170 | vertices = new List<vertex>(); | ||
171 | faces = new List<face>(); | ||
172 | |||
173 | |||
174 | } | ||
175 | } | ||
176 | } | ||