aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs')
-rw-r--r--OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs167
1 files changed, 167 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs b/OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs
new file mode 100644
index 0000000..edd58d3
--- /dev/null
+++ b/OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs
@@ -0,0 +1,167 @@
1// adapted from libomv removing cpu endian adjust
2// for prims lowlevel serialization
3
4using System;
5using System.IO;
6using OpenMetaverse;
7
8namespace OpenSim.Region.Physics.OdePlugin
9{
10 public class wstreamer
11 {
12 private MemoryStream st;
13
14 public wstreamer()
15 {
16 st = new MemoryStream();
17 }
18
19 public byte[] close()
20 {
21 byte[] data = st.ToArray();
22 st.Close();
23 return data;
24 }
25
26 public void Wshort(short value)
27 {
28 st.Write(BitConverter.GetBytes(value), 0, 2);
29 }
30 public void Wushort(ushort value)
31 {
32 byte[] t = BitConverter.GetBytes(value);
33 st.Write(BitConverter.GetBytes(value), 0, 2);
34 }
35 public void Wint(int value)
36 {
37 st.Write(BitConverter.GetBytes(value), 0, 4);
38 }
39 public void Wuint(uint value)
40 {
41 st.Write(BitConverter.GetBytes(value), 0, 4);
42 }
43 public void Wlong(long value)
44 {
45 st.Write(BitConverter.GetBytes(value), 0, 8);
46 }
47 public void Wulong(ulong value)
48 {
49 st.Write(BitConverter.GetBytes(value), 0, 8);
50 }
51
52 public void Wfloat(float value)
53 {
54 st.Write(BitConverter.GetBytes(value), 0, 4);
55 }
56
57 public void Wdouble(double value)
58 {
59 st.Write(BitConverter.GetBytes(value), 0, 8);
60 }
61
62 public void Wvector3(Vector3 value)
63 {
64 st.Write(BitConverter.GetBytes(value.X), 0, 4);
65 st.Write(BitConverter.GetBytes(value.Y), 0, 4);
66 st.Write(BitConverter.GetBytes(value.Z), 0, 4);
67 }
68 public void Wquat(Quaternion value)
69 {
70 st.Write(BitConverter.GetBytes(value.X), 0, 4);
71 st.Write(BitConverter.GetBytes(value.Y), 0, 4);
72 st.Write(BitConverter.GetBytes(value.Z), 0, 4);
73 st.Write(BitConverter.GetBytes(value.W), 0, 4);
74 }
75 }
76
77 public class rstreamer
78 {
79 private byte[] rbuf;
80 private int ptr;
81
82 public rstreamer(byte[] data)
83 {
84 rbuf = data;
85 ptr = 0;
86 }
87
88 public void close()
89 {
90 }
91
92 public short Rshort()
93 {
94 short v = BitConverter.ToInt16(rbuf, ptr);
95 ptr += 2;
96 return v;
97 }
98 public ushort Rushort()
99 {
100 ushort v = BitConverter.ToUInt16(rbuf, ptr);
101 ptr += 2;
102 return v;
103 }
104 public int Rint()
105 {
106 int v = BitConverter.ToInt32(rbuf, ptr);
107 ptr += 4;
108 return v;
109 }
110 public uint Ruint()
111 {
112 uint v = BitConverter.ToUInt32(rbuf, ptr);
113 ptr += 4;
114 return v;
115 }
116 public long Rlong()
117 {
118 long v = BitConverter.ToInt64(rbuf, ptr);
119 ptr += 8;
120 return v;
121 }
122 public ulong Rulong()
123 {
124 ulong v = BitConverter.ToUInt64(rbuf, ptr);
125 ptr += 8;
126 return v;
127 }
128 public float Rfloat()
129 {
130 float v = BitConverter.ToSingle(rbuf, ptr);
131 ptr += 4;
132 return v;
133 }
134
135 public double Rdouble()
136 {
137 double v = BitConverter.ToDouble(rbuf, ptr);
138 ptr += 8;
139 return v;
140 }
141
142 public Vector3 Rvector3()
143 {
144 Vector3 v;
145 v.X = BitConverter.ToSingle(rbuf, ptr);
146 ptr += 4;
147 v.Y = BitConverter.ToSingle(rbuf, ptr);
148 ptr += 4;
149 v.Z = BitConverter.ToSingle(rbuf, ptr);
150 ptr += 4;
151 return v;
152 }
153 public Quaternion Rquat()
154 {
155 Quaternion v;
156 v.X = BitConverter.ToSingle(rbuf, ptr);
157 ptr += 4;
158 v.Y = BitConverter.ToSingle(rbuf, ptr);
159 ptr += 4;
160 v.Z = BitConverter.ToSingle(rbuf, ptr);
161 ptr += 4;
162 v.W = BitConverter.ToSingle(rbuf, ptr);
163 ptr += 4;
164 return v;
165 }
166 }
167}