Example #1
0
        private void MapToSphere(Vector2 screenPoint, out Vector3 vector)
        {
            Vector2 deltaFromCenter = screenPoint - screenCenter;
            Vector2 deltaMinus1To1  = deltaFromCenter;

            //Adjust point coords and scale down to range of [-1 ... 1]
            deltaMinus1To1.x = (deltaMinus1To1.x / rotationTrackingRadius);
            deltaMinus1To1.y = (deltaMinus1To1.y / rotationTrackingRadius);

            //Compute square of the length of the vector from this point to the center
            double length = (deltaMinus1To1.x * deltaMinus1To1.x) + (deltaMinus1To1.y * deltaMinus1To1.y);

            //If the point is mapped outside the sphere... (length > radius squared)
            if (length > 1.0)
            {
                //Compute a normalizing factor (radius / sqrt(length))
                double normalizedLength = (1.0 / Math.Sqrt(length));

                //Return the "normalized" vector, a point on the sphere
                vector.x             = deltaMinus1To1.x * normalizedLength;
                vector.y             = deltaMinus1To1.y * normalizedLength;
                vector.z             = 0.0;
                lastMoveInsideRadius = false;
            }
            else             //Else it's inside
            {
                //Return a vector to a point mapped inside the sphere sqrt(radius squared - length)
                vector.x             = deltaMinus1To1.x;
                vector.y             = deltaMinus1To1.y;
                vector.z             = Math.Sqrt(1.0 - length);
                lastMoveInsideRadius = true;
            }

            vector = Vector3.TransformVector(vector, localToScreenTransform);
        }
Example #2
0
        public static Ray Transform(Ray ray, Matrix4X4 matrix)
        {
            Vector3 transformedOrigin   = Vector3.TransformPosition(ray.origin, matrix);
            Vector3 transformedDirecton = Vector3.TransformVector(ray.directionNormal, matrix);

            return(new Ray(transformedOrigin, transformedDirecton, ray.minDistanceToConsider, ray.maxDistanceToConsider, ray.intersectionType));
        }
Example #3
0
        public static Plane Transform(Plane inputPlane, Matrix4X4 matrix)
        {
            Vector3 planeNormal     = inputPlane.PlaneNormal;
            double  distanceToPlane = inputPlane.DistanceToPlaneFromOrigin;

            Plane outputPlane = new Plane();

            outputPlane.PlaneNormal = Vector3.TransformVector(planeNormal, matrix).GetNormal();
            Vector3 pointOnPlane            = planeNormal * distanceToPlane;
            Vector3 pointOnTransformedPlane = Vector3.Transform(pointOnPlane, matrix);

            outputPlane.DistanceToPlaneFromOrigin = Vector3.Dot(outputPlane.PlaneNormal, pointOnTransformedPlane);

            return(outputPlane);
        }