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
168
169
170
171
|
using System;
namespace NW4RTools {
public enum ByteEndian {
LittleEndian,
BigEndian
}
public struct Color {
public byte r, g, b, a;
public uint Rgba {
get {
return ((uint)r << 24) | ((uint)g << 16) | ((uint)b << 8) | (uint)a;
}
set {
r = (byte)((value & 0xFF000000) >> 24);
g = (byte)((value & 0x00FF0000) >> 16);
b = (byte)((value & 0x0000FF00) >> 8);
a = (byte)(value & 0x000000FF);
}
}
public Color(byte _r, byte _g, byte _b, byte _a) {
r = _r;
g = _g;
b = _b;
a = _a;
}
}
public struct Vec3 {
public float x, y, z;
public Vec3(float _x, float _y, float _z) {
x = _x;
y = _y;
z = _z;
}
}
public struct Vec2 {
public float x, y;
public Vec2(float _x, float _y) {
x = _x;
y = _y;
}
}
// TODO: Convert this to a packed struct, and change this[,] to use pointers
public struct Matrix {
public float v00, v01, v02, v03, v10, v11, v12, v13, v20, v21, v22, v23;
public void Identity() {
v00 = 1.0f;
v01 = 0.0f;
v02 = 0.0f;
v03 = 0.0f;
v10 = 0.0f;
v11 = 1.0f;
v12 = 0.0f;
v13 = 0.0f;
v20 = 0.0f;
v21 = 0.0f;
v22 = 1.0f;
v23 = 0.0f;
}
public float this[int x, int y] {
get {
switch (y) {
case 0:
switch (x) {
case 0:
return v00;
case 1:
return v01;
case 2:
return v02;
case 3:
return v03;
}
break;
case 1:
switch (x) {
case 0:
return v10;
case 1:
return v11;
case 2:
return v12;
case 3:
return v13;
}
break;
case 2:
switch (x) {
case 0:
return v20;
case 1:
return v21;
case 2:
return v22;
case 3:
return v23;
}
break;
}
throw new IndexOutOfRangeException();
}
set {
switch (y) {
case 0:
switch (x) {
case 0:
v00 = value;
break;
case 1:
v01 = value;
break;
case 2:
v02 = value;
break;
case 3:
v03 = value;
break;
}
break;
case 1:
switch (x) {
case 0:
v10 = value;
break;
case 1:
v11 = value;
break;
case 2:
v12 = value;
break;
case 3:
v13 = value;
break;
}
break;
case 2:
switch (x) {
case 0:
v20 = value;
break;
case 1:
v21 = value;
break;
case 2:
v22 = value;
break;
case 3:
v23 = value;
break;
}
break;
}
throw new IndexOutOfRangeException();
}
}
}
}
|