Exemple #1
0
        // cheap ;)
        public void SetScreenDimensions(int width, int height)
        {
            double factor = width / (2.0 * height);

            ViewPaneWidthVector /= 2;
            ViewPaneEdge        += ViewPaneWidthVector;
            ViewPaneWidthVector  = ViewPaneWidthVector.Normalize();
            ViewPaneWidthVector *= factor;
            ViewPaneEdge        -= ViewPaneWidthVector;
            ViewPaneWidthVector *= 2;
        }
Exemple #2
0
        /**
         * Refraction
         *
         * @param incoming incoming vector
         * @param normal normal of the reflectio area
         * @param outgoing result of the computation
         */

        public static Vect3 RefractOn(this Vect3 incoming, Vect3 normal, double refractionIndex)
        {
            //test implementation - working but propably slow
            Vect3 result = incoming.ProjectOnNormal(normal);

            result = result / refractionIndex;
            double quadLen = result.QuadLength();

            if (quadLen >= 1) //total reflection
            {
                result = incoming.ReflectOn(normal);
            }
            else
            {
                result = result + (normal * -System.Math.Sqrt(1 - quadLen));
                result = result.Normalize();
            }
            return(result);
        }
Exemple #3
0
        public static Camera CreateCamera(Vect3 position, Vect3 viewPaneCenter, Vect3 camUp, double viewPaneWidth,
                                          double viewPaneHeight)
        {
            var viewPaneHeightVector = camUp;

            viewPaneHeightVector *= -viewPaneHeight;

            Vect3 temp1 = position - viewPaneCenter;
            Vect3 viewPaneWidthVector = temp1.CrossProduct(viewPaneHeightVector);

            viewPaneWidthVector  = viewPaneWidthVector.Normalize();
            viewPaneWidthVector *= viewPaneWidth;

            viewPaneWidthVector.CopyDataTo(ref temp1);
            temp1 = temp1 / 2;
            Vect3 viewPaneEdge = viewPaneCenter - temp1;

            viewPaneHeightVector.CopyDataTo(ref temp1);
            temp1         = temp1 / 2;
            viewPaneEdge -= temp1;

            return(new Camera(position, viewPaneEdge, viewPaneWidthVector, viewPaneHeightVector));
        }
Exemple #4
0
        public static double InterpolateTriangleEdge(Vect3 v1, Vect3 v2, Vect3 v3, Vect3 point)
        {
            Vect3 v23N = v3 - v2;

            v23N = v23N.Normalize();

            Vect3 v21 = v1 - v2;

// ReSharper disable InconsistentNaming
            Vect3 v1o = v21.ProjectOn(v23N); //punkt gegenüber der ecke v1 (o ... opposite)

// ReSharper restore InconsistentNaming

            v1o -= v21;

            double h1 = v1o.Length(); //höhe auf v1

            v1o = v1o / h1;           //normieren

            Vect3 v1P = point - v1;
            Vect3 p1  = v1P.ProjectOn(v1o); //projektion von v1p auf v1hn

            return(1 - (p1.Length() / h1));
        }
Exemple #5
0
        public override Vect3 GetNormalAt(Vect3 hitPoint)
        {
            Vect3 target = hitPoint - Position;

            return(target.Normalize());
        }
Exemple #6
0
        public static Vect3 GetCircumScribedCircleCenter(Vect3 a, Vect3 b, Vect3 c)
        {
            Vect3 mab    = b - a;
            Vect3 mac    = c - a;
            Vect3 normal = mab.CrossProduct(mac);
            Vect3 dab    = mab.CrossProduct(normal);
            Vect3 dac    = mac.CrossProduct(normal);

            mab = a + mab / 2;
            mac = a + mac / 2;
            dab = dab.Normalize();
            dac = dac.Normalize();


            if (System.Math.Abs(dac.X) > Constants.EPS &&
                System.Math.Abs(dac.Y) > Constants.EPS &&
                System.Math.Abs(dab.X / dac.X - dab.Y / dac.Y) > Constants.EPS)
            {
                double x = ((mab.Y - mac.Y) / dac.Y - (mab.X - mac.X) / dac.X) / (dab.X / dac.X - dab.Y / dac.Y);
                return(mab + dab * x);
            }

            if (System.Math.Abs(dac.X) > Constants.EPS &&
                System.Math.Abs(dac.Z) > Constants.EPS &&
                System.Math.Abs(dab.Z / dac.Z - dab.X / dac.X) > Constants.EPS)
            {
                double x = ((mab.X - mac.X) / dac.X - (mab.Z - mac.Z) / dac.Z) / (dab.Z / dac.Z - dab.X / dac.X);
                return(mab + dab * x);
            }

            if (System.Math.Abs(dac.Y) > Constants.EPS &&
                System.Math.Abs(dac.Z) > Constants.EPS &&
                System.Math.Abs(dab.Y / dac.Y - dab.Z / dac.Z) > Constants.EPS)
            {
                double x = ((mab.Z - mac.Z) / dac.Z - (mab.Y - mac.Y) / dac.Y) / (dab.Y / dac.Y - dab.Z / dac.Z);
                return(mab + dab * x);
            }

            if (System.Math.Abs(dab.Y) > Constants.EPS &&
                System.Math.Abs(dab.X) > Constants.EPS &&
                System.Math.Abs(dac.X / dab.X - dac.Y / dab.Y) > Constants.EPS)
            {
                double y = ((mac.Y - mab.Y) / dab.Y - (mac.X - mab.X) / dab.X) / (dac.X / dab.X - dac.Y / dab.Y);
                return(mac + dac * y);
            }

            if (System.Math.Abs(dab.Z) > Constants.EPS &&
                System.Math.Abs(dab.X) > Constants.EPS &&
                System.Math.Abs(dac.Z / dab.Z - dac.X / dab.X) > Constants.EPS)
            {
                double y = ((mac.X - mab.X) / dab.X - (mac.Z - mab.Z) / dab.Z) / (dac.Z / dab.Z - dac.X / dab.X);
                return(mac + dac * y);
            }

            if (System.Math.Abs(dab.Z) > Constants.EPS &&
                System.Math.Abs(dab.Y) > Constants.EPS &&
                System.Math.Abs(dac.Y / dab.Y - dac.Z / dab.Z) > Constants.EPS)
            {
                double y = ((mac.Z - mab.Z) / dab.Z - (mac.Y - mab.Y) / dab.Y) / (dac.Y / dab.Y - dac.Z / dab.Z);
                return(mac + dac * y);
            }

            throw new Exception("implement more cases...");
        }