aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/types
diff options
context:
space:
mode:
authorgareth2007-02-27 23:00:49 +0000
committergareth2007-02-27 23:00:49 +0000
commit09dd4bd6834861791008e66652826a66724efa0e (patch)
treeae2b10c3b6ce3fab4c516c6710d4fa0adafedb77 /src/types
parentRemoved old trunk code (diff)
downloadopensim-SC_OLD-09dd4bd6834861791008e66652826a66724efa0e.zip
opensim-SC_OLD-09dd4bd6834861791008e66652826a66724efa0e.tar.gz
opensim-SC_OLD-09dd4bd6834861791008e66652826a66724efa0e.tar.bz2
opensim-SC_OLD-09dd4bd6834861791008e66652826a66724efa0e.tar.xz
Brought in code from branches/gareth
Diffstat (limited to 'src/types')
-rw-r--r--src/types/BitPack.cs138
-rw-r--r--src/types/Mesh.cs28
-rw-r--r--src/types/Triangle.cs28
3 files changed, 194 insertions, 0 deletions
diff --git a/src/types/BitPack.cs b/src/types/BitPack.cs
new file mode 100644
index 0000000..1abbcf0
--- /dev/null
+++ b/src/types/BitPack.cs
@@ -0,0 +1,138 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.types
6{
7 /* New Method
8 *
9 * 1. Get all the individual bytes and their bitlength, put them in a dictionary
10 * 2. Mash together when wanted.
11 *
12 * */
13 public class Bits {
14 public byte[] data;
15 public int len;
16 }
17
18 public class InverseBitPack
19 {
20 private List<Bits> bits;
21
22 public InverseBitPack()
23 {
24 bits = new List<Bits>();
25 }
26 }
27
28 public class BitPack
29 {
30 private const int MAX_BITS = 8;
31
32 private byte[] Data;
33 private int bytePos;
34 private int bitPos;
35
36 public BitPack(byte[] data, int pos) // For libsl compatibility
37 {
38 Data = data;
39 bytePos = pos;
40 }
41
42 public BitPack() // Encoding version
43 {
44
45 }
46
47 public void LoadData(byte[] data, int pos) {
48 Data = data;
49 bytePos = pos;
50 bitPos = 0;
51 }
52
53 private void PackBitsArray(byte[] bits, int bitLen)
54 {
55 int offset = bitPos % MAX_BITS;
56 int i;
57 byte temp1;
58 byte temp2;
59
60 for (i = 0; i < bits.Length; i++)
61 {
62 int Byte = bits[i];
63 Byte <<= offset;
64 temp1 = (byte)(Byte & 0xFF);
65 temp2 = (byte)((Byte >> 8) & 0xFF);
66
67 Data[Data.Length - 1] |= temp1;
68// Data
69
70 bitPos += bitLen;
71 }
72 }
73
74 public float UnpackFloat()
75 {
76 byte[] output = UnpackBitsArray(32);
77
78 if (!BitConverter.IsLittleEndian) Array.Reverse(output);
79 return BitConverter.ToSingle(output, 0);
80 }
81
82 public int UnpackBits(int totalCount)
83 {
84 byte[] output = UnpackBitsArray(totalCount);
85
86 if (!BitConverter.IsLittleEndian) Array.Reverse(output);
87 return BitConverter.ToInt32(output, 0);
88 }
89
90 private byte[] UnpackBitsArray(int totalCount)
91 {
92 int count = 0;
93 byte[] output = new byte[4];
94 int curBytePos = 0;
95 int curBitPos = 0;
96
97 while (totalCount > 0)
98 {
99 if (totalCount > MAX_BITS)
100 {
101 count = MAX_BITS;
102 totalCount -= MAX_BITS;
103 }
104 else
105 {
106 count = totalCount;
107 totalCount = 0;
108 }
109
110 while (count > 0)
111 {
112 // Shift the previous bits
113 output[curBytePos] <<= 1;
114
115 // Grab one bit
116 if ((Data[bytePos] & (0x80 >> bitPos++)) != 0)
117 ++output[curBytePos];
118
119 --count;
120 ++curBitPos;
121
122 if (bitPos >= MAX_BITS)
123 {
124 bitPos = 0;
125 ++bytePos;
126 }
127 if (curBitPos >= MAX_BITS)
128 {
129 curBitPos = 0;
130 ++curBytePos;
131 }
132 }
133 }
134
135 return output;
136 }
137 }
138}
diff --git a/src/types/Mesh.cs b/src/types/Mesh.cs
new file mode 100644
index 0000000..3e00c91
--- /dev/null
+++ b/src/types/Mesh.cs
@@ -0,0 +1,28 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.types
6{
7 // TODO: This will need some performance tuning no doubt.
8 public class Mesh
9 {
10 public List<Triangle> mesh;
11
12 public Mesh()
13 {
14 mesh = new List<Triangle>();
15 }
16
17 public void AddTri(Triangle tri)
18 {
19 mesh.Add(tri);
20 }
21
22 public static Mesh operator +(Mesh a, Mesh b)
23 {
24 a.mesh.AddRange(b.mesh);
25 return a;
26 }
27 }
28}
diff --git a/src/types/Triangle.cs b/src/types/Triangle.cs
new file mode 100644
index 0000000..8dfea6e
--- /dev/null
+++ b/src/types/Triangle.cs
@@ -0,0 +1,28 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using Axiom.MathLib;
5
6namespace OpenSim.types
7{
8 public class Triangle
9 {
10 Vector3 a;
11 Vector3 b;
12 Vector3 c;
13
14 public Triangle()
15 {
16 a = new Vector3();
17 b = new Vector3();
18 c = new Vector3();
19 }
20
21 public Triangle(Vector3 A, Vector3 B, Vector3 C)
22 {
23 a = A;
24 b = B;
25 c = C;
26 }
27 }
28}