Jypeli 10
The simple game programming library
MathReader.cs
Siirry tämän tiedoston dokumentaatioon.
1#region MIT License
2/*
3 * Copyright (c) 2005-2008 Jonathan Mark Porter. http://physics2d.googlepages.com/
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22#endregion
23
24
25
26
27#if UseDouble
28using Scalar = System.Double;
29#else
30using Scalar = System.Single;
31#endif
32using System;
33using System.IO;
34using System.Text;
35
37{
38 public class MathReader : BinaryReader
39 {
40 protected static Stream GetBaseStream(BinaryReader reader)
41 {
42 if (reader == null) { throw new ArgumentNullException("reader"); }
43 return reader.BaseStream;
44 }
45 public MathReader(Stream input)
46 : base(input) { }
47 public MathReader(Stream input, Encoding encoding)
48 : base(input, encoding) { }
49 public MathReader(BinaryReader reader)
50 : base(GetBaseStream(reader)) { }
52 {
53#if UseDouble
54 return base.ReadDouble();
55#else
56 return base.ReadSingle();
57#endif
58 }
59
61 {
62 Vector2D returnvalue;
63 returnvalue.X = ReadScalar();
64 returnvalue.Y = ReadScalar();
65 return returnvalue;
66 }
68 {
69 Vector3D returnvalue;
70 returnvalue.X = ReadScalar();
71 returnvalue.Y = ReadScalar();
72 returnvalue.Z = ReadScalar();
73 return returnvalue;
74 }
76 {
77 Vector4D returnvalue;
78 returnvalue.X = ReadScalar();
79 returnvalue.Y = ReadScalar();
80 returnvalue.Z = ReadScalar();
81 returnvalue.W = ReadScalar();
82 return returnvalue;
83 }
85 {
86 Quaternion returnvalue;
87 returnvalue.X = ReadScalar();
88 returnvalue.Y = ReadScalar();
89 returnvalue.Z = ReadScalar();
90 returnvalue.W = ReadScalar();
91 return returnvalue;
92 }
94 {
95 Matrix2x2 returnvalue;
96
97 returnvalue.m00 = ReadScalar();
98 returnvalue.m01 = ReadScalar();
99
100 returnvalue.m10 = ReadScalar();
101 returnvalue.m11 = ReadScalar();
102
103 return returnvalue;
104 }
106 {
107 Matrix3x3 returnvalue;
108
109 returnvalue.m00 = ReadScalar();
110 returnvalue.m01 = ReadScalar();
111 returnvalue.m02 = ReadScalar();
112
113 returnvalue.m10 = ReadScalar();
114 returnvalue.m11 = ReadScalar();
115 returnvalue.m12 = ReadScalar();
116
117 returnvalue.m20 = ReadScalar();
118 returnvalue.m21 = ReadScalar();
119 returnvalue.m22 = ReadScalar();
120
121 return returnvalue;
122 }
124 {
125 Matrix4x4 returnvalue;
126
127 returnvalue.m00 = ReadScalar();
128 returnvalue.m01 = ReadScalar();
129 returnvalue.m02 = ReadScalar();
130 returnvalue.m03 = ReadScalar();
131
132 returnvalue.m10 = ReadScalar();
133 returnvalue.m11 = ReadScalar();
134 returnvalue.m12 = ReadScalar();
135 returnvalue.m13 = ReadScalar();
136
137 returnvalue.m20 = ReadScalar();
138 returnvalue.m21 = ReadScalar();
139 returnvalue.m22 = ReadScalar();
140 returnvalue.m23 = ReadScalar();
141
142 returnvalue.m30 = ReadScalar();
143 returnvalue.m31 = ReadScalar();
144 returnvalue.m32 = ReadScalar();
145 returnvalue.m33 = ReadScalar();
146
147 return returnvalue;
148 }
149
151 {
152 Scalar[] returnvalue = new Scalar[ReadInt32()];
153 for (int index = 0; index < returnvalue.Length; index++)
154 {
155 returnvalue[index] = ReadScalar();
156 }
157 return returnvalue;
158 }
159 }
160}
System.Single Scalar
Definition: Clamped.cs:29
Quaternion ReadQuaternion()
Definition: MathReader.cs:84
MathReader(Stream input)
Definition: MathReader.cs:45
Matrix2x2 ReadMatrix2x2()
Definition: MathReader.cs:93
MathReader(Stream input, Encoding encoding)
Definition: MathReader.cs:47
MathReader(BinaryReader reader)
Definition: MathReader.cs:49
static Stream GetBaseStream(BinaryReader reader)
Definition: MathReader.cs:40
A 2x2 matrix which can represent rotations for 2D vectors.
Definition: Matrix2x2.cs:58
A 3x3 matrix which can represent rotations around axes.
Definition: Matrix3x3.cs:62
Summary description for Quaternion.
Definition: Quaternion.cs:82
This is the Vector Class.
Definition: Vector2D.cs:50
Scalar X
This is the X value. (Usually represents a horizontal position or direction.)
Definition: Vector2D.cs:796
Scalar Y
This is the Y value. (Usually represents a vertical position or direction.)
Definition: Vector2D.cs:805
A Vector with 3 dimensions.
Definition: Vector3D.cs:47
Scalar X
This is the X value.
Definition: Vector3D.cs:692
Scalar Y
This is the Y value.
Definition: Vector3D.cs:701
Scalar Z
This is the Z value.
Definition: Vector3D.cs:710
A Vector with 4 dimensions.
Definition: Vector4D.cs:48
Scalar X
This is the X value.
Definition: Vector4D.cs:710
Scalar Y
This is the Y value.
Definition: Vector4D.cs:719
Scalar Z
This is the Z value.
Definition: Vector4D.cs:728
Scalar W
This is the W value.
Definition: Vector4D.cs:737