示例#1
0
 private void GetWindowCoordinates(MCommonPrimitive shape)
 {
     foreach (MPoint point in shape.GetVertices())
     {
         TransformPointCoordsToDecart(point);
     }
 }
示例#2
0
        private void GetNormalizedCoordinates(MCommonPrimitive shape)
        {
            List <MPoint> vertices = shape.GetVertices();

            for (int i = 0; i < vertices.Count; ++i)
            {
                float[,] newCoords = { { vertices[i].X / vertices[i].W }, { vertices[i].Y / vertices[i].W }, { vertices[i].Z / vertices[i].W }, { vertices[i].W } };

                SetNewCoordinatesToPoint(vertices[i], newCoords);
            }
        }
示例#3
0
        private void MoveShapeToPreviousPosition(MCommonPrimitive shape, MPoint previousShapeCenter)
        {
            var vertices = shape.GetVertices();

            for (int i = 0; i < vertices.Count; ++i)
            {
                vertices[i].X += previousShapeCenter.X;
                vertices[i].Y += previousShapeCenter.Y;
                vertices[i].Z += previousShapeCenter.Z;
            }
        }
示例#4
0
        private void GetClippedCoordinates(MCommonPrimitive shape, float[,] projectionMatrix)
        {
            List <MPoint> vertices = shape.GetVertices();

            for (int i = 0; i < vertices.Count; ++i)
            {
                float[,] vertexCoords = { { vertices[i].X }, { vertices[i].Y }, { vertices[i].Z }, { 1 } };

                float[,] newCoords = MatrixMultiplier.MultiplyMatrix(projectionMatrix, vertexCoords);

                SetNewCoordinatesToPoint(vertices[i], newCoords);
            }
        }
示例#5
0
        private void MoveShapeToOrigin(MCommonPrimitive shape, out MPoint shapeCenter)
        {
            var vertices = shape.GetVertices();

            shapeCenter = shape.GetCenterPoint();

            for (int i = 0; i < vertices.Count; ++i)
            {
                vertices[i].X -= shapeCenter.X;
                vertices[i].Y -= shapeCenter.Y;
                vertices[i].Z -= shapeCenter.Z;
            }
        }
示例#6
0
        private void TransformShape(MCommonPrimitive shape)
        {
            List <MPoint> vertices = shape.GetVertices();

            for (int i = 0; i < vertices.Count; ++i)
            {
                float[,] vertexCoords = { { vertices[i].SX }, { vertices[i].SY }, { vertices[i].SZ }, { 1 } };

                float[,] newCoords = MatrixMultiplier.MultiplyMatrix(shape.ModelMatrix, vertexCoords);

                SetNewCoordinatesToPoint(vertices[i], newCoords);

                ////TEST
                //TransformPointCoordsToDecart(vertices[i]);
            }
        }
示例#7
0
        public void GetTransformedShape(MCommonPrimitive shape, Camera camera)
        {
            var vertices = shape.GetVertices();

            for (int i = 0; i < vertices.Count; ++i)
            {
                float[,] vertexCoords = { { vertices[i].SX }, { vertices[i].SY }, { vertices[i].SZ }, { vertices[i].SW } };

                var modelViewMatrix = MatrixMultiplier.MultiplyMatrix(camera.ViewMatrix, shape.ModelMatrix);
                var eyeCoordinates  = MatrixMultiplier.MultiplyMatrix(modelViewMatrix, vertexCoords);
                var clipCoordinates = MatrixMultiplier.MultiplyMatrix(camera.ProjectionMatrix, eyeCoordinates);

                //if (clipCoordinates[0, 0] < -1 || clipCoordinates[0, 0] > 1 ||
                //    clipCoordinates[1, 0] < -1 || clipCoordinates[1, 0] > 1)
                //{
                //    vertices.RemoveAt(i);
                //    continue;
                //}

                var ndc = new float[, ] {
                    { clipCoordinates[0, 0] / clipCoordinates[3, 0] },
                    { clipCoordinates[1, 0] / clipCoordinates[3, 0] },
                    { clipCoordinates[2, 0] / clipCoordinates[3, 0] },
                    { clipCoordinates[3, 0] }
                };

                var windowCoordinates = new float[, ] {
                    { 640 / 2 * ndc[0, 0] + (640 / 2) },
                    { 360 / 2 * ndc[1, 0] + (360 / 2) },
                    { (50 - (-50)) / 2 * ndc[2, 0] + (50 + (-50)) / 2 },
                    { ndc[3, 0] }
                };

                SetNewCoordinatesToPoint(vertices[i], windowCoordinates);
            }

            //float[,]
            //    ,
            //    projectionModelViewMatrix = GetProjectionModelViewMatrix(camera.ProjectionMatrix, modelViewMatrix);

            //GetClippedCoordinates(shape, projectionModelViewMatrix);
            //GetNormalizedCoordinates(shape);
            //GetWindowCoordinates(shape);

            //float[,] modelView = MatrixMultiplier.MultiplyMatrix(camera.ViewMatrix, shape.ModelMatrix);
            //float[,] projModelView = MatrixMultiplier.MultiplyMatrix(camera.ProjectionMatrix, modelView);

            //for (int i = 0; i < projModelView.GetLength(0); ++i)
            //{
            //    for (int j = 0; j < projModelView.GetLength(1); ++j)
            //    {
            //        if (i != 3 && j != 3)
            //            projModelView[i, j] /= projModelView[3, 3];
            //    }
            //}

            //List<MPoint> vertices = shape.GetVertices();

            //for (int i = 0; i < vertices.Count; ++i)
            //{
            //    float[,] vertexCoords = { { vertices[i].SX }, { vertices[i].SY }, { vertices[i].SZ }, { vertices[i].SW } };

            //    float[,] newCoords = MatrixMultiplier.MultiplyMatrix(projModelView, vertexCoords);

            //    SetNewCoordinatesToPoint(vertices[i], newCoords);

            //    TransformPointCoordsToDecart(vertices[i]);
            //}
        }