Esempio n. 1
0
        public void UnlinkChildren(EntityGroup group)
        {
            Vector3 ParentPos        = group.pos;
            Rot     ParentRot        = group.rot;
            Rot     InverseParentRot = ParentRot.Inverse();

            for (int i = 0; i < group.iNumSubEntities; i++)
            {
                Test.Debug("unlinking child " + group.SubEntities[i].ToString() +
                           " group pos " + group.pos.ToString()); // Test.Debug

                // Entity childentity = GetEntityByReference( group.SubEntityReferences[i] );
                Entity childentity = (Entity)group.SubEntities[i];

                Rot OldChildRot = childentity.rot;
                Rot NewChildRot = ParentRot * OldChildRot;

                Vector3 OldChildPos = childentity.pos;
                Vector3 GroupAxesVectorFromParentToChild  = OldChildPos;
                Vector3 GlobalAxesVectorFromParentToChild = GroupAxesVectorFromParentToChild * InverseParentRot;
                //MultiplyVectorByRot( GlobalAxesVectorFromParentToChild, InverseParentRot, GroupAxesVectorFromParentToChild );
                Vector3 NewChildPos = GlobalAxesVectorFromParentToChild + ParentPos;

                childentity.iParentReference = 0;
                childentity.pos = NewChildPos;
                childentity.rot = NewChildRot;
                Test.Debug("child after unlinking: " + childentity.pos.ToString() + " " + childentity.rot.ToString());    // Test.Debug

                group.SubEntities[i] = null;
            }
            group.iNumSubEntities = 0;
        }
Esempio n. 2
0
        // Maths description:
        //
        // take mousecoordinates, convert to 3d vector in screen coordinates
        // take object coordinates, convert to screen coordinates using OpenGL Feedback mode
        // now we have a vector, in screen coordinates, from the object to the mouse
        // convert this vector into OpenGL observer coordinates by dividing by the scaling factor from OpenGl.screen (see pos handles maths desscdription)
        //
        // now we imagine a line/ray running along our x-axis, in observer coordinates, through the point we we imagined the mouse clicked
        // we put the origin at the position of the object
        // we take the object axis according tot he handle we clicked on (XAXIS, YAXIS or ZAXIS) and multiple it by InverseEntityStartRot to convert from Entity coordinates into world coordinates
        // then we multiple by ObserverRot to convert into observer coordinates/axes
        // we normalize, which gives us the normal of a plane running through the origin perpendicular to the rotation axis, in observer coordinates
        // we use the maths from http://nehe.gamedev.net collision tutorial to intersect our mouseclick ray with this plane
        //
        // now we have a vector from the object to a point on the rotation plane
        // we multiply by EntityStartRot to move into object axes/coordinates
        // so the vector will now be in the x-y, x-z or y-z plane, depending on which handle we are dragging
        // we do a quick asin, trig according to which handle we are dragging,
        // and now we have the rotation angle
        //
        // when we first start dragging, we do this maths and store the start rotation angle
        // then we just find the difference between teh current rotation angle and the start one to get the rotation angle chnage
        // quick axisangle2rot and rotmultiply and now we have our new rot.

        public void InteractiveHandleEdit(Axis axis, int mousex, int mousey)
        {
            Entity entity = selectionmodel.GetFirstSelectedEntity();

            Vector3 OurPos;
            Rot     OurRot = null;

            if (camera.bRoamingCameraEnabled)
            {
                OurPos = camera.RoamingCameraPos;
                OurRot = camera.RoamingCameraRot;
            }
            else
            {
                Avatar ouravatar = MetaverseClient.GetInstance().myavatar;
                if (ouravatar != null)
                {
                    OurPos = ouravatar.pos;
                    OurRot = ouravatar.rot;
                }
            }
            Rot rInverseOurRot = OurRot.Inverse();

            if (entity != null)
            {
                double fCurrentRotationAngle = GetRotationAngleForEntityAndMouse(editing3d.startpos, editing3d.startrot, axis, mousex, mousey);
                double fRotateAngleChange    = fCurrentRotationAngle - fStartRotationAngle;
                // Test.Debug(  "Rotation angel change: " + fRotateAngleChange ); // Test.Debug

                Vector3 RotationAxisEntityAxes = axis.ToVector();

                Rot RotationChangeEntityAxes = mvMath.AxisAngle2Rot(RotationAxisEntityAxes, fRotateAngleChange);
                //Test.Debug(  " RotationChangeEntityAxes " + RotationChangeEntityAxes ); // Test.Debug

                Rot rInverseStartRot = editing3d.startrot.Inverse();

                Rot NewRotation = editing3d.startrot * RotationChangeEntityAxes;
                // Test.Debug(  " NewRotation " + NewRotation ); // Test.Debug

                //Test.Debug(  " NewRotation " + NewRotationWorldAxes ); // Test.Debug
                entity.rot = NewRotation;
                MetaverseClient.GetInstance().worldstorage.OnModifyEntity(entity);
            }
        }
Esempio n. 3
0
        //! Feedback line buffer for OpenGL feedback, used by mvgraphics.cpp

        /*
         * class FeedbackLineBufferItem
         * {
         *  public double type;
         *  public Vector2[] vertices = new Vector2[2];
         * }
         */

        public Vector3 GetMouseVector(Vector3 OurPos, Rot OurRot, int mousex, int mousey)
        {
            IRenderer renderer = RendererFactory.GetInstance();

            //Vector3 MouseVectorObserverAxes = new Vector3(-renderer.WindowWidth / 2 + mousex, -renderer.ScreenDistanceScreenCoords, renderer.WindowHeight / 2 - mousey);
            Vector3 MouseVectorObserverAxes = new Vector3(
                renderer.ScreenDistanceScreenCoords,
                renderer.WindowWidth / 2 - mousex,
                renderer.WindowHeight / 2 - mousey);

            //LogFile.WriteLine("MouseVectorObserverAxes: " + MouseVectorObserverAxes);
            MouseVectorObserverAxes.Normalize();
            //LogFile.WriteLine("MouseVectorObserverAxes (normalized): " + MouseVectorObserverAxes);
            Vector3 MouseVectorWorldAxes = MouseVectorObserverAxes * OurRot.Inverse();

            //LogFile.WriteLine("MouseVectorWorldAxes: " + MouseVectorWorldAxes.ToString());
            MouseVectorWorldAxes.Normalize();
            return(MouseVectorWorldAxes);
        }
Esempio n. 4
0
        // not to self: this is ugly, maybe simplify a little/lot?
        public Vector3 GetScreenPos(Vector3 ObserverPos, Rot ObserverRot, Vector3 TargetPos3D)
        {
            float[] feedbackbuffer = new float[1 * 3];

            Gl.glFeedbackBuffer(3, Gl.GL_2D, feedbackbuffer);

            int[] viewport = new int[4];
            // This Sets The Array <viewport> To The Size And Location Of The Screen Relative To The Window
            Gl.glGetIntegerv(Gl.GL_VIEWPORT, viewport);

            Gl.glPushMatrix();

            Gl.glRenderMode(Gl.GL_FEEDBACK);
            Gl.glLoadIdentity();

            // rotate so z axis is up, and x axis is forward
            Gl.glRotatef(90f, 0.0f, 0.0f, 1.0f);
            Gl.glRotatef(90f, 0.0f, 1.0f, 0.0f);

            Rotate(ObserverRot.Inverse());
            Translate(-ObserverPos);

            Gl.glBegin(Gl.GL_POINTS);
            Gl.glVertex3f((float)TargetPos3D.x, (float)TargetPos3D.y, (float)TargetPos3D.z);
            Gl.glEnd();

            Gl.glRenderMode(Gl.GL_RENDER);

            Gl.glPopMatrix();

            //DEBUG(  "Screencoords of input vertex: " << FeedbackBuffer.Vertices[0].x << " " << FeedbackBuffer.Vertices[0].y ); // DEBUG
            Vector2 screenpoint = GetFeedbackPointBufferItem(feedbackbuffer, 0);
            Vector3 ScreenPos   = new Vector3(
                0,
                RendererFactory.GetInstance().WindowWidth - screenpoint.x,
                screenpoint.y
                );

            //DEBUG(  "screenpos: " << ScreenPos ); // DEBUG

            return(ScreenPos);
        }
Esempio n. 5
0
        public void ApplyCamera()
        {
            UpdateCamera();

            // rotate so z axis is up, and x axis is forward

            PlayerMovement playermovement = PlayerMovement.GetInstance();

            GraphicsHelperGl g = new GraphicsHelperGl();

            g.Rotate(90, 0, 0, 1);
            g.Rotate(90, 0, 1, 0);

            Rot inversecamerarot = camerarot.Inverse();

            //inversecamerarot.Inverse();
            g.Rotate(inversecamerarot);
            //g.Rotate(camerarot);

            g.Translate(-camerapos);
        }
Esempio n. 6
0
        // not to self: this is ugly, maybe simplify a little/lot?
        public Vector3 GetScreenPos(Vector3 ObserverPos, Rot ObserverRot, Vector3 TargetPos3D)
        {
            float[] feedbackbuffer = new float[1 * 3];

            Gl.glFeedbackBuffer(3, Gl.GL_2D, feedbackbuffer);

            int[] viewport = new int[4];
            // This Sets The Array <viewport> To The Size And Location Of The Screen Relative To The Window
            Gl.glGetIntegerv(Gl.GL_VIEWPORT, viewport);

            Gl.glPushMatrix();

            Gl.glRenderMode(Gl.GL_FEEDBACK);
            Gl.glLoadIdentity();

            // rotate so z axis is up, and x axis is forward
            Gl.glRotatef(90f, 0.0f, 0.0f, 1.0f);
            Gl.glRotatef(90f, 0.0f, 1.0f, 0.0f);

            Rotate(ObserverRot.Inverse());
            Translate(-ObserverPos);

            Gl.glBegin(Gl.GL_POINTS);
            Gl.glVertex3f((float)TargetPos3D.x, (float)TargetPos3D.y, (float)TargetPos3D.z);
            Gl.glEnd();

            Gl.glRenderMode(Gl.GL_RENDER);

            Gl.glPopMatrix();

            //DEBUG(  "Screencoords of input vertex: " << FeedbackBuffer.Vertices[0].x << " " << FeedbackBuffer.Vertices[0].y ); // DEBUG
            Vector2 screenpoint = GetFeedbackPointBufferItem(feedbackbuffer, 0);
            Vector3 ScreenPos = new Vector3(
                0,
                RendererFactory.GetInstance().WindowWidth - screenpoint.x,
                screenpoint.y
            );

            //DEBUG(  "screenpos: " << ScreenPos ); // DEBUG

            return ScreenPos;
        }
Esempio n. 7
0
        //! Feedback line buffer for OpenGL feedback, used by mvgraphics.cpp
        /*
        class FeedbackLineBufferItem
        {
            public double type;
            public Vector2[] vertices = new Vector2[2];
        }
        */
        public Vector3 GetMouseVector(Vector3 OurPos, Rot OurRot, int mousex, int mousey)
        {
            IRenderer renderer = RendererFactory.GetInstance();

            //Vector3 MouseVectorObserverAxes = new Vector3(-renderer.WindowWidth / 2 + mousex, -renderer.ScreenDistanceScreenCoords, renderer.WindowHeight / 2 - mousey);
            Vector3 MouseVectorObserverAxes = new Vector3(
                renderer.ScreenDistanceScreenCoords,
                renderer.WindowWidth / 2 - mousex,
                renderer.WindowHeight / 2 - mousey);
            //LogFile.WriteLine("MouseVectorObserverAxes: " + MouseVectorObserverAxes);
            MouseVectorObserverAxes.Normalize();
            //LogFile.WriteLine("MouseVectorObserverAxes (normalized): " + MouseVectorObserverAxes);
            Vector3 MouseVectorWorldAxes = MouseVectorObserverAxes * OurRot.Inverse();
            //LogFile.WriteLine("MouseVectorWorldAxes: " + MouseVectorWorldAxes.ToString());
            MouseVectorWorldAxes.Normalize();
            return MouseVectorWorldAxes;
        }
Esempio n. 8
0
        public void _InteractiveFreeScaleEdit_Old(bool bAltAxes, int x, int y)
        {
            Vector3 OurPos = null;
            Rot     OurRot = null;

            if (camera.bRoamingCameraEnabled)
            {
                OurPos = camera.RoamingCameraPos;
                OurRot = camera.RoamingCameraRot;
            }
            else
            {
                Avatar ouravatar = MetaverseClient.GetInstance().myavatar;
                if (ouravatar != null)
                {
                    OurPos = ouravatar.pos;
                    OurRot = ouravatar.rot;
                }
                else
                {
                    return;
                }
            }

            Rot rInverseOurRot = OurRot.Inverse();

            Entity entity = selectionmodel.GetFirstSelectedEntity();

            // DEBUG(  "interactive scale edit objectype=[" << World.GetEntity( iSelectedArrayNum ).EntityType << "]" ); // DEBUG
            double HalfWinWidth  = RendererFactory.GetInstance().WindowWidth / 2;
            double HalfWinHeight = RendererFactory.GetInstance().WindowHeight / 2;

            Vector3 ScaleAvAxes = null;

            if (bAltAxes)
            {
                ScaleAvAxes = new Vector3(
                    -((double)(y - editing3d.iDragStartY)) / HalfWinWidth * 1.0,
                    ((double)(x - editing3d.iDragStartX)) / HalfWinWidth * 1.0,
                    0
                    );
            }
            else
            {
                ScaleAvAxes = new Vector3(
                    0,
                    ((double)(x - editing3d.iDragStartX)) / HalfWinWidth * 1.0,
                    -((double)(y - editing3d.iDragStartY)) / HalfWinWidth * 1.0
                    );
            }

            Vector3 CurrentScaleWorldAxes  = editing3d.startscale * entity.rot.Inverse();
            Vector3 CurrentScaleAvatarAxes = CurrentScaleWorldAxes * entity.rot;

            Vector3 ScaleNewScaleAvAxes = new Vector3(
                (1 + ScaleAvAxes.x) * CurrentScaleAvatarAxes.x,
                (1 + ScaleAvAxes.y) * CurrentScaleAvatarAxes.y,
                (1 + ScaleAvAxes.z) * CurrentScaleAvatarAxes.z
                );

            Vector3 NewScaleWorldAxes  = ScaleNewScaleAvAxes * rInverseOurRot;
            Vector3 NewScaleSeenByPrim = NewScaleWorldAxes * entity.rot;

            if (NewScaleSeenByPrim.x < 0)
            {
                NewScaleSeenByPrim.x = 0.05;
            }
            if (NewScaleSeenByPrim.y < 0)
            {
                NewScaleSeenByPrim.y = 0.05;
            }
            if (NewScaleSeenByPrim.z < 0)
            {
                NewScaleSeenByPrim.z = 0.05;
            }

            entity.scale = NewScaleSeenByPrim;
            // DEBUG(  "setting new scale " << NewScaleSeenByPrim ); // DEBUG
        }
Esempio n. 9
0
        public void InteractiveFreeEdit(int mousex, int mousey)
        {
            // DEBUG(  "InteractiveHandleScaleEdit" ); // DEBUG
            Entity entity = selectionmodel.GetFirstSelectedEntity();

            Vector3 OurPos = null;
            Rot     OurRot = null;

            if (camera.bRoamingCameraEnabled)
            {
                OurPos = camera.RoamingCameraPos;
                OurRot = camera.RoamingCameraRot;
            }
            else
            {
                Avatar ouravatar = MetaverseClient.GetInstance().myavatar;
                if (ouravatar != null)
                {
                    OurPos = ouravatar.pos;
                    OurRot = ouravatar.rot;
                }
                else
                {
                    return;
                }
            }

            if (entity != null)
            {
                double fDistanceFromUsToEntity = (entity.pos - OurPos).Det();
                double fScalingFromPosToScreen = graphics.GetScalingFrom3DToScreen(fDistanceFromUsToEntity);

                Vector3 ScreenMouseVector = new Vector3(
                    0,
                    -((double)(mousex - editing3d.iDragStartX)),
                    -((double)(mousey - editing3d.iDragStartY))
                    );

                Vector3 PosMouseVectorAvAxes = ScreenMouseVector * (1 / fScalingFromPosToScreen);

                Vector3 PosMouseVectorWorldAxes  = PosMouseVectorAvAxes * OurRot.Inverse();
                Vector3 PosMouseVectorEntityAxes = PosMouseVectorWorldAxes * entity.rot;
                //   DEBUG(  "screen vector: " << ScreenMouseVector << " PosMouseVectorAvAxes " << PosMouseVectorAvAxes <<
                //      " posmousevectorworldaxes: " << PosMouseVectorWorldAxes << " PosMouseVectorEntityAxes " << PosMouseVectorEntityAxes ); // DEBUG

                Vector3 vScaleChangeVectorEntityAxes = PosMouseVectorEntityAxes;
                Vector3 vNewScale = editing3d.startscale + vScaleChangeVectorEntityAxes;

                if (vNewScale.x < 0.05)
                {
                    vNewScale.x = 0.05;
                }
                else if (vNewScale.y < 0.05)
                {
                    vNewScale.y = 0.05;
                }
                else if (vNewScale.z < 0.05)
                {
                    vNewScale.z = 0.05;
                }

                //        Vector3 vTranslate;
                //        vTranslate = ( Vector3( vNewScale ) - Vector3( editing3d.startscale ) ) * 0.5f;
                entity.scale = vNewScale;
                MetaverseClient.GetInstance().worldstorage.OnModifyEntity(entity);
            }
            //   DEBUG(  "InteractiveHandleScaleEdit done" ); // DEBUG
        }
Esempio n. 10
0
        void SetupFrustrum()
        {
            //LogFile.WriteLine("setup frustrum");

            camerapos = Camera.GetInstance().CameraPos;
            camerarot = Camera.GetInstance().CameraRot;
            Rot inversecamerarot = camerarot.Inverse();
            //viewray = -mvMath.YAxis * inversecamerarot;
            //viewray.Normalize();
            //right = mvMath.XAxis * inversecamerarot;
            //up = mvMath.ZAxis * inversecamerarot;
            //right.Normalize();
            //up.Normalize();

            viewray = mvMath.XAxis * inversecamerarot;
            viewray.Normalize();
            right = - mvMath.YAxis * inversecamerarot;
            up = mvMath.ZAxis * inversecamerarot;
            right.Normalize();
            up.Normalize();

            nearclip = RendererFactory.GetInstance().NearClip;
            farclip = RendererFactory.GetInstance().FarClip;
            VNear = 2 * Math.Tan(RendererFactory.GetInstance().FieldOfView / 2 * Math.PI / 180) * nearclip;
            VFar = VNear * farclip / nearclip;
            HNear = VNear * (double)RendererFactory.GetInstance().OuterWindowWidth / RendererFactory.GetInstance().OuterWindowHeight;
            HFar = HNear * farclip / nearclip;

            //Console.WriteLine( "clips: " + nearclip + " " + farclip + " " + VNear + " " + VFar + " " + HNear + " " + HFar );

            fc = camerapos + viewray * farclip;
            ftl = fc + (up * VFar / 2) - (right * HFar / 2);
            ftr = fc + (up * VFar / 2) + (right * HFar / 2);
            fbl = fc - (up * VFar / 2) - (right * HFar / 2);
            fbr = fc - (up * VFar / 2) + (right * HFar / 2);

            nc = camerapos + viewray * nearclip;

            ntl = nc + (up * VNear / 2) - (right * HNear / 2);
            ntr = nc + (up * VNear / 2) + (right * HNear / 2);
            nbl = nc - (up * VNear / 2) - (right * HNear / 2);
            nbr = nc - (up * VNear / 2) + (right * HNear / 2);

            // note: all normals point outwards
            planes[0] = new Plane(-viewray, nc);
            planes[1] = new Plane(viewray, fc);

            Vector3 vectoralongplane;
            Vector3 normal;

            vectoralongplane = (ntr - camerapos).Normalize();
            normal = (up * vectoralongplane).Normalize();
            planes[2] = new Plane( - normal, camerapos);

            vectoralongplane = (nbr - camerapos).Normalize();
            normal = (right * vectoralongplane).Normalize();
            planes[3] = new Plane(- normal, camerapos);

            vectoralongplane = (nbl - camerapos).Normalize();
            normal = -(up * vectoralongplane).Normalize();
            planes[4] = new Plane(- normal, camerapos);

            vectoralongplane = (ntl - camerapos).Normalize();
            normal = -(right * vectoralongplane).Normalize();
            planes[5] = new Plane(- normal, camerapos);
        }
Esempio n. 11
0
        void SetupFrustrum()
        {
            //LogFile.WriteLine("setup frustrum");

            camerapos = Camera.GetInstance().CameraPos;
            camerarot = Camera.GetInstance().CameraRot;
            Rot inversecamerarot = camerarot.Inverse();

            //viewray = -mvMath.YAxis * inversecamerarot;
            //viewray.Normalize();
            //right = mvMath.XAxis * inversecamerarot;
            //up = mvMath.ZAxis * inversecamerarot;
            //right.Normalize();
            //up.Normalize();

            viewray = mvMath.XAxis * inversecamerarot;
            viewray.Normalize();
            right = -mvMath.YAxis * inversecamerarot;
            up    = mvMath.ZAxis * inversecamerarot;
            right.Normalize();
            up.Normalize();

            nearclip = RendererFactory.GetInstance().NearClip;
            farclip  = RendererFactory.GetInstance().FarClip;
            VNear    = 2 * Math.Tan(RendererFactory.GetInstance().FieldOfView / 2 * Math.PI / 180) * nearclip;
            VFar     = VNear * farclip / nearclip;
            HNear    = VNear * (double)RendererFactory.GetInstance().OuterWindowWidth / RendererFactory.GetInstance().OuterWindowHeight;
            HFar     = HNear * farclip / nearclip;

            //Console.WriteLine( "clips: " + nearclip + " " + farclip + " " + VNear + " " + VFar + " " + HNear + " " + HFar );

            fc  = camerapos + viewray * farclip;
            ftl = fc + (up * VFar / 2) - (right * HFar / 2);
            ftr = fc + (up * VFar / 2) + (right * HFar / 2);
            fbl = fc - (up * VFar / 2) - (right * HFar / 2);
            fbr = fc - (up * VFar / 2) + (right * HFar / 2);

            nc = camerapos + viewray * nearclip;

            ntl = nc + (up * VNear / 2) - (right * HNear / 2);
            ntr = nc + (up * VNear / 2) + (right * HNear / 2);
            nbl = nc - (up * VNear / 2) - (right * HNear / 2);
            nbr = nc - (up * VNear / 2) + (right * HNear / 2);

            // note: all normals point outwards
            planes[0] = new Plane(-viewray, nc);
            planes[1] = new Plane(viewray, fc);

            Vector3 vectoralongplane;
            Vector3 normal;

            vectoralongplane = (ntr - camerapos).Normalize();
            normal           = (up * vectoralongplane).Normalize();
            planes[2]        = new Plane(-normal, camerapos);

            vectoralongplane = (nbr - camerapos).Normalize();
            normal           = (right * vectoralongplane).Normalize();
            planes[3]        = new Plane(-normal, camerapos);

            vectoralongplane = (nbl - camerapos).Normalize();
            normal           = -(up * vectoralongplane).Normalize();
            planes[4]        = new Plane(-normal, camerapos);

            vectoralongplane = (ntl - camerapos).Normalize();
            normal           = -(right * vectoralongplane).Normalize();
            planes[5]        = new Plane(-normal, camerapos);
        }
Esempio n. 12
0
        double GetRotationAngleForEntityAndMouse(Vector3 EntityVector3, Rot EntityRot, Axis axis, int mousex, int mousey)
        {
            double fRotationAngle = 0;

            bool bRotAngleGot = false;

            Vector3 OurPos;
            Rot     OurRot;

            if (camera.bRoamingCameraEnabled)
            {
                OurPos = camera.RoamingCameraPos;
                OurRot = camera.RoamingCameraRot;
            }
            else
            {
                Avatar ouravatar = MetaverseClient.GetInstance().myavatar;
                if (ouravatar != null)
                {
                    OurPos = ouravatar.pos;
                    OurRot = ouravatar.rot;
                }
                else
                {
                    return(0);
                }
            }
            Rot rInverseOurRot = OurRot.Inverse();

            double fDistanceFromUsToEntity = (EntityVector3 - OurPos).Det();
            double fScalingFromPosToScreen = graphics.GetScalingFrom3DToScreen(fDistanceFromUsToEntity);

            Vector3 ScreenEntityPos = graphics.GetScreenPos(OurPos, OurRot, EntityVector3);
            Vector3 ScreenMousePos  = new Vector3(
                0,
                RendererFactory.GetInstance().WindowWidth - mousex,
                RendererFactory.GetInstance().WindowHeight - mousey);

            // mousepoint is a point on the mouseray into the screen, with x = entity.pos.x
            Vector3 ScreenVectorEntityToMousePoint       = ScreenMousePos - ScreenEntityPos;
            Vector3 VectorEntityToMousePointObserverAxes = ScreenVectorEntityToMousePoint * (1.0f / fScalingFromPosToScreen);

            //Test.Debug(  " screenobjectpos: " + ScreenEntityPos + " screenmousepos: " + ScreenMousePos + " objecttomouse: " + ScreenVectorEntityToMouse ); // Test.Debug

            Vector3 RotationAxisEntityAxes = axis.ToVector();
            Rot     rInverseEntityRot      = EntityRot.Inverse();

            Vector3 RotationAxisWorldAxes = RotationAxisEntityAxes * rInverseEntityRot;
            //    Test.Debug(  " RotationAxisWorldAxes " + RotationAxisWorldAxes ); // Test.Debug

            Vector3 RotationAxisObserverAxes = RotationAxisWorldAxes * OurRot;

            RotationAxisObserverAxes.Normalize();

            double DistanceOfRotationPlaneFromOrigin = 0; // Lets move right up to the object
            // we're going to imagine a ray from the MousePoint going down the XAXIS, away from us
            // we'll intersect this ray with the rotation plane to get the point on the rotation plane
            // where we can consider the mouse to be.
            double fVectorDotRotationAxisObserverAxesWithXAxis = Vector3.DotProduct(RotationAxisObserverAxes, mvMath.XAxis);

            if (Math.Abs(fVectorDotRotationAxisObserverAxesWithXAxis) > 0.0005)
            {
                double fDistanceFromMousePointToRotationPlane = (DistanceOfRotationPlaneFromOrigin -
                                                                 Vector3.DotProduct(RotationAxisObserverAxes, VectorEntityToMousePointObserverAxes))
                                                                / fVectorDotRotationAxisObserverAxesWithXAxis;
                //  Test.Debug(  " fDistanceFromMousePointToRotationPlane " + fDistanceFromMousePointToRotationPlane ); // Test.Debug

                Vector3 VectorMouseClickOnRotationPlaneObserverAxes = new Vector3(
                    fDistanceFromMousePointToRotationPlane,
                    VectorEntityToMousePointObserverAxes.y,
                    VectorEntityToMousePointObserverAxes.z);
                //    Test.Debug(  " VectorMouseClickOnRotationPlaneObserverAxes " + VectorMouseClickOnRotationPlaneObserverAxes ); // Test.Debug
                // We'll rotate this vector into object axes

                Vector3 VectorMouseClickOnRotationPlaneWorldAxes  = VectorMouseClickOnRotationPlaneObserverAxes * rInverseOurRot;
                Vector3 VectorMouseClickOnRotationPlaneEntityAxes = VectorMouseClickOnRotationPlaneWorldAxes * EntityRot;
                //     Test.Debug(  " VectorMouseClickOnRotationPlaneEntityAxes " + VectorMouseClickOnRotationPlaneEntityAxes ); // Test.Debug

                // now we work out rotation angle
                double fDistanceOfPointFromOrigin;
                if (axis.IsXAxis)
                {
                    fDistanceOfPointFromOrigin = Math.Sqrt(VectorMouseClickOnRotationPlaneEntityAxes.z * VectorMouseClickOnRotationPlaneEntityAxes.z
                                                           + VectorMouseClickOnRotationPlaneEntityAxes.y * VectorMouseClickOnRotationPlaneEntityAxes.y);
                    //         Test.Debug(  "Z axis distnace of point from origin: " + fDistanceOfPointFromOrigin ); // Test.Debug

                    if (Math.Abs(fDistanceOfPointFromOrigin) > 0.0005)
                    {
                        fRotationAngle = -Math.Asin(VectorMouseClickOnRotationPlaneEntityAxes.y / fDistanceOfPointFromOrigin);
                        if (VectorMouseClickOnRotationPlaneEntityAxes.z < 0)
                        {
                            fRotationAngle = mvMath.Pi - fRotationAngle;
                        }
                        //             Test.Debug(  "************RotANGLE: " + fRotationAngle ); // Test.Debug
                        bRotAngleGot = true;
                    }
                }
                else if (axis.IsYAxis)
                {
                    fDistanceOfPointFromOrigin = Math.Sqrt(VectorMouseClickOnRotationPlaneEntityAxes.z * VectorMouseClickOnRotationPlaneEntityAxes.z
                                                           + VectorMouseClickOnRotationPlaneEntityAxes.x * VectorMouseClickOnRotationPlaneEntityAxes.x);
                    //         Test.Debug(  "Z axis distnace of point from origin: " + fDistanceOfPointFromOrigin ); // Test.Debug

                    if (Math.Abs(fDistanceOfPointFromOrigin) > 0.0005)
                    {
                        fRotationAngle = Math.Asin(VectorMouseClickOnRotationPlaneEntityAxes.x / fDistanceOfPointFromOrigin);
                        if (VectorMouseClickOnRotationPlaneEntityAxes.z < 0)
                        {
                            fRotationAngle = mvMath.Pi - fRotationAngle;
                        }
                        //             Test.Debug(  "************RotANGLE: " + fRotationAngle ); // Test.Debug
                        bRotAngleGot = true;
                    }
                }
                else
                {
                    fDistanceOfPointFromOrigin = Math.Sqrt(VectorMouseClickOnRotationPlaneEntityAxes.x * VectorMouseClickOnRotationPlaneEntityAxes.x
                                                           + VectorMouseClickOnRotationPlaneEntityAxes.y * VectorMouseClickOnRotationPlaneEntityAxes.y);
                    //         Test.Debug(  "Z axis distnace of point from origin: " + fDistanceOfPointFromOrigin ); // Test.Debug

                    if (Math.Abs(fDistanceOfPointFromOrigin) > 0.0005)
                    {
                        fRotationAngle = Math.Asin(VectorMouseClickOnRotationPlaneEntityAxes.y / fDistanceOfPointFromOrigin);
                        if (VectorMouseClickOnRotationPlaneEntityAxes.x < 0)
                        {
                            fRotationAngle = mvMath.Pi - fRotationAngle;
                        }
                        //             Test.Debug(  "************RotANGLE: " + fRotationAngle ); // Test.Debug
                        bRotAngleGot = true;
                    }
                }
            }

            if (bRotAngleGot)
            {
                //fRotationAngle = fRotAngle;
                return(fRotationAngle);
            }
            else
            {
                return(0);
            }
        }