コード例 #1
0
ファイル: Matrix.cs プロジェクト: Daxode/CueNET3DProjection
        //Matrix rotation
        public static PointF3D Rotate(PointF3D rotation, PointF3D vertex)
        {
            float[,] rotationX =
            {
                { 1,                           0,                            0 },
                { 0, (float)Math.Cos(rotation.x), (float)-Math.Sin(rotation.x) },
                { 0, (float)Math.Sin(rotation.x), (float)Math.Cos(rotation.x)  }
            };

            float[,] rotationY =
            {
                { (float)Math.Cos(rotation.y),  0, (float)Math.Sin(rotation.y) },
                {                            0, 1,                           0 },
                { (float)-Math.Sin(rotation.y), 0, (float)Math.Cos(rotation.y) }
            };

            float[,] rotationZ =
            {
                { (float)Math.Cos(rotation.z), (float)-Math.Sin(rotation.z), 0 },
                { (float)Math.Sin(rotation.z), (float)Math.Cos(rotation.z),  0 },
                {                           0,                            0, 1 }
            };

            PointF3D rotated = Multiply3D(rotationY, vertex);

            rotated = Multiply3D(rotationX, rotated);
            rotated = Multiply3D(rotationZ, rotated);

            return(rotated);
        }
コード例 #2
0
        public static Model GetModel(string path, PointF3D translationToMid, PointF3D rotation, float scale)
        {
            StreamReader      fileReader  = new StreamReader(path);
            List <PointF3D[]> vertexLines = new List <PointF3D[]>();
            List <PolyLine[]> lineLines   = new List <PolyLine[]>();
            List <PolyLine[]> faceLines   = new List <PolyLine[]>();

            if (fileReader != null)
            {
                while (!fileReader.EndOfStream)
                {
                    var line = fileReader.ReadLine();
                    if (line.StartsWith("v "))
                    {
                        vertexLines.Add(GetVertexes(fileReader, line, translationToMid, rotation, scale));
                    }
                    else if (line.StartsWith("l "))
                    {
                        lineLines.Add(GetLines(fileReader, line));
                    }
                    else if (line.StartsWith("f "))
                    {
                        faceLines.Add(GetFaces(fileReader, line));
                    }
                }
            }

            PointF3D[] vertexes;
            PolyLine[] polyLines;
            PolyLine[] faces;

            if (vertexLines.Count == 0)
            {
                vertexes = new PointF3D[0];
            }
            else
            {
                vertexes = vertexLines[0];
            }

            if (faceLines.Count == 0)
            {
                faces = new PolyLine[0];
            }
            else
            {
                faces = faceLines[0];
            }

            if (lineLines.Count == 0)
            {
                polyLines = new PolyLine[0];
            }
            else
            {
                polyLines = lineLines[0];
            }

            return(new Model(vertexes, polyLines, faces));
        }
コード例 #3
0
        public static PointF3D[] GetVertexes(StreamReader fileReader, string current, PointF3D translationToMid, PointF3D rotation, float scale)
        {
            List <PointF3D> returnList = new List <PointF3D>();
            var             line       = current;

            do
            {
                var      point  = line.Replace('.', ',').Split(' ');
                PointF3D vertex = null;
                try {
                    if (point[1] != "")
                    {
                        vertex = new PointF3D((float)Convert.ToDouble(point[1]), (float)Convert.ToDouble(point[2]), (float)Convert.ToDouble(point[3]));
                    }
                    else
                    {
                        vertex = new PointF3D((float)Convert.ToDouble(point[2]), (float)Convert.ToDouble(point[3]), (float)Convert.ToDouble(point[4]));
                    }
                } catch { continue; }

                //Translate it
                vertex += translationToMid;

                //Scale it
                vertex *= scale;

                //Rotate it
                vertex = Matrix.Rotate(rotation, vertex);

                returnList.Add(vertex);
                line = fileReader.ReadLine();
            } while (line.StartsWith("v "));

            return(returnList.ToArray());
        }
コード例 #4
0
        public void ScaleBy(PointF3D scaleBy)
        {
            //Edit translater
            scaler += scaleBy;

            //Calculate new points
            CalcNewPoints();
        }
コード例 #5
0
ファイル: Model.cs プロジェクト: Daxode/CueNET3DProjection
        public void Rotation(PointF3D rotation)
        {
            //Edit rotation
            this.rotation = rotation;

            //Calculate new points
            CalcNewPoints();
        }
コード例 #6
0
ファイル: Model.cs プロジェクト: Daxode/CueNET3DProjection
 private void Setup()
 {
     calc2DPoints = new PointF[vertexes.Length];
     rotation     = new PointF3D();
     translator   = new PointF3D();
     translator2D = new PointF();
     CalcNewPoints();
 }
コード例 #7
0
 //Constructor - With rotation
 public Model(PointF3D[] vertexes, PointF3D rotation)
 {
     Setup();
     this.vertexes = vertexes;
     this.rotation = rotation;
     calc2DPoints  = new PointF[vertexes.Length];
     CalcNewPoints();
 }
コード例 #8
0
ファイル: Model.cs プロジェクト: Daxode/CueNET3DProjection
        public void Translation(PointF3D translation)
        {
            //Edit translater
            this.translator = translation;

            //Calculate new points
            CalcNewPoints();
        }
コード例 #9
0
        public void Scaler(float scaler)
        {
            //Edit translater
            this.scaler = new PointF3D(scaler, scaler, scaler);

            //Calculate new points
            CalcNewPoints();
        }
コード例 #10
0
        public void TranslateBy(PointF3D translateBy)
        {
            //Edit translater
            translator += translateBy;

            //Calculate new points
            CalcNewPoints();
        }
コード例 #11
0
        public void Scaler(PointF3D scaler)
        {
            //Edit translater
            this.scaler = scaler;

            //Calculate new points
            CalcNewPoints();
        }
コード例 #12
0
        public void RotateBy(PointF3D rotateBy)
        {
            //Edit rotater
            rotation += rotateBy;

            //Calculate new points
            CalcNewPoints();
        }
コード例 #13
0
ファイル: Matrix.cs プロジェクト: Daxode/CueNET3DProjection
 public static float[,] ToMatrix(PointF3D p)
 {
     float[,] m = new float[3, 1];
     m[0, 0]    = p.x;
     m[1, 0]    = p.y;
     m[2, 0]    = p.z;
     return(m);
 }
コード例 #14
0
ファイル: Matrix.cs プロジェクト: Daxode/CueNET3DProjection
        public static PointF3D ToPoint3D(float[,] m)
        {
            var p = new PointF3D();

            p.x = m[0, 0];
            p.y = m[1, 0];
            p.z = m[2, 0];
            return(p);
        }
コード例 #15
0
 private void Setup()
 {
     rotation     = new PointF3D();
     translator   = new PointF3D();
     scaler       = new PointF3D(1, 1, 1);
     translator2D = new PointF();
     faces        = new PolyLine[0];
     polyLines    = new PolyLine[0];
 }
コード例 #16
0
ファイル: Model.cs プロジェクト: Daxode/CueNET3DProjection
        public void TranslateBy(PointF3D translateBy)
        {
            //Edit translater
            translator.x += translateBy.x;
            translator.y += translateBy.y;
            translator.z += translateBy.z;

            //Calculate new points
            CalcNewPoints();
        }
コード例 #17
0
ファイル: Matrix.cs プロジェクト: Daxode/CueNET3DProjection
        //Matrix projektion
        public static PointF Project(PointF3D vertex)
        {
            float[,] projectionM =
            {
                { 1, 0, 0 },
                { 0, 1, 0 }
            };

            return(Matrix.Multiply2D(projectionM, vertex));
        }
コード例 #18
0
ファイル: Model.cs プロジェクト: Daxode/CueNET3DProjection
        public void RotateBy(PointF3D rotateBy)
        {
            //Edit rotater
            rotation.x += rotateBy.x;
            rotation.y += rotateBy.y;
            rotation.z += rotateBy.z;

            //Calculate new points
            CalcNewPoints();
        }
コード例 #19
0
        public PointF CalcNewPoint(PointF3D vertex)
        {
            //Scale the vertex
            var Vertex = vertex * scaler;

            //Translate it
            Vertex = Vertex + translator;

            //Rotate it
            Vertex = Matrix.Rotate(rotation, Vertex);

            //Project it
            var point = Matrix.Project(Vertex);

            //Translate it
            return(new PointF(point.X + translator2D.X, point.Y + translator2D.Y));
        }
コード例 #20
0
ファイル: Model.cs プロジェクト: Daxode/CueNET3DProjection
        private void CalcNewPoints()
        {
            //For each vertex in model
            for (int i = 0; i < vertexes.Length; i++)
            {
                //Translate the vertex
                var Vertex = new PointF3D(vertexes[i].x + translator.x, vertexes[i].y + translator.y, vertexes[i].z + translator.z);

                //Rotate it
                Vertex = Matrix.Rotate(rotation, Vertex);

                //Project it
                var point = Matrix.Project(Vertex);

                //Add it to calc2DPoints
                calc2DPoints[i] = point;
            }
        }
コード例 #21
0
        //Matrix projektion
        public static PointF Project(PointF3D vertex)
        {
            float[,] cameraM =
            {
                { 1, 0, 0 },
                { 0, 1, 0 }
            };

            float[,] rotationM =
            {
                { 1, 0, 0 },
                { 0, 1, 0 }
            };

            float zee = 1f;

            float[,] projectionM =
            {
                { zee,   0, 0 },
                {   0, zee, 0 }
            };

            return(Matrix.Multiply2D(projectionM, vertex));
        }
コード例 #22
0
ファイル: Matrix.cs プロジェクト: Daxode/CueNET3DProjection
 public static PointF Multiply2D(float[,] a, PointF3D b)
 {
     return(ToPoint(Multiply(a, ToMatrix(b))));
 }
コード例 #23
0
ファイル: Matrix.cs プロジェクト: Daxode/CueNET3DProjection
 public static void Log(PointF3D p)
 {
     Log(ToMatrix(p));
 }
コード例 #24
0
ファイル: Model.cs プロジェクト: Daxode/CueNET3DProjection
 //Constructor - With rotation
 public Model(PointF3D[] vertexes, PointF3D rotation)
 {
     this.vertexes = vertexes;
     this.rotation = rotation;
     Setup();
 }