Ejemplo n.º 1
0
 void CheckBase()
 {
     if (Curve != null)
     {
         StandardBase = Base.DoComplete(new xyz(0, 0, 0), Direction);
     }
     CurveArray = StandardBase.ToMatrix() * _CurveArray;
 }
Ejemplo n.º 2
0
        void DrawSkeleton()
        {
            if (Device == null)
            {
                return;
            }
            Matrix      P  = Device.ProjectionMatrix;
            PolygonMode PM = Device.PolygonMode;

            Device.PolygonMode = PolygonMode.Line;
            float PW = Device.PenWidth;

            Device.PenWidth = PenWidth;
            Color C = Device.Emission;

            Device.Emission = Color;
            Device.PushMatrix();
            Device.ModelMatrix = Base.ToMatrix();
            bool LE = Device.LightEnabled;

            Device.LightEnabled = false;
            Device.drawRectangle(A, B);
            Device.LightEnabled = LE;
            Device.PopMatrix();
            Device.Emission    = C;
            Device.PenWidth    = PW;
            Device.PolygonMode = PM;

            Device.ProjectionMatrix = P;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// te current camera base will be setted as base for the <see cref="Angles"/>.
        /// </summary>
        public void SetRelativeSystem()
        {
            Base B = Base;

            B.BaseO       = new xyz(0, 0, 0);
            RelativSystem = B.ToMatrix();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the transformation matrix for a "look at" situation. The camera is at CameraPosition
        /// and looks to CameraTarget. Additionally a normalvector CameraUpVector has to be given, because the
        /// Camera can turn up or down...
        /// </summary>
        /// <param name="CameraPosition">Position of the camera</param>
        /// <param name="CameraTarget">The camera looks to that point</param>
        /// <param name="CameraUpVector">Normalvector of the camera</param>
        /// <example> Matrix M = LookAt(new xyz(0,10,2), new xyz(0,0,2), new xyz(0,0,1));</example>
        /// <returns></returns>
        public static Matrix LookAt(xyz CameraPosition, xyz CameraTarget, xyz CameraUpVector)
        {
            Base B = Base.UnitBase;

            B = Base.LookAt(CameraPosition, CameraTarget, CameraUpVector);
            return(B.ToMatrix().invert());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// sets the position of the shaft and of the top.
        /// </summary>
        /// <param name="Shaft">the shaft</param>
        /// <param name="Top">the top</param>
        public void SetShaftAndTop(xyz Shaft, xyz Top)
        {
            Base B = Base.DoComplete(Shaft, Top - Shaft);

            this._Transformation = B.ToMatrix();
            Size = Top.dist(Shaft);
        }
Ejemplo n.º 6
0
        void CheckLoxy()
        {
            Base DownBase = Base.UnitBase;
            Base UpBase   = Base.UnitBase;

            DownLoxy       = getLoxy(0, ref DownBase);
            UpLoxy         = getLoxy(1, ref UpBase);
            DownBase.BaseZ = DownBase.BaseZ * (-1);
            UpMatrix       = UpBase.ToMatrix();
            DownMatrix     = DownBase.ToMatrix();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// overriders the <see cref="CustomEntity.OnDraw(OpenGlDevice)"/> method.
        /// </summary>
        /// <param name="Device"></param>
        protected override void OnDraw(OpenGlDevice Device)
        {
            if (Device.RenderKind != RenderKind.Render)
            {
                return;
            }
            Device.PushMatrix();
            Device.ModelMatrix = Matrix.identity;
            _Base = new Base(true);


            if (Device.SnappItems.Count > 0)
            {
                if ((Device.SnappItems[0].Crossed) && (CrossStyle != Cross.None))
                {
                    Base Base = new Base(true);
                    Base.BaseO = Device.SnappItems[0].Point;

                    Color C = Device.Ambient;
                    Device.Ambient = ColoroFtheCrossSymbol;
                    double r = Device.PixelToWorld(Device.SnappItems[0].Point, CrossSize);
                    if (CrossStyle == Cross.Sphere)
                    {
                        Device.drawSphere(Device.SnappItems[0].Point, r / 2f);
                    }
                    if (CrossStyle == Cross.Cube)
                    {
                        Base B = Device.SnappItems[0].GetBase();

                        Matrix M = B.ToMatrix();
                        Device.PushMatrix();
                        Device.ModelMatrix = M;
                        Device.drawBox(new xyz(-r / 2, -r / 2, -r / 2), new xyz(r, r, r));
                        Device.PopMatrix();
                    }
                    if ((_Base.BaseO.X == 2) && (_Base.BaseO.y == 2) && (_Base.BaseO.Z == 2))
                    {
                    }
                    Device.Ambient = C;
                    return;
                }

                else
                {
                    _Base.BaseO = Device.SnappItems[0].Point;
                    if (_Base.BaseO.dist(Device.Currentxyz) > 0.1)
                    {
                    }
                    if (!AxisFix)
                    {
                        {
                            _Base = Device.SnappItems[0].GetBase();
                        }
                    }
                }
            }
            else
            {
                _Base       = Base.UnitBase;
                _Base.BaseO = Device.Currentxyz;
            }

            float PenW = Device.PenWidth;

            Device.PenWidth = PenWidth;
            Color SaveEmission = Device.Emission;
            bool  Save         = Device.LightEnabled;

            Device.LightEnabled = true;

            Device.Emission = xAxisColor;
            Device.drawLine(Base.BaseO - Base.BaseX * Device.PixelToWorld(Base.BaseO, Size), Base.BaseO + Base.BaseX * Device.PixelToWorld(Base.BaseO, Size));
            double d = Device.PixelToWorld(Base.BaseO, Size);

            Device.Emission = yAxisColor;
            Device.drawLine(Base.BaseO - Base.BaseY * Device.PixelToWorld(Base.BaseO, Size), Base.BaseO + Base.BaseY * Device.PixelToWorld(Base.BaseO, Size));
            Device.Emission = zAxisColor;
            Device.drawLine(Base.BaseO - Base.BaseZ * Device.PixelToWorld(Base.BaseO, Size), Base.BaseO + Base.BaseZ * Device.PixelToWorld(Base.BaseO, Size));
            Device.LightEnabled = Save;
            Device.Emission     = SaveEmission;
            Device.PenWidth     = PenW;
            Device.PopMatrix();

            BaseZ = Base.BaseZ;

            base.OnDraw(Device);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// overrides the <see cref="CustomEntity.OnDraw(OpenGlDevice)"/> method.
        /// </summary>
        /// <param name="Device"></param>
        protected override void OnDraw(OpenGlDevice Device)
        {
            base.OnDraw(Device);
            if (Transverse == null)
            {
                return;
            }
            if (Transverse.Count == 0)
            {
                return;
            }

            for (int i = 1; i > 0; i--)
            {
                if (Trace[i].dist(Trace[i - 1]) < Utils.epsilon)
                {
                    Trace.RemoveAt(i);
                }
            }
            if ((Trace.Count == 3) && (Trace.Closed()))
            {
                Trace.RemoveAt(2);
            }
            if (Trace.Count <= 1)
            {
                return;
            }
            //    if (Trace.Count <= 1) return;
            xyz Basey = new xyz(0, 0, 0);

            if (Trace.Count == 2)
            {
                Basey = new xyz(0, 0, -1);
                if ((Basey & (Trace[1] - Trace[0])).length() < 0.000001)
                {
                    Basey = new xyz(0, -1, 0);
                }
            }
            else
            {
                Basey = (((Trace[2] - Trace[1]) & (Trace[0] - Trace[1]))).normalized() * (-1);
            }

            for (int i = 0; i < Trace.Count - 1; i++)
            {
                xyz N1, N2;
                if (i == 0)
                {
                    if (Trace.Closed())
                    {
                        N1 = (Trace[i + 1] - Trace[i]).normalized() - (Trace[Trace.Count - 2] - Trace[i]).normalized();
                    }
                    else
                    {
                        N1 = (Trace[i + 1] - Trace[i]).normalized();
                    }

                    if ((i + 2) == Trace.Count)
                    {
                        N2 = (Trace[i] - Trace[i + 1]).normalized() & Basey;
                    }
                    else
                    {
                        N2 = (Trace[i] - Trace[i + 1]).normalized() - (Trace[i + 2] - Trace[i + 1]).normalized();
                    }
                }
                else
                if (i == (Trace.Count - 2))
                {
                    N1 = (Trace[i + 1] - Trace[i]).normalized() - (Trace[i - 1] - Trace[i]).normalized();
                    if (Trace.Closed())
                    {
                        N2 = (Trace[i] - Trace[0]).normalized() - (Trace[1] - Trace[0]).normalized();
                    }
                    else
                    {
                        N2 = (Trace[i] - Trace[Trace.Count - 1]).normalized();
                    }
                }
                else
                {
                    N1 = (Trace[i + 1] - Trace[i]).normalized() - (Trace[i - 1] - Trace[i]).normalized();
                    N2 = (Trace[i] - Trace[i + 1]).normalized() - (Trace[i + 2] - Trace[i + 1]).normalized();
                }
                if (Trace.Count == 2)
                {
                    N1 = Trace[1] - Trace[0];
                    N2 = Trace[0] - Trace[1];
                }
                Plane P1 = new Plane(Trace[i], N1.normalized());
                Plane P2 = new Plane(Trace[i + 1], N2.normalized());

                if (i > 0)
                {
                    Basey = Matrix.Mirror(P1) * Basey - Matrix.Mirror(P1) * new xyz(0, 0, 0);
                }
                Base B = new Base();
                B.BaseO = Trace[i];
                B.BaseZ = (Trace[i + 1] - Trace[i]).normalized();
                B.BaseY = Basey.normalized();
                B.BaseX = (B.BaseY & B.BaseZ).normalized();
                B.BaseY = B.BaseZ & B.BaseX * (-1);



                Matrix BInvert   = B.ToMatrix().invert();
                Plane  DownPlane = BInvert * P1;
                Plane  UpPlane   = BInvert * P2;
                Device.PushMatrix();
                Device.MulMatrix(B.ToMatrix());
                for (int m = 0; m < Transverse.Count; m++)
                {
                    for (int n = 0; n < Transverse[m].Count; n++)
                    {
                        CurveExtruder CE = new CurveExtruder();
                        CE.Height = -1;


                        CE.DownPlane = BInvert * P1;
                        CE.UpPlane   = BInvert * P2;
                        CE.Curve     = Transverse[m][n];
                        CE.Paint(Device);
                        if (Device.RenderKind == RenderKind.SnapBuffer)
                        {
                            SnappItem SI = Selector.StoredSnapItems[Selector.StoredSnapItems.Count - 1];
                            if (SI != null)
                            {
                                SI.OfObject = this;
                            }
                        }
                    }
                }

                double L = (Trace[i + 1] - Trace[i]).length();

                if ((i == 0) && (CloseFirst))
                {
                    Device.drawPolyPolyCurve(Transverse);
                }
                if ((i == Trace.Count - 2) && (CloseLast))
                {
                    Device.PushMatrix();
                    Device.MulMatrix(Matrix.Translation(new xyz(0, 0, L)));
                    Device.drawPolyPolyCurve(Transverse);
                    Device.PopMatrix();
                }
                Device.PopMatrix();
            }
        }