private void GetBoundsOrthoSmart(Aabb aabbWorld, Matrix44F viewProj, out Aabb aabbClip) { Vector3F minimum = aabbWorld.Minimum; Vector3F maximum = aabbWorld.Maximum; Vector3F extent = maximum - minimum; Vector3F v0 = (viewProj * new Vector4F(minimum.X, minimum.Y, minimum.Z, 1)).XYZ; Vector3F minimumClip = v0; Vector3F maximumClip = v0; Vector3F d0 = extent.X * viewProj.GetColumn(0).XYZ; Vector3F d1 = extent.Y * viewProj.GetColumn(1).XYZ; Vector3F d2 = extent.Z * viewProj.GetColumn(2).XYZ; Vector3F v1 = v0 + d0; minimumClip = Vector3F.Min(minimumClip, v1); maximumClip = Vector3F.Max(maximumClip, v1); Vector3F v2 = v0 + d1; minimumClip = Vector3F.Min(minimumClip, v2); maximumClip = Vector3F.Max(maximumClip, v2); Vector3F v3 = v0 + d2; minimumClip = Vector3F.Min(minimumClip, v3); maximumClip = Vector3F.Max(maximumClip, v3); Vector3F v4 = v1 + d1; minimumClip = Vector3F.Min(minimumClip, v4); maximumClip = Vector3F.Max(maximumClip, v4); Vector3F v5 = v1 + d2; minimumClip = Vector3F.Min(minimumClip, v5); maximumClip = Vector3F.Max(maximumClip, v5); Vector3F v6 = v2 + d2; minimumClip = Vector3F.Min(minimumClip, v6); maximumClip = Vector3F.Max(maximumClip, v6); Vector3F v7 = v4 + d2; minimumClip = Vector3F.Min(minimumClip, v7); maximumClip = Vector3F.Max(maximumClip, v7); aabbClip.Minimum = minimumClip; aabbClip.Maximum = maximumClip; }
public void GetColumnException1() { Matrix44F m = new Matrix44F(rowMajor, MatrixOrder.RowMajor); m.GetColumn(-1); }
private void GetBoundsPerspSmart(Aabb aabbWorld, Matrix44F viewProj, out Aabb aabbClip) { Vector3F minimum = aabbWorld.Minimum; Vector3F maximum = aabbWorld.Maximum; Vector3F extent = maximum - minimum; Vector4F v0 = viewProj * new Vector4F(minimum.X, minimum.Y, minimum.Z, 1); Vector4F d0 = extent.X * viewProj.GetColumn(0); Vector4F d1 = extent.Y * viewProj.GetColumn(1); Vector4F d2 = extent.Z * viewProj.GetColumn(2); Vector4F v1 = v0 + d0; Vector4F v2 = v0 + d1; Vector4F v3 = v0 + d2; Vector4F v4 = v1 + d1; Vector4F v5 = v1 + d2; Vector4F v6 = v2 + d2; Vector4F v7 = v4 + d2; Vector3F v; if (v0.Z < 0) { v = new Vector3F(); } else { v = v0.XYZ / v0.W; } Vector3F minimumClip = v; Vector3F maximumClip = v; if (v1.Z < 0) { v = new Vector3F(); } else { v = v1.XYZ / v1.W; } minimumClip = Vector3F.Min(minimumClip, v); maximumClip = Vector3F.Max(maximumClip, v); if (v2.Z < 0) { v = new Vector3F(); } else { v = v2.XYZ / v2.W; } minimumClip = Vector3F.Min(minimumClip, v); maximumClip = Vector3F.Max(maximumClip, v); if (v3.Z < 0) { v = new Vector3F(); } else { v = v3.XYZ / v3.W; } minimumClip = Vector3F.Min(minimumClip, v); maximumClip = Vector3F.Max(maximumClip, v); if (v4.Z < 0) { v = new Vector3F(); } else { v = v4.XYZ / v4.W; } minimumClip = Vector3F.Min(minimumClip, v); maximumClip = Vector3F.Max(maximumClip, v); if (v5.Z < 0) { v = new Vector3F(); } else { v = v5.XYZ / v5.W; } minimumClip = Vector3F.Min(minimumClip, v); maximumClip = Vector3F.Max(maximumClip, v); if (v6.Z < 0) { v = new Vector3F(); } else { v = v6.XYZ / v6.W; } minimumClip = Vector3F.Min(minimumClip, v); maximumClip = Vector3F.Max(maximumClip, v); if (v7.Z < 0) { v = new Vector3F(); } else { v = v7.XYZ / v7.W; } minimumClip = Vector3F.Min(minimumClip, v); maximumClip = Vector3F.Max(maximumClip, v); aabbClip.Minimum = minimumClip; aabbClip.Maximum = maximumClip; }
public void GetColumn() { Matrix44F m = new Matrix44F(rowMajor, MatrixOrder.RowMajor); Assert.AreEqual(new Vector4F(1.0f, 5.0f, 9.0f, 13.0f), m.GetColumn(0)); Assert.AreEqual(new Vector4F(2.0f, 6.0f, 10.0f, 14.0f), m.GetColumn(1)); Assert.AreEqual(new Vector4F(3.0f, 7.0f, 11.0f, 15.0f), m.GetColumn(2)); Assert.AreEqual(new Vector4F(4.0f, 8.0f, 12.0f, 16.0f), m.GetColumn(3)); }
public void SetColumn() { Matrix44F m = new Matrix44F(rowMajor, MatrixOrder.RowMajor); m.SetColumn(0, new Vector4F(0.1f, 0.2f, 0.3f, 0.4f)); Assert.AreEqual(new Vector4F(0.1f, 0.2f, 0.3f, 0.4f), m.GetColumn(0)); Assert.AreEqual(new Vector4F(2.0f, 6.0f, 10.0f, 14.0f), m.GetColumn(1)); Assert.AreEqual(new Vector4F(3.0f, 7.0f, 11.0f, 15.0f), m.GetColumn(2)); Assert.AreEqual(new Vector4F(4.0f, 8.0f, 12.0f, 16.0f), m.GetColumn(3)); m.SetColumn(1, new Vector4F(0.4f, 0.5f, 0.6f, 0.7f)); Assert.AreEqual(new Vector4F(0.1f, 0.2f, 0.3f, 0.4f), m.GetColumn(0)); Assert.AreEqual(new Vector4F(0.4f, 0.5f, 0.6f, 0.7f), m.GetColumn(1)); Assert.AreEqual(new Vector4F(3.0f, 7.0f, 11.0f, 15.0f), m.GetColumn(2)); Assert.AreEqual(new Vector4F(4.0f, 8.0f, 12.0f, 16.0f), m.GetColumn(3)); m.SetColumn(2, new Vector4F(0.7f, 0.8f, 0.9f, 1.0f)); Assert.AreEqual(new Vector4F(0.1f, 0.2f, 0.3f, 0.4f), m.GetColumn(0)); Assert.AreEqual(new Vector4F(0.4f, 0.5f, 0.6f, 0.7f), m.GetColumn(1)); Assert.AreEqual(new Vector4F(0.7f, 0.8f, 0.9f, 1.0f), m.GetColumn(2)); Assert.AreEqual(new Vector4F(4.0f, 8.0f, 12.0f, 16.0f), m.GetColumn(3)); m.SetColumn(3, new Vector4F(1.1f, 1.8f, 1.9f, 1.2f)); Assert.AreEqual(new Vector4F(0.1f, 0.2f, 0.3f, 0.4f), m.GetColumn(0)); Assert.AreEqual(new Vector4F(0.4f, 0.5f, 0.6f, 0.7f), m.GetColumn(1)); Assert.AreEqual(new Vector4F(0.7f, 0.8f, 0.9f, 1.0f), m.GetColumn(2)); Assert.AreEqual(new Vector4F(1.1f, 1.8f, 1.9f, 1.2f), m.GetColumn(3)); }
public void MultiplyMatrixOperator() { Matrix44F m = new Matrix44F(12, 23, 45, 56, 67, 89, 90, 12, 43, 65, 87, 43, 34, -12, 84, 44); Assert.AreEqual(Matrix44F.Zero, m * Matrix44F.Zero); Assert.AreEqual(Matrix44F.Zero, Matrix44F.Zero * m); Assert.AreEqual(m, m * Matrix44F.Identity); Assert.AreEqual(m, Matrix44F.Identity * m); Assert.IsTrue(Matrix44F.AreNumericallyEqual(Matrix44F.Identity, m * m.Inverse)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(Matrix44F.Identity, m.Inverse * m)); Matrix44F m1 = new Matrix44F(rowMajor, MatrixOrder.RowMajor); Matrix44F m2 = new Matrix44F(12, 23, 45, 56, 67, 89, 90, 12, 43, 65, 87, 43, 34, -12, 84, 44); Matrix44F result = m1 * m2; for (int column = 0; column < 4; column++) for (int row = 0; row < 4; row++) Assert.AreEqual(Vector4F.Dot(m1.GetRow(row), m2.GetColumn(column)), result[row, column]); }
private void GetBoundsPerspSmart(Aabb aabbWorld, Matrix44F viewProj, out Aabb aabbClip) { Vector3F minimum = aabbWorld.Minimum; Vector3F maximum = aabbWorld.Maximum; Vector3F extent = maximum - minimum; Vector4F v0 = viewProj * new Vector4F(minimum.X, minimum.Y, minimum.Z, 1); Vector4F d0 = extent.X * viewProj.GetColumn(0); Vector4F d1 = extent.Y * viewProj.GetColumn(1); Vector4F d2 = extent.Z * viewProj.GetColumn(2); Vector4F v1 = v0 + d0; Vector4F v2 = v0 + d1; Vector4F v3 = v0 + d2; Vector4F v4 = v1 + d1; Vector4F v5 = v1 + d2; Vector4F v6 = v2 + d2; Vector4F v7 = v4 + d2; Vector3F v; if (v0.Z < 0) v = new Vector3F(); else v = v0.XYZ / v0.W; Vector3F minimumClip = v; Vector3F maximumClip = v; if (v1.Z < 0) v = new Vector3F(); else v = v1.XYZ / v1.W; minimumClip = Vector3F.Min(minimumClip, v); maximumClip = Vector3F.Max(maximumClip, v); if (v2.Z < 0) v = new Vector3F(); else v = v2.XYZ / v2.W; minimumClip = Vector3F.Min(minimumClip, v); maximumClip = Vector3F.Max(maximumClip, v); if (v3.Z < 0) v = new Vector3F(); else v = v3.XYZ / v3.W; minimumClip = Vector3F.Min(minimumClip, v); maximumClip = Vector3F.Max(maximumClip, v); if (v4.Z < 0) v = new Vector3F(); else v = v4.XYZ / v4.W; minimumClip = Vector3F.Min(minimumClip, v); maximumClip = Vector3F.Max(maximumClip, v); if (v5.Z < 0) v = new Vector3F(); else v = v5.XYZ / v5.W; minimumClip = Vector3F.Min(minimumClip, v); maximumClip = Vector3F.Max(maximumClip, v); if (v6.Z < 0) v = new Vector3F(); else v = v6.XYZ / v6.W; minimumClip = Vector3F.Min(minimumClip, v); maximumClip = Vector3F.Max(maximumClip, v); if (v7.Z < 0) v = new Vector3F(); else v = v7.XYZ / v7.W; minimumClip = Vector3F.Min(minimumClip, v); maximumClip = Vector3F.Max(maximumClip, v); aabbClip.Minimum = minimumClip; aabbClip.Maximum = maximumClip; }