Пример #1
0
        public override bool testIntersection()
        {
            if (mLocked)
            {
                return(true);
            }

            mXaxisSelected = mYaxisSelected = mZaxisSelected = false;

            //cast a ray
            //find what axis it's hitting..
            Point cursorPos = new Point();

            UIManager.GetCursorPos(ref cursorPos);
            Vector3 orig = BRenderDevice.getRayPosFromMouseCoords(false, cursorPos);
            Vector3 dir  = BRenderDevice.getRayPosFromMouseCoords(true, cursorPos) - orig;

            dir = BMathLib.Normalize(dir);

            //test intersection against our entire widget first
            BBoundingBox myBox = new BBoundingBox();

            myBox.min = mTranslation - (new Vector3(mRodWidth, mRodWidth, mRodWidth) * mVisibleScale.Y);
            myBox.max = mTranslation + (new Vector3(mRodLength + 0.5f, mRodLength + 0.5f, mRodLength + 0.5f) * mVisibleScale.Y);
            if (!myBox.intersect(orig, dir))
            {
                return(false);
            }

            //if we didn't hit a plane, check our boxes
            if (!testPlanesIntersection(orig, dir))
            {
                testRodsIntersection(orig, dir);
            }


            return(mXaxisSelected | mYaxisSelected | mZaxisSelected);
        }
Пример #2
0
        public override bool testIntersection()
        {
            if (mLocked)
            {
                return(true);
            }

            mXaxisSelected = mYaxisSelected = mZaxisSelected = false;

            //find what axis it's hitting..
            Point cursorPos = new Point();

            UIManager.GetCursorPos(ref cursorPos);
            Vector3 orig = BRenderDevice.getRayPosFromMouseCoords(false, cursorPos);
            Vector3 dir  = BRenderDevice.getRayPosFromMouseCoords(true, cursorPos) - orig;

            dir = BMathLib.Normalize(dir);

            //test intersection against our entire widget first
            float tVal = 0;

            if (!BMathLib.raySphereIntersect(mTranslation, mVisibleScale.Y, orig, dir, ref tVal))
            {
                return(false);
            }

            //we hit the sphere. Find out what axis we're interested in
            Vector3 pt = orig + (dir * tVal);

            Plane xPlane = Plane.FromPoints(mTranslation, mTranslation + new Vector3(0, 1, 0), mTranslation + new Vector3(0, 0, 1));
            Plane yPlane = Plane.FromPoints(mTranslation, mTranslation + new Vector3(1, 0, 0), mTranslation + new Vector3(0, 0, 1));
            Plane zPlane = Plane.FromPoints(mTranslation, mTranslation + new Vector3(1, 0, 0), mTranslation + new Vector3(0, 1, 0));

            float tol   = 0.35f * mVisibleScale.Y;
            float yDist = Math.Abs(BMathLib.pointPlaneDistance(pt, yPlane)); // < tol;
            float xDist = Math.Abs(BMathLib.pointPlaneDistance(pt, xPlane)); // < tol;
            float zDist = Math.Abs(BMathLib.pointPlaneDistance(pt, zPlane)); // < tol;

            mXaxisSelected = mYaxisSelected = mZaxisSelected = false;


            if (xDist < yDist && xDist < zDist)
            {
                mXaxisSelected = xDist < tol;
            }
            else if (yDist < xDist && yDist < zDist)
            {
                mYaxisSelected = yDist < tol;
            }
            else if (zDist < xDist && zDist < yDist)
            {
                mZaxisSelected = zDist < tol;
            }


            if (mYaxisSelected)
            {
                mXaxisSelected = mZaxisSelected = false;
            }
            if (mZaxisSelected)
            {
                mYaxisSelected = mXaxisSelected = false;
            }
            if (mXaxisSelected)
            {
                mYaxisSelected = mZaxisSelected = false;
            }

            return(mXaxisSelected | mYaxisSelected | mZaxisSelected);
        }