Пример #1
0
 private void GetWindowCoordinates(MCommonPrimitive shape)
 {
     foreach (MPoint point in shape.GetVertices())
     {
         TransformPointCoordsToDecart(point);
     }
 }
Пример #2
0
        private void RotateShape(MCommonPrimitive shape, double angle, Vector3 axis)
        {
            double rads = angle * Math.PI / 180.0;

            Quaternion rotationQuaternion = GetRotationQuaternion(axis, rads);

            shape.RotationQuaternion *= rotationQuaternion;
        }
Пример #3
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);
            }
        }
Пример #4
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;
            }
        }
Пример #5
0
        //------------------SCALING-------------------------------
        public void Scale(MCommonPrimitive shape, float sx, float sy, float sz)
        {
            float[,] scaleMatrix =
            {
                { sx,  0,  0, 0 },
                {  0, sy,  0, 0 },
                {  0,  0, sz, 0 },
                {  0,  0,  0, 1 }
            };

            shape.ModelMatrix = MatrixMultiplier.MultiplyMatrix(shape.ModelMatrix, scaleMatrix);
        }
Пример #6
0
        //------------------TRANSLATING-------------------------------
        public void Translate(MCommonPrimitive shape, float sx, float sy, float sz)
        {
            float[,] movementMatrix =
            {
                { 1, 0, 0, sx },
                { 0, 1, 0, sy },
                { 0, 0, 1, sz },
                { 0, 0, 0,  1 }
            };

            shape.ModelMatrix = MatrixMultiplier.MultiplyMatrix(movementMatrix, shape.ModelMatrix);
        }
Пример #7
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);
            }
        }
Пример #8
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;
            }
        }
Пример #9
0
        public void RotateY(MCommonPrimitive shape, double angle)
        {
            double rads = angle * Math.PI / 180.0;

            float[,] rotateY =
            {
                { (float)Math.Cos(rads),  0, (float)Math.Sin(rads), 0 },
                {                      0, 1,                     0, 0 },
                { -(float)Math.Sin(rads), 0, (float)Math.Cos(rads), 0 },
                {                      0, 0,                     0, 1 }
            };

            shape.ModelMatrix = MatrixMultiplier.MultiplyMatrix(shape.ModelMatrix, rotateY);
        }
Пример #10
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]);
            }
        }
Пример #11
0
        //public void Rotate(MCommonPrimitive shape, double sx, double sy, double sz)
        //{
        //    if (sx != 0)
        //        RotateX(shape, sx);

        //    if (sy != 0)
        //        RotateY(shape, sy);

        //    if (sz != 0)
        //        RotateZ(shape, sz);
        //}

        //public void RotateX(MCommonPrimitive shape, double angle)
        //{
        //    var axis = Vector3.UnitX;

        //    RotateShape(shape, angle, axis);
        //}

        //public void RotateY(MCommonPrimitive shape, double angle)
        //{
        //    var axis = Vector3.UnitY;

        //    RotateShape(shape, angle, axis);
        //}

        //public void RotateZ(MCommonPrimitive shape, double angle)
        //{
        //    var axis = Vector3.UnitZ;

        //    RotateShape(shape, angle, axis);
        //}

        //------------------ROTATING-------------------------------
        public void Rotate(MCommonPrimitive shape, double sx, double sy, double sz)
        {
            if (sx != 0)
            {
                RotateX(shape, sx);
            }

            if (sy != 0)
            {
                RotateY(shape, sy);
            }

            if (sz != 0)
            {
                RotateZ(shape, sz);
            }
        }
Пример #12
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]);
            //}
        }
Пример #13
0
 public void AddShape(MCommonPrimitive shape)
 {
     Shapes.Add(shape);
 }