Beispiel #1
0
        public void InteractiveFreeEdit(bool bAltAxes, int x, int y)
        {
            Entity entity = selectionmodel.GetFirstSelectedEntity();

            if (entity == null)
            {
                return;
            }

            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;
                }
            }

            double HalfWinWidth  = RendererFactory.GetInstance().WindowWidth / 2;
            double HalfWinHeight = RendererFactory.GetInstance().WindowHeight / 2;

            Vector3 translatevector = new Vector3();

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

            Vector3 PosChangeWorldAxes = translatevector * OurRot.Inverse();

            entity.pos = editing3d.startpos + PosChangeWorldAxes;
            MetaverseClient.GetInstance().worldstorage.OnModifyEntity(entity);
        }
Beispiel #2
0
        public void InitiateHandleEdit(int mousex, int mousey, Axis axis)
        {
            editing3d.EditingPreliminaries();

            Entity entity = selectionmodel.GetFirstSelectedEntity();

            if (entity != null)
            {
                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;
                    }
                }
                Rot rInverseOurRot = OurRot.Inverse();

                double fCurrentRotationAngle;

                editing3d.startpos    = entity.pos;
                editing3d.startrot    = entity.rot;
                fCurrentRotationAngle = GetRotationAngleForEntityAndMouse(editing3d.startpos, editing3d.startrot, axis, mousex, mousey);

                editing3d.iDragStartX = mousex;
                editing3d.iDragStartY = mousey;
                fStartRotationAngle   = fCurrentRotationAngle;
                Test.Debug("initializing StartRot " + editing3d.startrot.ToString() + " rotation angle " + fCurrentRotationAngle.ToString());     // Test.Debug

                editing3d.currentaxis     = axis;
                editing3d.currentedittype = Editing3d.EditType.RotHandle;
            }
        }
Beispiel #3
0
        public void InteractiveFreeEdit(int x, int y)
        {
            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;
                }
            }

            Rot rInverseOurRot = OurRot.Inverse();

            double HalfWinWidth  = RendererFactory.GetInstance().WindowWidth / 2;
            double HalfWinHeight = RendererFactory.GetInstance().WindowHeight / 2;

            double zRoll  = (x - editing3d.iDragStartX) / HalfWinWidth;
            double yRoll  = -(y - editing3d.iDragStartY) / HalfWinHeight;
            double amount = Math.Sqrt((double)((editing3d.iDragStartX - x) * (editing3d.iDragStartX - x) +
                                               (editing3d.iDragStartY - y) * (editing3d.iDragStartY - y))) * mvMath.Pi2 / HalfWinHeight;

            Vector3 ArcBallAxis = new Vector3(0, yRoll, zRoll);
            Rot     ArcBallRot  = mvMath.AxisAngle2Rot(ArcBallAxis, amount);

            Rot rTransposedToAv = rInverseOurRot * editing3d.startrot;
            Rot rRotated        = ArcBallRot * rTransposedToAv;
            Rot rNewRot         = OurRot * rRotated;

            selectionmodel.GetFirstSelectedEntity().rot = rNewRot;
            MetaverseClient.GetInstance().worldstorage.OnModifyEntity(selectionmodel.GetFirstSelectedEntity());
        }
Beispiel #4
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);
            }
        }