Пример #1
0
        Vertex EvaluateTrefoil(float s, float t)
        {
            float TwoPi = (float)Math.PI * 2;
            float a = 0.5f;
            float b = 0.3f;
            float c = 0.5f;
            float d = 0.1f;
            float u = (1 - s) * 2 * TwoPi;
            float v = t * TwoPi;
            float r = (float)(a + b * Math.Cos(1.5f * u));
            float x = (float)(r * Math.Cos(u));
            float y = (float)(r * Math.Sin(u));
            float z = (float)(c * Math.Sin(1.5f * u));

            Vertex dv;
            dv.X = (float)(-1.5f * b * Math.Sin(1.5f * u) * Math.Cos(u) -
                    (a + b * Math.Cos(1.5f * u)) * Math.Sin(u));
            dv.Y = (float)(-1.5f * b * Math.Sin(1.5f * u) * Math.Sin(u) +
                    (a + b * Math.Cos(1.5f * u)) * Math.Cos(u));
            dv.Z = (float)(1.5f * c * Math.Cos(1.5f * u));

            Vertex q = new Vertex(dv);
            q.Normalize();
            Vertex qvn = new Vertex(q.Y, -q.X, 0);
            qvn.Normalize();
            Vertex ww = q.VectorProduct(qvn);

            Vertex range;
            range.X = (float)(x + d * (qvn.X * Math.Cos(v) + ww.X * Math.Sin(v)));
            range.Y = (float)(y + d * (qvn.Y * Math.Cos(v) + ww.Y * Math.Sin(v)));
            range.Z = (float)(z + d * ww.Z * Math.Sin(v));
            return range;
        }
Пример #2
0
        /// <summary>
        /// Returns the angle to another vector.
        /// </summary>
        /// <remarks>
        /// The order of the directions plays a role.
        /// </remarks>
        /// <returns>Value between -PI and + PI.</returns>
        public double getAngle(Vertex dir, Vertex viewDir)
        {
            Vertex thisNomalized = new Vertex(this);

            thisNomalized.Normalize();

            Vertex viewDirNormalized = new Vertex(viewDir);

            viewDirNormalized.Normalize();

            double dotProduct = thisNomalized.ScalarProduct(viewDirNormalized);

            double arc = Math.Acos(dotProduct);

            // We construct three points from the two directions.
            // Which are then checked, to see how they are.
            Vertex vec1 = new Vertex(this);
            Vertex vec2 = new Vertex();
            Vertex vec3 = new Vertex(dir);

            try
            {
                if (vec1.areClockwise(vec2, vec3, viewDir))
                {
                    arc *= -1;
                }
                return(arc);
            }
            // The points lie on a straight line.
            catch (InvalidOperationException)
            {
                return(arc);
            }
        }
Пример #3
0
        public static Vertex GetPackedTo01(this Vertex me)
        {
        	Vertex temp = new Vertex(me);
            temp.Normalize();
            
            temp= (temp * 0.5f) + new Vertex(0.5f, 0.5f, 0.5f);
	
	        return temp;
        }
Пример #4
0
        public void MouseMove(int x, int y)
        {
            if (this.mouseDownFlag)
            {
                IViewCamera camera = this.Camera;
                if (camera == null)
                {
                    return;
                }

                Vertex back         = this.back;
                Vertex right        = this.right;
                Vertex up           = this.up;
                Size   bound        = this.bound;
                Point  downPosition = this.downPosition;
                {
                    float  deltaX  = -horizontalRotationFactor * (x - downPosition.X) / bound.Width;
                    float  cos     = (float)Math.Cos(deltaX);
                    float  sin     = (float)Math.Sin(deltaX);
                    Vertex newBack = new Vertex(
                        back.X * cos + right.X * sin,
                        back.Y * cos + right.Y * sin,
                        back.Z * cos + right.Z * sin);
                    back  = newBack;
                    right = up.VectorProduct(back);
                    back.Normalize();
                    right.Normalize();
                }
                {
                    float  deltaY  = verticalRotationFactor * (y - downPosition.Y) / bound.Height;
                    float  cos     = (float)Math.Cos(deltaY);
                    float  sin     = (float)Math.Sin(deltaY);
                    Vertex newBack = new Vertex(
                        back.X * cos + up.X * sin,
                        back.Y * cos + up.Y * sin,
                        back.Z * cos + up.Z * sin);
                    back = newBack;
                    up   = back.VectorProduct(right);
                    back.Normalize();
                    up.Normalize();
                }

                camera.Position = camera.Target +
                                  back * (float)((camera.Position - camera.Target).Magnitude());
                camera.UpVector     = up;
                this.back           = back;
                this.right          = right;
                this.up             = up;
                this.downPosition.X = x;
                this.downPosition.Y = y;
            }
        }
Пример #5
0
        /// <summary>
        /// Tests the order of the points.
        ///
        /// Seen in the direction, indicated by the third parameter.
        /// </summary>
        /// <param name = "p1"> First point. </param>
        /// <param name = "p2"> Second point. </param>
        /// <param name = "viewDir"> View direction from which the sense of rotation should be calculated. </param>
        /// <exception cref="InvalidOperationException">if the points lie on a line</exception>
        public bool areClockwise(Vertex p1, Vertex p2, Vertex viewDir)
        {
            Vertex u = p2 - this;

            u.Normalize();

            Vertex v = p1 - this;

            v.Normalize();

            Vertex w = u.VectorProduct(v);

            double test = w.ScalarProduct(viewDir);

            if (Math.Abs(test) < 0.000001)
            {
                throw new InvalidOperationException("All points are on one line!");
            }

            return(test < 0);
        }