Exemple #1
0
 /// <summary>
 /// Converts an array of xy to an array of float points
 /// </summary>
 /// <param name="Array">Array of xy, which will be converted</param>
 /// <returns>Array of <see cref="xyf"/></returns>
 public static xyf[] ToxyfArray(xy[] Array)
 {
     xyf[] Result = new xyf[Array.Length];
     for (int i = 0; i < Array.Length; i++)
     {
         Result[i] = new xyf((float)Array[i].x, (float)Array[i].y);
     }
     return(Result);
 }
Exemple #2
0
 /// <summary>
 /// Converts a List of xy to an array of float points
 /// </summary>
 /// <param name="Array">List of xy, which will be converted</param>
 /// <returns>Array of <see cref="xyf"/></returns>
 public static xyf[] ToxyfArray(List <xy> Array)
 {
     xyf[] Result = new xyf[Array.Count];
     for (int i = 0; i < Array.Count; i++)
     {
         Result[i] = new xyf((float)Array[i].x, (float)Array[i].y);
     }
     return(Result);
 }
Exemple #3
0
        /// <summary>
        /// Multiply the 2D-point <see cref="xyf"/> with the matrix but omit the third component.
        /// This multiplication gives the zero point by a multiplication of a zero point.
        /// You can use it to transform vectors.
        /// </summary>
        /// <param name="a">a <see cref="xyf"/>point, which will be multiplied</param>
        /// <returns>
        /// Transformed point
        /// </returns>
        public xyf multaffin(xyf a)
        {
            xyf p = new xyf(0, 0);


            {
                p.x = a00 * a.x + a01 * a.y;
                p.y = a10 * a.x + a11 * a.y;
            }
            return(p);
        }
Exemple #4
0
        ///// <summary>
        ///// Converts the Loxy to a <see cref="Loxyz"/> by setting the z-coordinates to 0.
        ///// </summary>
        ///// <returns></returns>
        //public Loxyz toLoxyz()
        //{
        //    return toLoxyz(0);
        //}
        short getPointId(xyf Point)
        {
            //_TmpPoints.Add(Point);
            //return (uint)(_TmpPoints.Count - 1);

            if (TmpPointArray.ContainsKey(Point))
            {
                object Ob = TmpPointArray[Point];

                return((short)Ob);
            }
            else
            {
                TmpPointArray.Add(Point, (uint)_TmpPoints.Count);
                _TmpPoints.Add(Point);
                return((short)(_TmpPoints.Count - 1));
            }
        }
Exemple #5
0
        /// <summary>
        /// overrides the <see cref="Surface.OnDraw(OpenGlDevice)"/> method.
        /// </summary>
        /// <param name="Device">the <see cref="OpenGlDevice"/> in which will be painted.</param>

        protected override void OnDraw(OpenGlDevice Device)
        {
            if (!plane)
            {
                base.OnDraw(Device); return;
            }
            object Handle = null;

            if ((Device.RenderKind == RenderKind.SnapBuffer) || (Entity.Compiling))
            {
                SurfaceSnappItem S = new SurfaceSnappItem();
                Handle    = Device.Selector.RegisterSnapItem(S);
                S.Surface = this;
            }
            IndexType[] Indices = null;
            xyzf[]      Points  = null;
            xyzf[]      Normals = null;
            xyf[]       Texture = null;
            //         if ((BoundedCurves != null) && (BoundedCurves.Count > 0))
            {
                Indices = new IndexType[] { 0, 1, 2, 0, 2, 3 };
                Points  = new xyzf[] { A, B, C, D };
                Normals = new xyzf[] { N00.toXYZF(), N00.toXYZF(), N00.toXYZF(), N00.toXYZF() };
                Texture = new xyf[] { new xyf(0, 0), new xyf(0, 0), new xyf(0, 0), new xyf(0, 0) };
            }
            //else
            //    GetTrianglesFull(ref Indices, ref Points, ref Normals, ref Texture);
            if (Device.PolygonMode == PolygonMode.Fill)
            {
                Primitives3d.drawTriangles(Device, Indices, Points, Normals, Texture, null);
            }
            else
            {
                Primitives3d.drawFouranglesLined(Device, Indices, Points, Normals, Texture);
            }

            Entity.CheckCompiling();
            if ((Device.RenderKind == RenderKind.SnapBuffer) || (Entity.Compiling))
            {
                Device.Selector.UnRegisterSnapItem(Handle);
            }
        }
Exemple #6
0
        /// <summary>
        /// This operator returns the multiplication of a two-dimensional floatvector with the matrix3x3.
        /// </summary>
        /// <param name="a">3X3 Matrix</param>
        /// <param name="b">2D-floatvector</param>
        /// <returns>2D-floatvector</returns>


        public static xyf operator *(Matrix3x3 a, xyf b)
        {
            float x = b.x;
            float y = b.y;

            xyf   p = new xyf(0, 0);
            float r;

            {
                p.x = a.a00 * x + a.a01 * y + a.a02;
                p.y = a.a10 * x + a.a11 * y + a.a12;
                r   = a.a20 * x + a.a21 * y + a.a22;

                if (!Utils.Equals(r, 0))
                {
                    p.x = p.x / r;
                    p.y = p.y / r;
                }
            }
            return(p);
        }
Exemple #7
0
        static string TextureToString(xyf Pt)
        {
            string s = "new xyf(";

            if (Pt.x == 1)
            {
                s += "Size.x,";
            }
            else
            {
                s += "0,";
            }
            if (Pt.y == 1)
            {
                s += "+Size.y";
            }
            else
            {
                s += "0";
            }
            s += ")";
            return(s);
        }
Exemple #8
0
 /// <summary>
 /// adds the float point a
 /// </summary>
 /// <param name="a"></param>
 /// <returns>returns this + a</returns>
 public xyf add(xyf a)
 {
     return(new xyf(a.x + x, a.y + y));
 }
Exemple #9
0
        private void drawFilledArray2d(OpenGlDevice Device, Loxy L)
        {
            if (L.Count == 0)
            {
                return;
            }
            double xMax = -10000000;
            double yMax = -10000000;
            double xMin = 10000000;
            double yMin = 10000000;

            if ((Device.texture != null) && (Device.texture.SoBigAsPossible != Drawing3d.Texture.BigAsPosible.None))

            {
                for (int i = 0; i < L[0].Count; i++)
                {
                    if (L[0][i].X > xMax)
                    {
                        xMax = L[0][i].X;
                    }
                    if (L[0][i].X < xMin)
                    {
                        xMin = L[0][i].X;
                    }
                    if (L[0][i].Y > yMax)
                    {
                        yMax = L[0][i].Y;
                    }
                    if (L[0][i].Y < yMin)
                    {
                        yMin = L[0][i].Y;
                    }
                }
            }
            double xDiff = xMax - xMin;
            double yDiff = yMax - yMin;


            List <IndexType> Indices = new List <IndexType>();

            xyf[] Points = null;
            L.TriAngulation(Indices, ref Points);
            xyf[] Texture = new xyf[Points.Length];
            float Aspectx = 1;
            float Aspecty = 1;

            if ((Device.texture != null) && (Device.texture.SoBigAsPossible != Drawing3d.Texture.BigAsPosible.None))

            {
                if (Device.texture.Bitmap != null)
                {
                    double w = (float)Device.texture.Bitmap.Width / Device.PixelsPerUnit;
                    double h = (float)Device.texture.Bitmap.Height / Device.PixelsPerUnit;
                    if (Device.texture.KeepAspect)
                    {
                        if (Device.texture.SoBigAsPossible == Drawing3d.Texture.BigAsPosible.Height)
                        {
                            Aspectx = (float)(h / w);
                        }
                        else
                        {
                            Aspecty = (float)(w / h);
                        }
                    }
                }
                for (int i = 0; i < Points.Length; i++)
                {
                    if (Device.texture.KeepAspect)
                    {
                        if (Aspecty != 1)
                        {
                            Texture[i] = new xyf((Points[i].x - (float)xMin) / (float)(xDiff), (Points[i].y - (float)yMin) / (float)(xDiff / Aspecty));
                        }
                        if (Aspectx != 1)
                        {
                            Texture[i] = new xyf((Points[i].x - (float)xMin) / (float)(yDiff / Aspectx), (Points[i].y - (float)yMin) / (float)(yDiff));
                        }
                    }
                    else
                    {
                        Texture[i] = new xyf((Points[i].x - (float)xMin) / (float)(xDiff), (Points[i].y - (float)yMin) / (float)(yDiff));
                    }
                }
            }
            else
            {
                for (int i = 0; i < Points.Length; i++)
                {
                    Texture[i] = Points[i] + Points[0] * (-1);
                }
            }

            Primitives2d.drawTriangles2d(Device, Indices, Points, Texture);
        }
Exemple #10
0
        void RefreshVertices()
        {
            Position = new xyzf[(UResolution + 1) * (VResolution + 1)];
            Normals  = new xyzf[(UResolution + 1) * (VResolution + 1)];

            Rectangled R       = new Rectangled(0, 0, 1, 1);
            double     xStep   = (float)1 / (float)(UResolution);
            double     yStep   = (float)1 / (float)(VResolution);
            xyzf       _Point  = new xyzf(0, 0, 0);
            xyzf       _Normal = new xyzf(0, 0, 0);
            float      ustep   = (float)(Width / (float)UResolution);
            float      vstep   = (float)(Height / (float)VResolution);

            for (int u = 0; u < UResolution + 1; u++)
            {
                int URow = u * (VResolution + 1);
                for (int v = 0; v < VResolution + 1; v++)
                {
                    Position[URow + v] = new xyzf((float)Origin.x + u * ustep, (float)Origin.y + v * vstep, (float)Origin.z);
                }
            }
            for (int u = 0; u < UResolution + 1; u++)
            {
                int URow = u * (VResolution + 1);
                for (int v = 0; v < VResolution + 1; v++)
                {
                    Normals[URow + v] = new xyzf(0, 0, 1);
                }
            }
            TextureCoords = new xyf[(UResolution + 1) * (VResolution + 1)];
            ustep         = (float)(1 / (float)UResolution);
            vstep         = (float)(1 / (float)VResolution);
            for (int u = 0; u < UResolution + 1; u++)
            {
                int URow = u * (VResolution + 1);
                for (int v = 0; v < VResolution + 1; v++)
                {
                    TextureCoords[URow + v] = new xyf(u * ustep, v * vstep);
                }
            }

            if (UseQuads)
            {
                Indices = new int[UResolution * VResolution * 4];
                int ID = 0;
                for (int u = 0; u < UResolution; u++)
                {
                    int URow = u * (VResolution + 1);
                    for (int v = 0; v < VResolution; v++)
                    {
                        Indices[ID]     = u * (VResolution + 1) + v;
                        Indices[ID + 1] = u * (VResolution + 1) + v + 1;
                        Indices[ID + 2] = (u + 1) * (VResolution + 1) + v + 1;
                        Indices[ID + 3] = (u + 1) * (VResolution + 1) + v;
                        ID += 4;
                    }
                }
                TriangleIndices = getTriangleIndices();
            }
            else
            {
                Indices = getTriangleIndices();
            }
        }