aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs
blob: edd58d3bfce6a04de208273237a099ba201f8ccd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// adapted from libomv removing cpu endian adjust
// for prims lowlevel serialization

using System;
using System.IO;
using OpenMetaverse;

namespace OpenSim.Region.Physics.OdePlugin
{
    public class wstreamer
    {
        private MemoryStream st;

        public wstreamer()
        {
            st = new MemoryStream();
        }

        public byte[] close()
        {
            byte[] data = st.ToArray();
            st.Close();
            return data;
        }

        public void Wshort(short value)
        {
            st.Write(BitConverter.GetBytes(value), 0, 2);
        }
        public void Wushort(ushort value)
        {
            byte[] t = BitConverter.GetBytes(value);
            st.Write(BitConverter.GetBytes(value), 0, 2);
        }
        public void Wint(int value)
        {
            st.Write(BitConverter.GetBytes(value), 0, 4);
        }
        public void Wuint(uint value)
        {
            st.Write(BitConverter.GetBytes(value), 0, 4);
        }
        public void Wlong(long value)
        {
            st.Write(BitConverter.GetBytes(value), 0, 8);
        }
        public void Wulong(ulong value)
        {
            st.Write(BitConverter.GetBytes(value), 0, 8);
        }

        public void Wfloat(float value)
        {
            st.Write(BitConverter.GetBytes(value), 0, 4);
        }

        public void Wdouble(double value)
        {
            st.Write(BitConverter.GetBytes(value), 0, 8);
        }

        public void Wvector3(Vector3 value)
        {
            st.Write(BitConverter.GetBytes(value.X), 0, 4);
            st.Write(BitConverter.GetBytes(value.Y), 0, 4);
            st.Write(BitConverter.GetBytes(value.Z), 0, 4);
        }
        public void Wquat(Quaternion value)
        {
            st.Write(BitConverter.GetBytes(value.X), 0, 4);
            st.Write(BitConverter.GetBytes(value.Y), 0, 4);
            st.Write(BitConverter.GetBytes(value.Z), 0, 4);
            st.Write(BitConverter.GetBytes(value.W), 0, 4);
        }
    }

    public class rstreamer
    {
        private byte[] rbuf;
        private int ptr;

        public rstreamer(byte[] data)
        {
            rbuf = data;
            ptr = 0;
        }

        public void close()
        {
        }

        public short Rshort()
        {
            short v = BitConverter.ToInt16(rbuf, ptr);
            ptr += 2;
            return v;
        }
        public ushort Rushort()
        {
            ushort v = BitConverter.ToUInt16(rbuf, ptr);
            ptr += 2;
            return v;
        }
        public int Rint()
        {
            int v = BitConverter.ToInt32(rbuf, ptr);
            ptr += 4;
            return v;
        }
        public uint Ruint()
        {
            uint v = BitConverter.ToUInt32(rbuf, ptr);
            ptr += 4;
            return v;
        }
        public long Rlong()
        {
            long v = BitConverter.ToInt64(rbuf, ptr);
            ptr += 8;
            return v;
        }
        public ulong Rulong()
        {
            ulong v = BitConverter.ToUInt64(rbuf, ptr);
            ptr += 8;
            return v;
        }
        public float Rfloat()
        {
            float v = BitConverter.ToSingle(rbuf, ptr);
            ptr += 4;
            return v;
        }

        public double Rdouble()
        {
            double v = BitConverter.ToDouble(rbuf, ptr);
            ptr += 8;
            return v;
        }

        public Vector3 Rvector3()
        {
            Vector3 v;
            v.X = BitConverter.ToSingle(rbuf, ptr);
            ptr += 4;
            v.Y = BitConverter.ToSingle(rbuf, ptr);
            ptr += 4;
            v.Z = BitConverter.ToSingle(rbuf, ptr);
            ptr += 4;
            return v;
        }
        public Quaternion Rquat()
        {
            Quaternion v;
            v.X = BitConverter.ToSingle(rbuf, ptr);
            ptr += 4;
            v.Y = BitConverter.ToSingle(rbuf, ptr);
            ptr += 4;
            v.Z = BitConverter.ToSingle(rbuf, ptr);
            ptr += 4;
            v.W = BitConverter.ToSingle(rbuf, ptr);
            ptr += 4;
            return v;
        }
    }
}