Esempio n. 1
0
        /// <summary>
        /// overrides the <see cref="PlaneSurface.Normal(double, double)"/> method.
        /// </summary>
        /// <param name="u">first parameter.</param>
        /// <param name="v">second parameter.</param>
        /// <returns>the normal vector.</returns>
        public override xyz Normal(double u, double v)
        {
            xy     value = new xy(u, v);
            double dir   = 1;

            if (!SameSense)
            {
                dir = -1;
            }
            u = value.x;
            v = value.y;
            if (!Smooth)
            {
                return(base.Normal(u, v));
            }
            if (value.dist(A11) < 0.001)
            {
                return(N11.normalized() * dir);
            }
            if (value.dist(A01) < 0.001)
            {
                return(N01.normalized() * dir);
            }
            if (value.dist(A10) < 0.001)
            {
                return(N10.normalized() * dir);
            }
            if (value.dist(A00) < 0.001)
            {
                return(N00.normalized() * dir);
            }

            if (A10.dist(A01) < 0.00001)
            {
                xyz B = BaryCentric(A00, A10, A11, value);
                return(((N00)*B.x + (N10)*B.y + (N11)*B.z) * dir);
            }
            if (((A10 - value) & (A01 - value)) == 0)
            {
            }
            if (((A00 - value) & (A01 - value)) > 0)
            {
                xyz B = BaryCentric(A11, A00, A01, value);
                return(((N11)*B.x + (N00)*B.y + (N01)*B.z) * dir);
            }
            else
            {
                xyz B = BaryCentric(A00, A11, A10, value);

                return(((N00)*B.x + (N11)*B.y + (N10)*B.z) * dir);
            }
        }
Esempio n. 2
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);
            }
        }