Esempio n. 1
0
        public void DrawVectors(Matrix4d transformacja)
        {
            if (VectorsVisibility)
            {
                GL.Begin(BeginMode.Lines);
                GL.Color3(1.0, 1.0, 0);
                foreach (var item in ControlArrayC1)
                {
                    for (int i = 1; i < 6; i++)
                    {
                        Matrix4d projection = MatrixProvider.ProjectionMatrix();
                        var      a          = projection.Multiply(transformacja.Multiply(item[0][i]));
                        var      b          = projection.Multiply(transformacja.Multiply(item[1][i]));
                        var      c          = projection.Multiply(transformacja.Multiply(2 * item[0][i] - item[1][i]));

                        //GL.Vertex2(new Vector2d(a.X / 720, a.Y / 375));
                        //GL.Vertex2(new Vector2d(b.X / 720, b.Y / 375));
                        //GL.Vertex2(new Vector2d((2*(item[0][i].X_Window / (1440.0 / 2.0) )- item[1][i].X_Window /(1440.0 / 2.0)), (2* (item[0][i].Y_Window / (1440.0 / 2.0) )- item[1][i].Y_Window / (1440.0 / 2.0))));
                        //GL.Vertex2(new Vector2d(item[1][i].X_Window/ (1440.0 / 2.0) , item[1][i].Y_Window/(750.0 / 2.0)));
                        GL.Vertex2(new Vector2d(c.X, c.Y));
                        GL.Vertex2(new Vector2d(b.X, b.Y));
                    }
                }

                GL.End();
            }
        }
Esempio n. 2
0
        public void DrawPolyline(Matrix4d transformacja)
        {
            GL.Begin(BeginMode.Lines);
            GL.Color3(1.0, 1.0, 1.0);
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4 - 1; j++)
                {
                    var _windowCoordinates = projection.Multiply(transformacja.Multiply(PatchPoints[i, j].Coordinates));
                    GL.Vertex2(_windowCoordinates.X, _windowCoordinates.Y);

                    _windowCoordinates = projection.Multiply(transformacja.Multiply(PatchPoints[i, j + 1].Coordinates));
                    GL.Vertex2(_windowCoordinates.X, _windowCoordinates.Y);
                }
            }

            for (int i = 0; i < 4 - 1; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    var _windowCoordinates = projection.Multiply(transformacja.Multiply(PatchPoints[i, j].Coordinates));
                    GL.Vertex2(_windowCoordinates.X, _windowCoordinates.Y);

                    _windowCoordinates = projection.Multiply(transformacja.Multiply(PatchPoints[i + 1, j].Coordinates));
                    GL.Vertex2(_windowCoordinates.X, _windowCoordinates.Y);
                }
            }

            GL.End();
        }
Esempio n. 3
0
        public void Draw(Matrix4d transformacja, int size = 4, double red = 1, double green = 1, double blue = 1)
        {
            //Matrix4d projekcja = MatrixProvider.ProjectionMatrix(100);
            GL.Enable(EnableCap.VertexProgramPointSize);
            GL.PointSize(size);
            GL.Begin(BeginMode.Points);


            if (_selected)
            {
                GL.Color3(0.0, 1.0, 0.0);
            }
            else
            {
                GL.Color3(red, green, blue);
            }

            Matrix4d projection = MatrixProvider.ProjectionMatrix();

            _windowCoordinates = projection.Multiply(transformacja.Multiply(_coordinates));
            GL.Vertex2(_windowCoordinates.X, _windowCoordinates.Y);
            _windowCoordinates.X = _windowCoordinates.X * 1440 / 2;
            _windowCoordinates.Y = _windowCoordinates.Y * 750 / 2;

            GL.End();
        }
Esempio n. 4
0
        public void Draw(Program program, ref Matrix4d world, SetWorldMatrixCallback setWorldMatrix, IModelMaterialBinder materialBinder)
        {
            ModelMaterial material = null;

            foreach (ModelMesh mesh in meshes)
            {
                if (setWorldMatrix != null)
                {
                    Matrix4d meshWorld;

                    if (mesh.bone != null)
                    {
                        mesh.bone.GetWorldTransform(out meshWorld);
                        world.Multiply(ref meshWorld, out meshWorld);
                        setWorldMatrix.Invoke(ref meshWorld);
                    }
                }

                foreach (ModelPart part in mesh.parts)
                {
                    if (part.Material != null && part.Material != material && materialBinder != null)
                    {
                        material = part.Material;
                        materialBinder.BindMaterial(part.Material);
                    }

                    program.Draw(part.Primitive, part.Count, elementBuffer, elementType, part.Offset);
                }
            }
        }
Esempio n. 5
0
        protected void DrawBezierCurve(Matrix4d transformacja, IEnumerable <Point> points)
        {
            GL.Begin(BeginMode.Lines);
            GL.Color3(1.0, 1.0, 1.0);

            ObservableCollection <Point> transformedProjectedPoints = new ObservableCollection <Point>();
            ObservableCollection <Point> temp = new ObservableCollection <Point>();

            foreach (var p in points)
            {
                var a = projekcjaRight.Multiply(transformacja.Multiply(p));
                transformedProjectedPoints.Add(new Point(a.X, a.Y, a.Z));
            }

            foreach (var p in transformedProjectedPoints)
            {
                temp.Add(p);
                if (temp.Count % 4 == 0 || p == transformedProjectedPoints.Last())
                {
                    var divisions = GetDivisions(transformacja, temp);
                    var point     = Casteljeu(temp, 0);

                    for (double t = divisions / 2; t <= 1; t += divisions / 2)
                    {
                        GL.Vertex2(point.X, point.Y);
                        point = Casteljeu(temp, t);
                        GL.Vertex2(point.X, point.Y);
                    }
                    temp.Clear();
                    temp.Add(p);
                }
            }
            GL.End();
        }
Esempio n. 6
0
 public override void DrawPolyline(Matrix4d transformacja)
 {
     GL.Begin(BeginMode.Lines);
     GL.Color3(1.0, 1.0, 1.0);
     if (PolylineEnabled)
     {
         for (int i = 0; i < PointsCollection.Count - 1; i++)
         {
             var windowCoordinates = projekcja.Multiply(transformacja.Multiply(PointsCollection[i].Coordinates));
             GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
             windowCoordinates = projekcja.Multiply(transformacja.Multiply(PointsCollection[i + 1].Coordinates));
             GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
         }
     }
     GL.End();
 }
Esempio n. 7
0
        public double GetDivisions(Matrix4d transformacja, ObservableCollection <Point> temp)
        {
            int    j      = temp.Count;
            double length = 0;

            for (int i = 0; i < j - 1; i++)
            {
                Vector4d a = projekcja.Multiply(transformacja.Multiply(temp[i + 1])) -
                             projekcja.Multiply(transformacja.Multiply(temp[i]));
                a.X    *= 1440;
                a.Y    *= 750;
                length += a.Length;
            }

            return(0.1 / length);
        }
Esempio n. 8
0
 public void GetWorldTransform(out Matrix4d result)
 {
     result = Transform;
     for (ModelBone parent = Parent; parent != null; parent = parent.parent)
     {
         result.Multiply(ref parent.transform, out result);
     }
 }
Esempio n. 9
0
        public void Draw(Matrix4d transformacja)
        {
            GL.Begin(BeginMode.Lines);

            GL.Color3(1.0, 0.0, 0.0);
            var vertex = transformacja.Multiply(vertices[0]);

            GL.Vertex2(_projection.Multiply(vertex).X, _projection.Multiply(vertex).Y);
            vertex = transformacja.Multiply(vertices[1]);
            GL.Vertex2(_projection.Multiply(vertex).X, _projection.Multiply(vertex).Y);

            GL.Color3(0.0, 1.0, 0.0);
            vertex = transformacja.Multiply(vertices[2]);
            GL.Vertex2(_projection.Multiply(vertex).X, _projection.Multiply(vertex).Y);
            vertex = transformacja.Multiply(vertices[3]);
            GL.Vertex2(_projection.Multiply(vertex).X, _projection.Multiply(vertex).Y);

            GL.Color3(0.0, 0.0, 1.0);
            vertex = transformacja.Multiply(vertices[4]);
            GL.Vertex2(_projection.Multiply(vertex).X, _projection.Multiply(vertex).Y);
            vertex = transformacja.Multiply(vertices[5]);
            GL.Vertex2(_projection.Multiply(vertex).X, _projection.Multiply(vertex).Y);

            GL.End();
            var temp = _projection.Multiply(transformacja.Multiply(_coordinates));

            WindowCoordinate = new Vector4d(temp.X * 720, temp.Y * 375, 0, 0);
        }
Esempio n. 10
0
        public void DrawPolyline(Matrix4d transformacja)
        {
            if (PolylineEnabled)
            {
                GL.Begin(BeginMode.Lines);
                GL.Color3(1.0, 1.0, 1.0);

                for (int i = 0; i < PatchPoints.GetLength(0); i++)
                {
                    for (int j = 0; j < PatchPoints.GetLength(1) - 1; j++)
                    {
                        var _windowCoordinates = projection.Multiply(transformacja.Multiply(PatchPoints[i, j].Coordinates));
                        GL.Vertex2(_windowCoordinates.X, _windowCoordinates.Y);

                        _windowCoordinates = projection.Multiply(transformacja.Multiply(PatchPoints[i, j + 1].Coordinates));
                        GL.Vertex2(_windowCoordinates.X, _windowCoordinates.Y);
                    }
                }

                for (int i = 0; i < PatchPoints.GetLength(0) - 1; i++)
                {
                    for (int j = 0; j < PatchPoints.GetLength(1); j++)
                    {
                        var _windowCoordinates = projection.Multiply(transformacja.Multiply(PatchPoints[i, j].Coordinates));
                        GL.Vertex2(_windowCoordinates.X, _windowCoordinates.Y);

                        _windowCoordinates = projection.Multiply(transformacja.Multiply(PatchPoints[i + 1, j].Coordinates));
                        GL.Vertex2(_windowCoordinates.X, _windowCoordinates.Y);
                    }
                }

                if (PatchesAreCylinder)
                {
                    for (int i = 0; i < PatchPoints.GetLength(0); i++)
                    {
                        var _windowCoordinates = projection.Multiply(transformacja.Multiply(PatchPoints[i, 0].Coordinates));
                        GL.Vertex2(_windowCoordinates.X, _windowCoordinates.Y);

                        _windowCoordinates = projection.Multiply(transformacja.Multiply(PatchPoints[i, PatchPoints.GetLength(1) - 1].Coordinates));
                        GL.Vertex2(_windowCoordinates.X, _windowCoordinates.Y);
                    }
                }
                GL.End();
            }
        }
Esempio n. 11
0
        public void Draw(Matrix4d transformacja)
        {
            Matrix4d projekcja = MatrixProvider.ProjectionMatrix();

            GL.Begin(BeginMode.Lines);
            GL.Color3(1.0, 1.0, 1.0);

            foreach (var relations in _relationsList)
            {
                var vertex  = transformacja.Multiply(_verticesList[relations.Item1]);
                var vertex2 = transformacja.Multiply(_verticesList[relations.Item2]);
                GL.Vertex2(projekcja.Multiply(vertex).X, projekcja.Multiply(vertex).Y);
                GL.Vertex2(projekcja.Multiply(vertex2).X, projekcja.Multiply(vertex2).Y);
                //}
                //GL.Vertex3(_verticesList[relations.Item1]);
                //GL.Vertex3(_verticesList[relations.Item2]);
            }
            GL.End();
        }
Esempio n. 12
0
        public void DrawPatch(Matrix4d transformacja)
        {
            GL.Begin(BeginMode.Lines);
            GL.Color3(1.0, 1.0, 1.0);


            for (int i = 0; i < _curvesPatchPoints1.GetLength(0) - 1; i++)
            {
                for (int j = 0; j < _curvesPatchPoints1.GetLength(1); j++)
                {
                    // if (_curvesPatchPoints[i + 1, j] == null || _curvesPatchPoints[i, j] == null) break;

                    var _windowCoordinates = projection.Multiply(transformacja.Multiply(_curvesPatchPoints1[i, j].Coordinates));
                    GL.Vertex2(_windowCoordinates.X, _windowCoordinates.Y);


                    _windowCoordinates = projection.Multiply(transformacja.Multiply(_curvesPatchPoints1[i + 1, j].Coordinates));

                    GL.Vertex2(_windowCoordinates.X, _windowCoordinates.Y);
                }
            }



            for (int i = 0; i < _curvesPatchPoints.GetLength(0); i++)
            {
                for (int j = 0; j < _curvesPatchPoints.GetLength(1) - 1; j++)
                {
                    //if (_curvesPatchPoints[i , j+1] == null || _curvesPatchPoints[i, j] == null) break;


                    var _windowCoordinates = projection.Multiply(transformacja.Multiply(_curvesPatchPoints[i, j].Coordinates));
                    GL.Vertex2(_windowCoordinates.X, _windowCoordinates.Y);

                    _windowCoordinates = projection.Multiply(transformacja.Multiply(_curvesPatchPoints[i, j + 1].Coordinates));
                    GL.Vertex2(_windowCoordinates.X, _windowCoordinates.Y);
                }
            }


            GL.End();
        }
Esempio n. 13
0
        public void DrawStereoscopy(Matrix4d transformacja)
        {
            double StereoscopyMin = 1;

            GL.Enable(EnableCap.VertexProgramPointSize);
            GL.PointSize(3);
            GL.Begin(BeginMode.Points);


            //zmiana odleglosciu oczu
            Matrix4d projekcja = MatrixProvider.RightProjectionMatrix();
            var      a         = projekcja.Multiply(transformacja.Multiply(_coordinates));



            projekcja = MatrixProvider.LeftProjectionMatrix();
            var b = projekcja.Multiply(transformacja.Multiply(_coordinates));

            var c = a - b;

            c.X = c.X * 1440 / 2;
            c.Y = c.Y * 750 / 2;
            if (c.Length < StereoscopyMin)
            {
                GL.Color3(1.0, 0.0, 1.0);
                GL.Vertex2((a.X + b.X) / 2, (a.Y + b.Y) / 2);
            }
            else
            {
                GL.Color3(1.0, 0, 0);
                GL.Vertex2(a.X, a.Y);
                GL.Color3(0, 0, 1.0);
                GL.Vertex2(b.X, b.Y);
            }

            _windowCoordinates.X = (a.X / 2 + b.X / 2) * 1440 / 2;
            _windowCoordinates.Y = (a.Y / 2 + b.Y / 2) * 750 / 2;

            GL.End();
        }
Esempio n. 14
0
        public override void DrawPolylineStereoscopy(Matrix4d transformacja)
        {
            if (PolylineEnabled)
            {
                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);
                GL.Begin(BeginMode.Lines);
                GL.Color3(0.6, 0.0, 0.0);

                for (int i = 0; i < PointsCollection.Count - 1; i++)
                {
                    var windowCoordinates =
                        projekcjaRight.Multiply(transformacja.Multiply(PointsCollection[i].Coordinates));
                    GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                    windowCoordinates =
                        projekcjaRight.Multiply(transformacja.Multiply(PointsCollection[i + 1].Coordinates));
                    GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                }



                GL.Color3(0.0, 0.0, 0.6);

                for (int i = 0; i < PointsCollection.Count - 1; i++)
                {
                    var windowCoordinates =
                        projekcjaLeft.Multiply(transformacja.Multiply(PointsCollection[i].Coordinates));
                    GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                    windowCoordinates =
                        projekcjaLeft.Multiply(transformacja.Multiply(PointsCollection[i + 1].Coordinates));
                    GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                }


                GL.End();
            }
        }
Esempio n. 15
0
        public override void DrawCurveStereoscopy(Matrix4d transformacja)
        {
            if (_interpolation)
            {
                CalculateInterpolationDeBoore();
                transformedProjectedPoints.Clear();
                foreach (var p in _pointsCollectionInterpolation)
                {
                    var a = projekcjaRight.Multiply(transformacja.Multiply(p));
                    transformedProjectedPoints.Add(new Point(a.X, a.Y, a.Z));
                }

                SetSplineKnots();

                CalculateAdditionalPoints(_pointsCollectionInterpolation);
                double divisions = GetDivisions(transformacja, _additionalPointsCollection2);

                if (IsBernsteinBasis)
                {
                    foreach (var p in _additionalPointsCollection)
                    {
                        p.Draw(transformacja, 4);
                    }
                    foreach (var p in _additionalPointsCollection2)
                    {
                        p.Draw(transformacja, 4);
                    }
                    DrawBezierCurveStereoscopy(transformacja, _additionalPointsCollection2);
                }
                else
                {
                    GL.Enable(EnableCap.Blend);
                    GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);
                    GL.Begin(BeginMode.Lines);
                    GL.Color3(0.6, 0.0, 0.0);
                    for (double t = 0; t < 1; t += divisions)
                    {
                        if (t >= _knots[3] && t <= _knots[_knots.Length - PolynomialDegree - 4])
                        {
                            var u = BSplinePoint(t);
                            var v = BSplinePoint(t + divisions);

                            // var windowCoordinates = projekcja.Multiply(transformacja.Multiply(u.Coordinates));
                            GL.Vertex2(u.X, u.Y);

                            ///   windowCoordinates = projekcja.Multiply(transformacja.Multiply(v.Coordinates));
                            GL.Vertex2(v.X, v.Y);
                        }
                    }

                    GL.Color3(0.0, 0.0, 0.6);
                    for (double t = 0; t < 1; t += divisions)
                    {
                        if (t >= _knots[3] && t <= _knots[_knots.Length - PolynomialDegree - 4])
                        {
                            var u = BSplinePoint(t);
                            var v = BSplinePoint(t + divisions);

                            // var windowCoordinates = projekcja.Multiply(transformacja.Multiply(u.Coordinates));
                            GL.Vertex2(u.X, u.Y);

                            ///   windowCoordinates = projekcja.Multiply(transformacja.Multiply(v.Coordinates));
                            GL.Vertex2(v.X, v.Y);
                        }
                    }
                    GL.End();
                }
            }


            else
            {
                transformedProjectedPoints.Clear();
                foreach (var p in PointsCollection)
                {
                    var a = projekcjaRight.Multiply(transformacja.Multiply(p));
                    transformedProjectedPoints.Add(new Point(a.X, a.Y, a.Z));
                }

                SetSplineKnots();

                CalculateAdditionalPoints(PointsCollection);
                double divisions = GetDivisions(transformacja, _additionalPointsCollection2);

                if (IsBernsteinBasis)
                {
                    foreach (var p in _additionalPointsCollection)
                    {
                        p.Draw(transformacja, 4);
                    }
                    foreach (var p in _additionalPointsCollection2)
                    {
                        p.Draw(transformacja, 4);
                    }
                    DrawBezierCurveStereoscopy(transformacja, _additionalPointsCollection2);
                }
                else
                {
                    GL.Enable(EnableCap.Blend);
                    GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);
                    GL.Begin(BeginMode.Lines);
                    GL.Color3(0.6, 0.0, 0.0);
                    for (double t = 0; t < 1; t += divisions)
                    {
                        if (t >= _knots[3] && t <= _knots[_knots.Length - PolynomialDegree - 4])
                        {
                            var u = BSplinePoint(t);
                            var v = BSplinePoint(t + divisions);

                            // var windowCoordinates = projekcja.Multiply(transformacja.Multiply(u.Coordinates));
                            GL.Vertex2(u.X, u.Y);

                            ///   windowCoordinates = projekcja.Multiply(transformacja.Multiply(v.Coordinates));
                            GL.Vertex2(v.X, v.Y);
                        }
                    }

                    GL.Color3(0.0, 0.0, 0.6);
                    for (double t = 0; t < 1; t += divisions)
                    {
                        if (t >= _knots[3] && t <= _knots[_knots.Length - PolynomialDegree - 4])
                        {
                            var u = BSplinePoint(t);
                            var v = BSplinePoint(t + divisions);

                            // var windowCoordinates = projekcja.Multiply(transformacja.Multiply(u.Coordinates));
                            GL.Vertex2(u.X, u.Y);

                            ///   windowCoordinates = projekcja.Multiply(transformacja.Multiply(v.Coordinates));
                            GL.Vertex2(v.X, v.Y);
                        }
                    }
                    GL.End();
                }
            }
        }
Esempio n. 16
0
        public override void DrawPolylineStereoscopy(Matrix4d transformacja)
        {
            if (_interpolation)
            {
                if (IsBernsteinBasis)
                {
                    if (PolylineEnabled)
                    {
                        CalculateAdditionalPoints(_pointsCollectionInterpolation);

                        GL.Enable(EnableCap.Blend);
                        GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);
                        GL.Begin(BeginMode.Lines);
                        GL.Color3(0.6, 0.0, 0.0);


                        for (int i = 0; i < _additionalPointsCollection2.Count - 1; i++)
                        {
                            var windowCoordinates =
                                projekcjaRight.Multiply(transformacja.Multiply(_additionalPointsCollection2[i].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                            windowCoordinates =
                                projekcjaRight.Multiply(transformacja.Multiply(_additionalPointsCollection2[i + 1].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                        }

                        GL.Color3(0.0, 0.0, 0.6);

                        for (int i = 0; i < _additionalPointsCollection2.Count - 1; i++)
                        {
                            var windowCoordinates =
                                projekcjaLeft.Multiply(transformacja.Multiply(_additionalPointsCollection2[i].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                            windowCoordinates =
                                projekcjaLeft.Multiply(transformacja.Multiply(_additionalPointsCollection2[i + 1].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                        }
                        GL.End();
                    }
                }
                else
                {
                    if (PolylineEnabled)
                    {
                        GL.Enable(EnableCap.Blend);
                        GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);
                        GL.Begin(BeginMode.Lines);
                        GL.Color3(0.6, 0.0, 0.0);

                        for (int i = 0; i < _pointsCollectionInterpolation.Count - 1; i++)
                        {
                            var windowCoordinates =
                                projekcjaRight.Multiply(transformacja.Multiply(_pointsCollectionInterpolation[i].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                            windowCoordinates =
                                projekcjaRight.Multiply(transformacja.Multiply(_pointsCollectionInterpolation[i + 1].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                        }

                        GL.Color3(0.0, 0.0, 0.6);
                        for (int i = 0; i < _pointsCollectionInterpolation.Count - 1; i++)
                        {
                            var windowCoordinates =
                                projekcjaLeft.Multiply(transformacja.Multiply(_pointsCollectionInterpolation[i].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                            windowCoordinates =
                                projekcjaLeft.Multiply(transformacja.Multiply(_pointsCollectionInterpolation[i + 1].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                        }

                        GL.End();
                    }
                }
            }
            else
            {
                if (IsBernsteinBasis)
                {
                    if (PolylineEnabled)
                    {
                        CalculateAdditionalPoints(PointsCollection);

                        GL.Enable(EnableCap.Blend);
                        GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);
                        GL.Begin(BeginMode.Lines);
                        GL.Color3(0.6, 0.0, 0.0);


                        for (int i = 0; i < _additionalPointsCollection2.Count - 1; i++)
                        {
                            var windowCoordinates =
                                projekcjaRight.Multiply(transformacja.Multiply(_additionalPointsCollection2[i].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                            windowCoordinates =
                                projekcjaRight.Multiply(transformacja.Multiply(_additionalPointsCollection2[i + 1].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                        }

                        GL.Color3(0.0, 0.0, 0.6);

                        for (int i = 0; i < _additionalPointsCollection2.Count - 1; i++)
                        {
                            var windowCoordinates =
                                projekcjaLeft.Multiply(transformacja.Multiply(_additionalPointsCollection2[i].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                            windowCoordinates =
                                projekcjaLeft.Multiply(transformacja.Multiply(_additionalPointsCollection2[i + 1].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                        }
                        GL.End();
                    }
                }
                else
                {
                    if (PolylineEnabled)
                    {
                        GL.Enable(EnableCap.Blend);
                        GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);
                        GL.Begin(BeginMode.Lines);
                        GL.Color3(0.6, 0.0, 0.0);

                        for (int i = 0; i < PointsCollection.Count - 1; i++)
                        {
                            var windowCoordinates =
                                projekcjaRight.Multiply(transformacja.Multiply(PointsCollection[i].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                            windowCoordinates =
                                projekcjaRight.Multiply(transformacja.Multiply(PointsCollection[i + 1].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                        }

                        GL.Color3(0.0, 0.0, 0.6);
                        for (int i = 0; i < PointsCollection.Count - 1; i++)
                        {
                            var windowCoordinates =
                                projekcjaLeft.Multiply(transformacja.Multiply(PointsCollection[i].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                            windowCoordinates =
                                projekcjaLeft.Multiply(transformacja.Multiply(PointsCollection[i + 1].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                        }

                        GL.End();
                    }
                }
            }
        }
Esempio n. 17
0
        public void DrawStereoscopy(Matrix4d transformacja)
        {
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);
            GL.Begin(BeginMode.Lines);

            GL.Color3(0.6, 0.0, 0.0);
            var vertex = transformacja.Multiply(vertices[0]);

            GL.Vertex2(_projectionRight.Multiply(vertex).X, _projectionRight.Multiply(vertex).Y);
            vertex = transformacja.Multiply(vertices[1]);
            GL.Vertex2(_projectionRight.Multiply(vertex).X, _projectionRight.Multiply(vertex).Y);


            vertex = transformacja.Multiply(vertices[2]);
            GL.Vertex2(_projectionRight.Multiply(vertex).X, _projectionRight.Multiply(vertex).Y);
            vertex = transformacja.Multiply(vertices[3]);
            GL.Vertex2(_projectionRight.Multiply(vertex).X, _projectionRight.Multiply(vertex).Y);


            vertex = transformacja.Multiply(vertices[4]);
            GL.Vertex2(_projectionRight.Multiply(vertex).X, _projectionRight.Multiply(vertex).Y);
            vertex = transformacja.Multiply(vertices[5]);
            GL.Vertex2(_projectionRight.Multiply(vertex).X, _projectionRight.Multiply(vertex).Y);


            GL.Color3(0.0, 0.0, 0.6);
            vertex = transformacja.Multiply(vertices[0]);
            GL.Vertex2(_projectionLeft.Multiply(vertex).X, _projectionLeft.Multiply(vertex).Y);
            vertex = transformacja.Multiply(vertices[1]);
            GL.Vertex2(_projectionLeft.Multiply(vertex).X, _projectionLeft.Multiply(vertex).Y);


            vertex = transformacja.Multiply(vertices[2]);
            GL.Vertex2(_projectionLeft.Multiply(vertex).X, _projectionLeft.Multiply(vertex).Y);
            vertex = transformacja.Multiply(vertices[3]);
            GL.Vertex2(_projectionLeft.Multiply(vertex).X, _projectionLeft.Multiply(vertex).Y);


            vertex = transformacja.Multiply(vertices[4]);
            GL.Vertex2(_projectionLeft.Multiply(vertex).X, _projectionLeft.Multiply(vertex).Y);
            vertex = transformacja.Multiply(vertices[5]);
            GL.Vertex2(_projectionLeft.Multiply(vertex).X, _projectionLeft.Multiply(vertex).Y);
            GL.End();
            var temp = _projectionLeft.Multiply(transformacja.Multiply(_coordinates));

            WindowCoordinate = new Vector4d(temp.X * 720, temp.Y * 375, 0, 0);
        }
Esempio n. 18
0
        public void DrawBezierCurveStereoscopy(Matrix4d transformacja, ObservableCollection <Point> Points)
        {
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);
            GL.Begin(BeginMode.Lines);
            GL.Color3(0.6, 0.0, 0.0);
            int j = 0;

            ObservableCollection <Point> temp = new ObservableCollection <Point>();
            ObservableCollection <Point> transformedProjectedPoints = new ObservableCollection <Point>();

            foreach (var p in Points)
            {
                var a = projekcjaRight.Multiply(transformacja.Multiply(p));
                transformedProjectedPoints.Add(new Point(a.X, a.Y, a.Z));
            }

            foreach (var p in transformedProjectedPoints)
            {
                j++;
                temp.Add(p);
                if (j % 4 == 0 || p == transformedProjectedPoints.Last())
                {
                    double divisions = GetDivisions(temp);
                    var    point     = Casteljeu(temp, 0);
                    for (double t = divisions / 2; t <= 1; t += divisions / 2)
                    {
                        GL.Vertex2(point.X, point.Y);
                        point = Casteljeu(temp, t);
                        GL.Vertex2(point.X, point.Y);
                    }
                    temp.Clear();
                    temp.Add(p);
                    j = 1;
                }
            }

            GL.Color3(0.0, 0.0, 0.6);
            j = 0;
            ObservableCollection <Point> temp2 = new ObservableCollection <Point>();

            foreach (var p in Points)
            {
                j++;
                temp2.Add(p);
                if (j % 4 == 0 || p == PointsCollection.Last())
                {
                    double divisions = GetDivisions(transformacja, temp2);

                    var point             = Casteljeu(temp2, 0);
                    var windowCoordinates = projekcjaLeft.Multiply(transformacja.Multiply(point));
                    for (double t = divisions / 2; t <= 1; t += divisions / 2)
                    {
                        GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);

                        point             = Casteljeu(temp2, t);
                        windowCoordinates = projekcjaLeft.Multiply(transformacja.Multiply(point));
                        GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                    }
                    temp2.Clear();
                    temp2.Add(p);
                    j = 1;
                }
            }
            GL.End();
        }
Esempio n. 19
0
        public void DrawStereoscopy(Matrix4d transformacja)
        {
            const int renderWidth  = 1440;
            const int renderHeight = 750;

            GL.Begin(BeginMode.Lines);
            GL.Color3(0.6, 0, 0);


            Matrix4d projekcja = MatrixProvider.RightProjectionMatrix();

            foreach (var relations in _relationsList)
            {
                var avertex  = transformacja.Multiply(_verticesList[relations.Item1]);
                var avertex2 = transformacja.Multiply(_verticesList[relations.Item2]);
                var dx       = projekcja.M13 * avertex.Z;
                var dx2      = projekcja.M13 * avertex2.Z;
                var vertex   = projekcja.Multiply(avertex);
                var vertex2  = projekcja.Multiply(avertex2);
                GL.Vertex2(vertex.X, vertex.Y);
                GL.Vertex2(vertex2.X, vertex2.Y);
            }
            GL.End();

            Bitmap bmp1 = new Bitmap(renderWidth, renderHeight);

            System.Drawing.Imaging.BitmapData dat = bmp1.LockBits(new Rectangle(0, 0, renderWidth, renderHeight), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
            GL.ReadPixels(0, 0, renderWidth, renderHeight, PixelFormat.Bgra, PixelType.UnsignedByte, dat.Scan0);
            bmp1.UnlockBits(dat);
            //bmp1.Save("D:\\ModelowanieGeometryczne\\a1.bmp", ImageFormat.Bmp);

            GL.Clear(ClearBufferMask.ColorBufferBit);


            GL.Begin(BeginMode.Lines);
            GL.Color3(0, 0, 0.9);


            projekcja = MatrixProvider.LeftProjectionMatrix();
            foreach (var relations in _relationsList)
            {
                var avertex  = transformacja.Multiply(_verticesList[relations.Item1]);
                var avertex2 = transformacja.Multiply(_verticesList[relations.Item2]);
                var dx       = projekcja.M13 * avertex.Z;
                var dx2      = projekcja.M13 * avertex2.Z;
                var vertex   = projekcja.Multiply(avertex);
                var vertex2  = projekcja.Multiply(avertex2);
                GL.Vertex2(vertex.X, vertex.Y);
                GL.Vertex2(vertex2.X, vertex2.Y);
            }
            GL.End();

            Bitmap bmp2 = new Bitmap(renderWidth, renderHeight);

            System.Drawing.Imaging.BitmapData dat2 = bmp2.LockBits(new Rectangle(0, 0, renderWidth, renderHeight), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
            GL.ReadPixels(0, 0, renderWidth, renderHeight, PixelFormat.Bgra, PixelType.UnsignedByte, dat2.Scan0);
            bmp2.UnlockBits(dat2);
            // bmp2.Save("D:\\ModelowanieGeometryczne\\a2.bmp", ImageFormat.Bmp);

            GL.Clear(ClearBufferMask.ColorBufferBit);

            Bitmap bmp3 = bmp2;

            Color temp, pixeltemp, result;

            ////Działa dla dowolnego koloru torusa 1 i torusa 2

            for (int i = 0; i < renderWidth; i++)
            {
                for (int j = 0; j < renderHeight; j++)
                {
                    temp = bmp1.GetPixel(i, j);
                    if (temp.R == 0 && temp.G == 0 && temp.B == 0)
                    {
                    }
                    else
                    {
                        pixeltemp = bmp3.GetPixel(i, j);
                        result    = Color.FromArgb(Math.Min(temp.R + pixeltemp.R, 255), Math.Min(temp.G + pixeltemp.G, 255), Math.Min(temp.B + pixeltemp.B, 255));
                        bmp3.SetPixel(i, j, result);
                    }
                }
            }

            //Writable bitmap
            bmp3.Save("D:\\ModelowanieGeometryczne\\a3.bmp", ImageFormat.Bmp);



            //Color k1 = Color.FromArgb(87, 0, 0);
            //Color k2 = Color.FromArgb(87, 0, 173);
            //for (int i = 0; i < RenderWidth; i++)
            //{
            //    for (int j = 0; j < RenderHeight; j++)
            //    {


            //        if (bmp1.GetPixel(i, j).R == 0)
            //        {

            //        }
            //        else if (bmp3.GetPixel(i, j).B == 0)
            //        {

            //            //Blending colors overlapped lines.

            //            bmp3.SetPixel(i, j, k1);
            //        }
            //        else
            //        {

            //            bmp3.SetPixel(i, j, k2);
            //        }

            //    }
            //}
            //bmp3.Save("D:\\ModelowanieGeometryczne\\a3.bmp", ImageFormat.Bmp);


            dat2 = bmp2.LockBits(new Rectangle(0, 0, renderWidth, renderHeight), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
            GL.DrawPixels(renderWidth, renderHeight, PixelFormat.Bgra, PixelType.UnsignedByte, dat2.Scan0);
            bmp2.UnlockBits(dat2);
        }
Esempio n. 20
0
 private Matrix4d GetOrientationMatrix()
 {
     return(_cameraOrientation.Multiply(_tempCameraOrientation));
 }
Esempio n. 21
0
        /// <summary>
        /// This is where we do our rendering
        /// Called from UI thread = UI code safe in this function
        /// </summary>
        public override void Render(DrawArgs drawArgs)
        {
            if (!isInitialized || (this.world.Name == "Earth" && World.Settings.EnableAtmosphericScattering))
            {
                return;
            }

            // Camera & Device shortcuts ;)
            CameraBase camera = drawArgs.WorldCamera;
            Device     device = drawArgs.device;

            //if(camera.Altitude > 200e3) return;

            Point3d cameraPos            = camera.Position;
            double  distToCenterOfPlanet = (camera.Altitude + camera.WorldRadius);

            // Create or refresh SkyGradient dome
            if (mesh == null || lastAltitude != camera.Altitude)
            {
                // Compute distance to horizon and dome radius
                double tangentalDistance = Math.Sqrt(distToCenterOfPlanet * distToCenterOfPlanet - camera.WorldRadius * camera.WorldRadius);
                double domeRadius        = tangentalDistance;

                // horizon latitude
                double horizonLat = (-Math.PI / 2 + Math.Acos(tangentalDistance / distToCenterOfPlanet)) * 180 / Math.PI;

                // zenith latitude
                double zenithLat = 90;
                if (camera.Altitude >= thickness)
                {
                    double tangentalDistanceZenith = Math.Sqrt(distToCenterOfPlanet * distToCenterOfPlanet - (camera.WorldRadius + thickness) * (camera.WorldRadius + thickness));
                    zenithLat = (-Math.PI / 2 + Math.Acos(tangentalDistanceZenith / distToCenterOfPlanet)) * 180 / Math.PI;
                }
                if (camera.Altitude < thickness && camera.Altitude > thickness * 0.8)
                {
                    zenithLat = (thickness - camera.Altitude) / (thickness - thickness * 0.8) * 90;
                }
                // new mesh
                if (mesh != null)
                {
                    mesh.Dispose();
                }
                mesh         = ColoredSphere(device, domeRadius, horizonLat, zenithLat, 128, 24);
                lastAltitude = camera.Altitude;
            }

            // set texture to null
            device.SetTexture(0, null);
            device.TextureState[0].ColorOperation = TextureOperation.BlendCurrentAlpha;
            device.VertexFormat = CustomVertex.PositionColored.Format;

            // save world and projection transform
            Matrix origWorld      = device.Transform.World;
            Matrix origProjection = device.Transform.Projection;

            // move SkyGradient dome
            Matrix4d SkyGradientTrans;
            Point3d  cameraCoord = MathEngine.CartesianToSpherical(cameraPos.X, cameraPos.Y, cameraPos.Z);
            double   camLat      = cameraCoord.Y;
            double   camLon      = cameraCoord.Z;

            SkyGradientTrans = Matrix4d.Translation(0, 0, distToCenterOfPlanet);
            SkyGradientTrans = Matrix4d.Multiply(SkyGradientTrans, Matrix4d.RotationY(-camLat + Math.PI / 2));
            SkyGradientTrans = Matrix4d.Multiply(SkyGradientTrans, Matrix4d.RotationZ(camLon));

            device.Transform.World = ConvertDX.FromMatrix4d(SkyGradientTrans);

            // Recenter
            Recenter(drawArgs);

            // Save fog status
            bool origFog = device.RenderState.FogEnable;

            device.RenderState.FogEnable = false;

            // Set new one (to avoid being clipped) - probably better ways of doing this?
            double aspectRatio = (double)device.Viewport.Width / device.Viewport.Height;

            device.Transform.Projection = ConvertDX.FromMatrix4d(Matrix4d.PerspectiveFovRH(camera.Fov.Radians, aspectRatio, 1000, 30000000.0));

            // draw
            //device.RenderState.FillMode = FillMode.WireFrame;
            mesh.DrawSubset(0);

            // Restore device states
            device.RenderState.FillMode      = FillMode.Solid;
            device.Transform.World           = origWorld;
            device.Transform.Projection      = origProjection;
            device.RenderState.FogEnable     = origFog;
            device.RenderState.ZBufferEnable = true;

            // Fog effect
            if (useFog)
            {
                // Compute distance to horizon and camera altitude
                double tangentalDistance = Math.Sqrt(distToCenterOfPlanet * distToCenterOfPlanet - camera.WorldRadius * camera.WorldRadius);
                double a = camera.Altitude;
                device.RenderState.FogEnable    = true;
                device.RenderState.FogColor     = horizonColor;
                device.RenderState.FogTableMode = FogMode.Linear;
                device.RenderState.FogStart     = (float)(a * nearFactor);
                device.RenderState.FogEnd       = (float)(tangentalDistance * farFactor);
            }
        }
Esempio n. 22
0
        public override void DrawPolyline(Matrix4d transformacja)
        {
            if (_interpolation)
            {
                //  var debor = CalculateInterpolationDeBoore(transformacja);

                CalculateInterpolationDeBoore();
                var debor = _pointsCollectionInterpolation;
                if (IsBernsteinBasis)
                {
                    if (PolylineEnabled)
                    {//TODO: tu wroc
                        CalculateAdditionalPoints(_pointsCollectionInterpolation);
                        GL.Begin(BeginMode.Lines);
                        GL.Color3(1.0, 1.0, 1.0);


                        for (int i = 0; i < _additionalPointsCollection2.Count - 1; i++)
                        {
                            var windowCoordinates =
                                projekcja.Multiply(transformacja.Multiply(_additionalPointsCollection2[i].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                            windowCoordinates =
                                projekcja.Multiply(transformacja.Multiply(_additionalPointsCollection2[i + 1].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                        }

                        GL.End();
                    }
                }
                else
                {
                    if (PolylineEnabled)
                    {
                        GL.Begin(BeginMode.Lines);
                        GL.Color3(1.0, 1.0, 1.0);

                        for (int i = 0; i < _pointsCollectionInterpolation.Count - 1; i++)
                        {
                            var windowCoordinates =
                                projekcja.Multiply(transformacja.Multiply(_pointsCollectionInterpolation[i].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                            windowCoordinates =
                                projekcja.Multiply(transformacja.Multiply(_pointsCollectionInterpolation[i + 1].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                        }

                        GL.End();
                    }
                }
            }
            else
            {
                if (IsBernsteinBasis)
                {
                    if (PolylineEnabled)
                    {
                        CalculateAdditionalPoints(PointsCollection);
                        GL.Begin(BeginMode.Lines);
                        GL.Color3(1.0, 1.0, 1.0);


                        for (int i = 0; i < _additionalPointsCollection2.Count - 1; i++)
                        {
                            var windowCoordinates =
                                projekcja.Multiply(transformacja.Multiply(_additionalPointsCollection2[i].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                            windowCoordinates =
                                projekcja.Multiply(transformacja.Multiply(_additionalPointsCollection2[i + 1].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                        }

                        GL.End();
                    }
                }
                else
                {
                    if (PolylineEnabled)
                    {
                        GL.Begin(BeginMode.Lines);
                        GL.Color3(1.0, 1.0, 1.0);

                        for (int i = 0; i < PointsCollection.Count - 1; i++)
                        {
                            var windowCoordinates =
                                projekcja.Multiply(transformacja.Multiply(PointsCollection[i].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                            windowCoordinates =
                                projekcja.Multiply(transformacja.Multiply(PointsCollection[i + 1].Coordinates));
                            GL.Vertex2(windowCoordinates.X, windowCoordinates.Y);
                        }

                        GL.End();
                    }
                }
            }
        }