예제 #1
0
        public void CanSubtractTwoVectors()
        {
            var v1 = Tuple.NewVector(3, 2, 1);
            var v2 = Tuple.NewVector(5, 6, 7);

            Assert.Equal(Tuple.NewVector(-2, -4, -6), v1 - v2);
        }
예제 #2
0
        public void CanSubtractTwoPoints()
        {
            var p1 = Tuple.NewPoint(3, 2, 1);
            var p2 = Tuple.NewPoint(5, 6, 7);

            Assert.Equal(Tuple.NewVector(-2, -4, -6), p1 - p2);
        }
예제 #3
0
        public void CanSubtractAVectorFromAPoint()
        {
            var p = Tuple.NewPoint(3, 2, 1);
            var v = Tuple.NewVector(5, 6, 7);

            Assert.Equal(Tuple.NewPoint(-2, -4, -6), p - v);
        }
예제 #4
0
        public void CanSubtractAVectorFromTheZeroVector()
        {
            var zero = Tuple.NewVector(0, 0, 0);
            var v    = Tuple.NewVector(1, -2, 3);

            Assert.Equal(Tuple.NewVector(-1, 2, -3), zero - v);
        }
예제 #5
0
        public void CanCalculateTheDotProductOfTwoVectors()
        {
            var a = Tuple.NewVector(1, 2, 3);
            var b = Tuple.NewVector(2, 3, 4);

            Assert.True(FloatMath.AreEqual(20, a.Dot(b)));
        }
예제 #6
0
        public void CanCalculateTheCrossProductOfTwoVectors()
        {
            var a = Tuple.NewVector(1, 2, 3);
            var b = Tuple.NewVector(2, 3, 4);

            Assert.Equal(Tuple.NewVector(-1, 2, -1), a.Cross(b));
            Assert.Equal(Tuple.NewVector(1, -2, 1), b.Cross(a));
        }
예제 #7
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Projectile Demo");

            var p        = new Projectile(Tuple.NewPoint(0, 1, 0), Tuple.NewVector(1, 1, 0).Normalized);
            var w        = new World(Tuple.NewVector(0, -0.1, 0), Tuple.NewVector(-0.01, 0, 0));
            var numTicks = 0;

            Console.WriteLine($"Y: {p.Position.Y}, Ticks: {numTicks}");
            while (p.Position.Y > 0)
            {
                p = Tick(w, p);
                numTicks++;
                Console.WriteLine($"Y: {p.Position.Y}, Ticks: {numTicks}");
            }

            Console.WriteLine($"It took {numTicks} ticks to hit the ground.");

            Console.Read();
        }
예제 #8
0
        public void TupleFactoryCanCreateAVector()
        {
            var p = Tuple.NewVector(4, -4, 3);

            Assert.Equal(new Tuple4(4, -4, 3, 0), p);
        }
예제 #9
0
        public void MagnitudeOfANormalizedVectorEqualsOne()
        {
            var v = Tuple.NewVector(1, 2, 3);

            Assert.True(FloatMath.AreEqual(1, v.Normalized.Magnitude));
        }
예제 #10
0
        public void CanNormalizeAVector(double v1, double v2, double v3, double r1, double r2, double r3)
        {
            var v = Tuple.NewVector(v1, v2, v3);

            Assert.Equal(Tuple.NewVector(r1, r2, r3), v.Normalized);
        }
예제 #11
0
        public void VectorsHaveAFloatingPointMagnitude(double a, double b, double c)
        {
            var v = Tuple.NewVector(a, b, c);

            Assert.True(FloatMath.AreEqual(v.Magnitude, Math.Sqrt(14)));
        }
예제 #12
0
        public void VectorsHaveAMagnitude(double a, double b, double c, double expected)
        {
            var v = Tuple.NewVector(a, b, c);

            Assert.True(FloatMath.AreEqual(v.Magnitude, expected));
        }
예제 #13
0
 public Tuple4 Cross(Tuple4 other)
 {
     return(Tuple.NewVector(Y * other.Z - Z * other.Y,
                            Z * other.X - X * other.Z,
                            X * other.Y - Y * other.X));
 }