public void DividTuple()
        {
            RayTracer.Tuple t1       = new RayTracer.Tuple(1, -2, 3, -4);
            float           scalar01 = 2.0f;

            RayTracer.Tuple DividTuple  = t1 / scalar01;
            RayTracer.Tuple answerTuple = new RayTracer.Tuple(0.5f, -1, 1.5f, -2f);

            Assert.Equal(answerTuple, DividTuple);
            Assert.True(answerTuple == DividTuple);
        }
        public void NegationTuple()
        {
            RayTracer.Tuple zero = new RayTracer.Tuple();
            RayTracer.Tuple v1   = new RayTracer.Tuple(1, -2, 3);

            RayTracer.Tuple negationTuple = new RayTracer.Tuple();
            RayTracer.Tuple anwserTuple   = new RayTracer.Tuple(-1, 2, -3);

            negationTuple = -v1;

            Assert.Equal(anwserTuple, negationTuple);
            Assert.True(anwserTuple == negationTuple);
        }
        public void TupleVector()
        {
            RayTracer.Tuple t1 = new RayTracer.Tuple(4.3f, -4.2f, 3.1f, 0.0f);

            Assert.Equal(4.3f, t1.x);
            Assert.Equal(-4.2f, t1.y);
            Assert.Equal(3.1f, t1.z);
            Assert.Equal(0.0f, t1.w);

            Assert.True(Utilities.FloatEquality(4.3f, t1.x));
            Assert.True(Utilities.FloatEquality(-4.2f, t1.y));
            Assert.True(Utilities.FloatEquality(3.1f, t1.z));
            Assert.True(Utilities.FloatEquality(0.0f, t1.w));
        }
        public void MultipicationMatrix4Tuple()
        {
            Matrix4 m1 = new Matrix4(1, 2, 3, 4,
                                     2, 4, 4, 2,
                                     8, 6, 4, 1,
                                     0, 0, 0, 1);

            RayTracer.Tuple t2 = new RayTracer.Tuple(1, 2, 3, 1);

            RayTracer.Tuple result = m1 * t2;

            RayTracer.Tuple answer = new RayTracer.Tuple(18, 24, 33, 1);

            Assert.True(answer == result);
        }
        public void AddTuples()
        {
            RayTracer.Tuple t1 = new RayTracer.Tuple(3.0f, -2.0f, 5.0f, 1.0f);
            RayTracer.Tuple t2 = new RayTracer.Tuple(-2.0f, 3.0f, 1.0f, 0.0f);

            RayTracer.Tuple additionTuple      = new RayTracer.Tuple();
            RayTracer.Tuple correctAnswerTuple = new RayTracer.Tuple(1, 1, 6, 1);

            additionTuple = t1 + t2;

            Assert.Equal(additionTuple, correctAnswerTuple);
            Assert.True(additionTuple == correctAnswerTuple);

            Assert.True(Utilities.FloatEquality(correctAnswerTuple.x, additionTuple.x));
            Assert.True(Utilities.FloatEquality(correctAnswerTuple.y, additionTuple.y));
            Assert.True(Utilities.FloatEquality(correctAnswerTuple.z, additionTuple.z));
            Assert.True(Utilities.FloatEquality(correctAnswerTuple.w, additionTuple.w));
        }
        public void TupleInEqualiyOperator()
        {
            Point p1 = new Point(-1, 5, 4);

            Vector3 v1 = new Vector3(4, -7, -3);
            Vector3 v2 = new Vector3(4, -7, -3);
            Vector3 v3 = new Vector3(3, -9, 5);

            RayTracer.Tuple t1 = new RayTracer.Tuple(-1, 5, 4, 1);
            RayTracer.Tuple t2 = new RayTracer.Tuple(3, -9, 5, 0);

            Assert.NotEqual(t2, p1);
            Assert.True(t2 != p1);
            Assert.NotEqual(t1, v3);
            Assert.True(t1 != v3);
            Assert.NotEqual(v1, v3);
            Assert.True(v1 != v3);
        }
        public void SubtractTuples()
        {
            RayTracer.Tuple t1 = new RayTracer.Tuple(0.005f, 2.0f, 1.0f, 1.0f);
            RayTracer.Tuple t2 = new RayTracer.Tuple(5000.0f, 6.0f, 7.0f, 1.0f);

            RayTracer.Tuple substractionTuple  = new RayTracer.Tuple();
            RayTracer.Tuple correctAnswerTuple = new RayTracer.Tuple(-4999.995f, -4f, -6f, 0f);

            substractionTuple = t1 - t2;

            Assert.Equal(correctAnswerTuple, substractionTuple);
            Assert.True(correctAnswerTuple == substractionTuple);

            Assert.True(Utilities.FloatEquality(correctAnswerTuple.x, substractionTuple.x));
            Assert.True(Utilities.FloatEquality(correctAnswerTuple.y, substractionTuple.y));
            Assert.True(Utilities.FloatEquality(correctAnswerTuple.z, substractionTuple.z));
            Assert.True(Utilities.FloatEquality(correctAnswerTuple.w, substractionTuple.w));
        }
        public void ScalarMultiplyTuple()
        {
            RayTracer.Tuple t1       = new RayTracer.Tuple(1, -2, 3, -4);
            float           scalar01 = 3.5f;

            RayTracer.Tuple scalarMultipleTuple01 = t1 * scalar01;
            RayTracer.Tuple answerTuple01         = new RayTracer.Tuple(3.5f, -7, 10.5f, -14);

            Assert.Equal(answerTuple01, scalarMultipleTuple01);
            Assert.True(answerTuple01 == scalarMultipleTuple01);

            float scalar02 = 0.5f;

            RayTracer.Tuple scalarMultipleTuple02 = t1 * scalar02;
            RayTracer.Tuple answerTuple02         = new RayTracer.Tuple(0.5f, -1, 1.5f, -2);

            Assert.Equal(answerTuple02, scalarMultipleTuple02);
            Assert.True(answerTuple02 == scalarMultipleTuple02);
        }
Esempio n. 9
0
        /// <summary>
        /// Returns the dot product of two vector as a float.
        /// </summary>
        /// <param name="t1"></param>
        /// <param name="t2"></param>
        /// <returns></returns>
        public static float Dot(Tuple t1, Tuple t2)
        {
            float product = (t1.x * t2.x) + (t1.y * t2.y) + (t1.z * t2.z) + (t1.w * t2.w);

            return(product);
        }
Esempio n. 10
0
        // Methods
        /// <summary>
        /// Returns the dot product of two vector as a float.
        /// </summary>
        /// <param name="t2"></param>
        /// <returns></returns>
        public float Dot(Tuple t2)
        {
            float product = (this.x * t2.x) + (this.y * t2.y) + (this.z * t2.z) + (this.w * t2.w);

            return(product);
        }