Skip to content

Commit 6434cef

Browse files
authored
Shorten FloatMath function and call it more consistently (KhronosGroup#539)
1 parent c81b229 commit 6434cef

10 files changed

+38
-44
lines changed

Source/FloatMath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ static class FloatMath
44
{
55
public const float Pi = 3.14159265f;
66

7-
public static float ConvertDegreesToRadians(float degrees)
7+
public static float ToRadians(float degrees)
88
{
99
return degrees * Pi / 180.0f;
1010
}

Source/ModelGroup_SkinB.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protected static partial class Nodes
1313
var colorInner = new Vector4(0.8f, 0.8f, 0.8f, 1.0f);
1414
var colorOuter = new Vector4(0.0f, 0.0f, 1.0f, 1.0f);
1515

16-
Matrix4x4 rotation = Matrix4x4.CreateFromYawPitchRoll(0.0f, FloatMath.ConvertDegreesToRadians(90.0f), 0.0f);
16+
Matrix4x4 rotation = Matrix4x4.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(90), 0.0f);
1717
var translationVectorJoint1 = new Vector3(0.0f, 0.0f, -0.6f);
1818
var translationVectorJoint0 = new Vector3(0.0f, 0.0f, 0.3f);
1919
Matrix4x4 matrixJoint1 = Matrix4x4.CreateTranslation(translationVectorJoint1);

Source/ModelGroup_SkinBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ protected static partial class Nodes
5151
}
5252
}
5353

54-
Matrix4x4 baseRotation = Matrix4x4.CreateFromYawPitchRoll(0.0f, FloatMath.ConvertDegreesToRadians(-90.0f), 0.0f);
55-
Quaternion jointRotation = Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateFromYawPitchRoll(0.0f, FloatMath.ConvertDegreesToRadians(-30.0f), 0.0f));
54+
Matrix4x4 baseRotation = Matrix4x4.CreateFromYawPitchRoll(0.0f, -FloatMath.ToRadians(90), 0.0f);
55+
Quaternion jointRotation = Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(-30.0f), 0.0f));
5656
var translationVector = new Vector3(0.0f, 0.0f, vertexHeightOffset);
5757
var translationVectorJoint0 = new Vector3(0.0f, startHeight, 0.0f);
5858
var matrixJoint0 = Matrix4x4.CreateTranslation(new Vector3(0.0f, 0.0f, startHeight));

Source/ModelGroup_SkinE.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ protected static partial class Nodes
8181

8282
private static List<Runtime.Node> CreateJointsAndWeightsForCommonRoot(Runtime.Node nodePlane)
8383
{
84-
Matrix4x4 baseRotation = Matrix4x4.CreateFromYawPitchRoll(0.0f, FloatMath.ConvertDegreesToRadians(-90.0f), 0.0f);
85-
Matrix4x4 jointRotation = Matrix4x4.CreateFromYawPitchRoll(0.0f, FloatMath.ConvertDegreesToRadians(-15.0f), 0.0f);
84+
Matrix4x4 baseRotation = Matrix4x4.CreateFromYawPitchRoll(0.0f, -FloatMath.ToRadians(90), 0.0f);
85+
Matrix4x4 jointRotation = Matrix4x4.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(-15.0f), 0.0f);
8686
var translationVectorJoint3 = new Vector3(0.1875f, 0.0f, 0.25f);
8787
var translationVectorJoint2 = new Vector3(-0.1875f, 0.0f, 0.25f);
8888
var translationVectorJoint1 = new Vector3(0.0f, 0.0f, 0.25f);
@@ -271,8 +271,8 @@ protected static partial class Nodes
271271

272272
private static List<Runtime.Node> CreateJointsAndWeightsForMultipleRoots(Runtime.Node nodePlane)
273273
{
274-
Matrix4x4 baseRotation = Matrix4x4.CreateFromYawPitchRoll(0.0f, FloatMath.ConvertDegreesToRadians(-90.0f), 0.0f);
275-
Matrix4x4 jointRotation = Matrix4x4.CreateFromYawPitchRoll(0.0f, FloatMath.ConvertDegreesToRadians(-15.0f), 0.0f);
274+
Matrix4x4 baseRotation = Matrix4x4.CreateFromYawPitchRoll(0.0f, -FloatMath.ToRadians(90), 0.0f);
275+
Matrix4x4 jointRotation = Matrix4x4.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(-15.0f), 0.0f);
276276
var translationVectorJoint3 = new Vector3(0.0f, 0.25f, 0.0f);
277277
var translationVectorJoint2 = new Vector3(0.0f, 0.0f, 0.25f);
278278
var translationVectorJoint1 = new Vector3(0.1875f, -0.25f, 0.0f);

Source/ModelGroups/Animation_Node.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ void SetLinearSamplerForScale(List<Property> properties, Runtime.AnimationChanne
140140

141141
void SetLinearSamplerForRotation(List<Property> properties, Runtime.AnimationChannel channel)
142142
{
143-
var quarterTurn = (FloatMath.Pi / 2.0f);
144143
channel.Sampler = new Runtime.LinearAnimationSampler<Quaternion>
145144
(
146145
new[]
@@ -153,11 +152,11 @@ void SetLinearSamplerForRotation(List<Property> properties, Runtime.AnimationCha
153152
},
154153
new[]
155154
{
156-
Quaternion.CreateFromYawPitchRoll(quarterTurn, 0.0f, 0.0f),
155+
Quaternion.CreateFromYawPitchRoll(FloatMath.ToRadians(90), 0.0f, 0.0f),
157156
Quaternion.Identity,
158-
Quaternion.CreateFromYawPitchRoll(-quarterTurn, 0.0f, 0.0f),
157+
Quaternion.CreateFromYawPitchRoll(-FloatMath.ToRadians(90), 0.0f, 0.0f),
159158
Quaternion.Identity,
160-
Quaternion.CreateFromYawPitchRoll(quarterTurn, 0.0f, 0.0f),
159+
Quaternion.CreateFromYawPitchRoll(FloatMath.ToRadians(90), 0.0f, 0.0f),
161160
}
162161
);
163162

@@ -227,7 +226,6 @@ void SetCubicSplineSamplerForTranslation(List<Property> properties, Runtime.Anim
227226

228227
void CreateCubicSplineSamplerForRotation(List<Property> properties, Runtime.AnimationChannel channel)
229228
{
230-
var quarterTurn = (FloatMath.Pi / 2.0f);
231229
channel.Sampler = new Runtime.CubicSplineAnimationSampler<Quaternion>
232230
(
233231
new[]
@@ -243,7 +241,7 @@ void CreateCubicSplineSamplerForRotation(List<Property> properties, Runtime.Anim
243241
new Runtime.CubicSplineAnimationSampler<Quaternion>.Key
244242
{
245243
InTangent = new Quaternion(0.0f, 0.0f, 0.0f, 0.0f),
246-
Value = Quaternion.CreateFromYawPitchRoll(quarterTurn, 0.0f, 0.0f),
244+
Value = Quaternion.CreateFromYawPitchRoll(FloatMath.ToRadians(90), 0.0f, 0.0f),
247245
OutTangent = new Quaternion(0.0f, 0.0f, 0.0f, 0.0f)
248246
},
249247
new Runtime.CubicSplineAnimationSampler<Quaternion>.Key
@@ -255,7 +253,7 @@ void CreateCubicSplineSamplerForRotation(List<Property> properties, Runtime.Anim
255253
new Runtime.CubicSplineAnimationSampler<Quaternion>.Key
256254
{
257255
InTangent = new Quaternion(0.0f, 0.0f, 0.0f, 0.0f),
258-
Value = Quaternion.CreateFromYawPitchRoll(-quarterTurn, 0.0f, 0.0f),
256+
Value = Quaternion.CreateFromYawPitchRoll(-FloatMath.ToRadians(90), 0.0f, 0.0f),
259257
OutTangent = new Quaternion(0.0f, 0.0f, 0.0f, 0.0f)
260258
},
261259
new Runtime.CubicSplineAnimationSampler<Quaternion>.Key
@@ -267,7 +265,7 @@ void CreateCubicSplineSamplerForRotation(List<Property> properties, Runtime.Anim
267265
new Runtime.CubicSplineAnimationSampler<Quaternion>.Key
268266
{
269267
InTangent = new Quaternion(0.0f, 0.0f, 0.0f, 0.0f),
270-
Value = Quaternion.CreateFromYawPitchRoll(quarterTurn, 0.0f, 0.0f),
268+
Value = Quaternion.CreateFromYawPitchRoll(FloatMath.ToRadians(90), 0.0f, 0.0f),
271269
OutTangent = new Quaternion(0.0f, 0.0f, 0.0f, 0.0f)
272270
},
273271
}

Source/ModelGroups/Animation_NodeMisc.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ void SetLinearSamplerForTranslation(Runtime.AnimationChannel channel)
110110

111111
void SetLinearSamplerForHorizontalRotation(Runtime.AnimationChannel channel)
112112
{
113-
var quarterTurn = (FloatMath.Pi / 2.0f);
114113
channel.Sampler = new Runtime.LinearAnimationSampler<Quaternion>
115114
(
116115
new[]
@@ -123,18 +122,17 @@ void SetLinearSamplerForHorizontalRotation(Runtime.AnimationChannel channel)
123122
},
124123
new[]
125124
{
126-
Quaternion.CreateFromYawPitchRoll(quarterTurn, 0.0f, 0.0f),
125+
Quaternion.CreateFromYawPitchRoll(FloatMath.ToRadians(90), 0.0f, 0.0f),
127126
Quaternion.Identity,
128-
Quaternion.CreateFromYawPitchRoll(-quarterTurn, 0.0f, 0.0f),
127+
Quaternion.CreateFromYawPitchRoll(-FloatMath.ToRadians(90), 0.0f, 0.0f),
129128
Quaternion.Identity,
130-
Quaternion.CreateFromYawPitchRoll(quarterTurn, 0.0f, 0.0f),
129+
Quaternion.CreateFromYawPitchRoll(FloatMath.ToRadians(90), 0.0f, 0.0f),
131130
}
132131
);
133132
}
134133

135134
void SetLinearSamplerForVerticalRotation(Runtime.AnimationChannel channel)
136135
{
137-
var quarterTurn = (FloatMath.Pi / 2.0f);
138136
channel.Sampler = new Runtime.LinearAnimationSampler<Quaternion>
139137
(
140138
new[]
@@ -147,11 +145,11 @@ void SetLinearSamplerForVerticalRotation(Runtime.AnimationChannel channel)
147145
},
148146
new[]
149147
{
150-
Quaternion.CreateFromYawPitchRoll(0.0f, quarterTurn, 0.0f),
148+
Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(90), 0.0f),
151149
Quaternion.Identity,
152-
Quaternion.CreateFromYawPitchRoll(0.0f, -quarterTurn, 0.0f),
150+
Quaternion.CreateFromYawPitchRoll(0.0f, -FloatMath.ToRadians(90), 0.0f),
153151
Quaternion.Identity,
154-
Quaternion.CreateFromYawPitchRoll(0.0f, quarterTurn, 0.0f),
152+
Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(90), 0.0f),
155153
}
156154
);
157155
}
@@ -209,7 +207,6 @@ void SetLinearSamplerWithOneKey(Runtime.AnimationChannel channel)
209207

210208
void SetLinearSamplerForRotationThatStartsAboveZero(Runtime.AnimationChannel channel)
211209
{
212-
var quarterTurn = (FloatMath.Pi / 2.0f);
213210
channel.Sampler = new Runtime.LinearAnimationSampler<Quaternion>
214211
(
215212
new[]
@@ -222,11 +219,11 @@ void SetLinearSamplerForRotationThatStartsAboveZero(Runtime.AnimationChannel cha
222219
},
223220
new[]
224221
{
225-
Quaternion.CreateFromYawPitchRoll(quarterTurn, 0.0f, 0.0f),
222+
Quaternion.CreateFromYawPitchRoll(FloatMath.ToRadians(90), 0.0f, 0.0f),
226223
Quaternion.Identity,
227-
Quaternion.CreateFromYawPitchRoll(-quarterTurn, 0.0f, 0.0f),
224+
Quaternion.CreateFromYawPitchRoll(-FloatMath.ToRadians(90), 0.0f, 0.0f),
228225
Quaternion.Identity,
229-
Quaternion.CreateFromYawPitchRoll(quarterTurn, 0.0f, 0.0f),
226+
Quaternion.CreateFromYawPitchRoll(FloatMath.ToRadians(90), 0.0f, 0.0f),
230227
}
231228
);
232229
}

Source/ModelGroups/Animation_SamplerType.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Model CreateModel(AnimationSampler.ComponentTypeEnum samplerOutputComponentType,
2020
{
2121
var properties = new List<Property>();
2222
var cubeMeshPrimitive = MeshPrimitive.CreateCube();
23-
var quarterTurn = (FloatMath.Pi / 2.0f);
2423

2524
// Apply the common properties to the gltf.
2625
cubeMeshPrimitive.Material = new Runtime.Material
@@ -59,11 +58,11 @@ Model CreateModel(AnimationSampler.ComponentTypeEnum samplerOutputComponentType,
5958
},
6059
new[]
6160
{
62-
Quaternion.CreateFromYawPitchRoll(quarterTurn, 0.0f, 0.0f),
61+
Quaternion.CreateFromYawPitchRoll(FloatMath.ToRadians(90), 0.0f, 0.0f),
6362
Quaternion.Identity,
64-
Quaternion.CreateFromYawPitchRoll(-quarterTurn, 0.0f, 0.0f),
63+
Quaternion.CreateFromYawPitchRoll(-FloatMath.ToRadians(90), 0.0f, 0.0f),
6564
Quaternion.Identity,
66-
Quaternion.CreateFromYawPitchRoll(quarterTurn, 0.0f, 0.0f),
65+
Quaternion.CreateFromYawPitchRoll(FloatMath.ToRadians(90), 0.0f, 0.0f),
6766
},
6867
outputComponentType: samplerOutputComponentType
6968
)

Source/ModelGroups/Animation_Skin.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Runtime.Animation CreateFoldingAnimation(Runtime.Node jointRootNode, List<Runtim
9999
}
100100

101101
Runtime.Node nodeCheck = jointRootNode;
102-
float pitchValue = FloatMath.ConvertDegreesToRadians(-90.0f);
102+
float pitchValue = -FloatMath.ToRadians(90);
103103
var nodeList = new List<Runtime.Node>
104104
{
105105
jointRootNode,
@@ -308,7 +308,7 @@ Runtime.Animation CreateFoldingAnimation(Runtime.Node jointRootNode, List<Runtim
308308
Runtime.Node nodeJoint0 = nodes[1];
309309
Runtime.Node nodeJoint1 = nodeJoint0.Children.First();
310310
var channelList = new List<Runtime.AnimationChannel>();
311-
float rotationValue = FloatMath.ConvertDegreesToRadians(-15.0f);
311+
float rotationValue = FloatMath.ToRadians(-15.0f);
312312
AddRotationAnimationChannel(channelList, nodeJoint1, Quaternion.CreateFromYawPitchRoll(0.0f, 0.0f, rotationValue), Quaternion.CreateFromYawPitchRoll(0.0f, 0.0f, 0.0f));
313313
animations.Add(new Runtime.Animation
314314
{
@@ -326,7 +326,7 @@ Runtime.Animation CreateFoldingAnimation(Runtime.Node jointRootNode, List<Runtim
326326

327327
// Rotate each joint node, except the root which already has the desired rotation
328328
Runtime.Node nodeCheck = nodes[1].Children.First();
329-
float rotationRadian = FloatMath.ConvertDegreesToRadians(-10.0f);
329+
float rotationRadian = FloatMath.ToRadians(-10.0f);
330330
Quaternion rotation = Quaternion.CreateFromYawPitchRoll(0.0f, rotationRadian, 0.0f);
331331
nodeCheck.Rotation = rotation;
332332
while (nodeCheck.Children != null)

Source/ModelGroups/Animation_SkinType.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void AnimateWithRotation(List<Runtime.Animation> animations, List<Runtime.Node>
6161
}
6262
}
6363
);
64-
float quarterTurn = (FloatMath.Pi / 2.0f);
64+
6565
animations[0].Channels.First().Sampler = new Runtime.LinearAnimationSampler<Quaternion>
6666
(
6767
new[]
@@ -73,7 +73,7 @@ void AnimateWithRotation(List<Runtime.Animation> animations, List<Runtime.Node>
7373
new[]
7474
{
7575
Quaternion.Identity,
76-
Quaternion.CreateFromYawPitchRoll(0.0f, quarterTurn, 0.0f),
76+
Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(90), 0.0f),
7777
Quaternion.Identity,
7878
}
7979
);

Source/ModelGroups/Instancing.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,20 @@ Model CreateModel(Action<List<Property>, List<Runtime.Node>, List<Runtime.Animat
7070

7171
var SamplerOutput = new[]
7272
{
73-
Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ConvertDegreesToRadians(90), 0.0f),
73+
Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(90), 0.0f),
7474
Quaternion.Identity,
75-
Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ConvertDegreesToRadians(-90), 0.0f),
75+
Quaternion.CreateFromYawPitchRoll(0.0f, -FloatMath.ToRadians(90), 0.0f),
7676
Quaternion.Identity,
77-
Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ConvertDegreesToRadians(90), 0.0f),
77+
Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(90), 0.0f),
7878
};
7979

8080
var SamplerOutputReverse = new[]
8181
{
82-
Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ConvertDegreesToRadians(-90), 0.0f),
82+
Quaternion.CreateFromYawPitchRoll(0.0f, -FloatMath.ToRadians(90), 0.0f),
8383
Quaternion.Identity,
84-
Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ConvertDegreesToRadians(90), 0.0f),
84+
Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(90), 0.0f),
8585
Quaternion.Identity,
86-
Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ConvertDegreesToRadians(-90), 0.0f),
86+
Quaternion.CreateFromYawPitchRoll(0.0f, -FloatMath.ToRadians(90), 0.0f),
8787
};
8888

8989
Runtime.Texture CreateTexture(Runtime.Image image)
@@ -388,7 +388,7 @@ void AddAnimation(List<Runtime.Animation> animations, List<Runtime.Node> nodes,
388388
nodes[2].Skin.InverseBindMatrices = new[]
389389
{
390390
nodes[2].Skin.InverseBindMatrices.First(),
391-
Matrix4x4.Multiply(nodes[2].Skin.InverseBindMatrices.ElementAt(1), Matrix4x4.CreateRotationX(FloatMath.ConvertDegreesToRadians(-30))),
391+
Matrix4x4.Multiply(nodes[2].Skin.InverseBindMatrices.ElementAt(1), Matrix4x4.CreateRotationX(FloatMath.ToRadians(-30))),
392392
};
393393

394394
// Offsets the position of both meshes so they don't overlap.

0 commit comments

Comments
 (0)