Пример #1
0
        void LoadHeightMap(string sm3directory, TdfParser.Section terrainsection)
        {
            TerrainModel terrainmodel = MetaverseClient.GetInstance().worldstorage.terrainmodel;

            string filename     = Path.Combine(sm3directory, terrainsection.GetStringValue("heightmap"));
            double heightoffset = terrainsection.GetDoubleValue("heightoffset");
            double heightscale  = terrainsection.GetDoubleValue("heightscale");

            LogFile.WriteLine("heightoffset: " + heightoffset + " heightscale " + heightscale);
            terrainmodel.MinHeight = heightoffset;
            terrainmodel.MaxHeight = heightoffset + heightscale; // I guess???

            ImageWrapper image = new ImageWrapper(filename);
            //Bitmap bitmap = DevIL.DevIL.LoadBitmap(filename);
            int width  = image.Width;
            int height = image.Height;

            terrainmodel.HeightMapWidth  = width;
            terrainmodel.HeightMapHeight = height;
            terrainmodel.Map             = new double[width, height];
            LogFile.WriteLine("loaded bitmap " + width + " x " + height);
            double minheight        = terrainmodel.MinHeight;
            double maxheight        = terrainmodel.MaxHeight;
            double heightmultiplier = (maxheight - minheight) / 255;

            LogFile.WriteLine("heightmultiplier: " + heightmultiplier + " minheight: " + minheight);
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    terrainmodel.Map[i, j] =
                        (float)(minheight + heightmultiplier *
                                image.GetBlue(i, j));
                }
            }
            terrain.HeightmapFilename = filename;
        }
Пример #2
0
 public bool IsPartOfAvatar(Entity entity)
 {
     //   Test.Debug(  "IsPartOfAvatar() " + entity.ToString() ); // Test.Debug
     // Entity entity = worldstorage.entities[ iarrayreference ];
     if (entity != null)
     {
         //Test.Debug(  "object type: " + p_Object.sDeepObjectType.ToString() + " " + p_Object.iReference.ToString() + " parentref: " + p_Object.iParentReference.ToString() ); // Test.Debug;
         if (entity.Parent == null)
         {
             // Test.Debug(  "IsPartOfAvatar() doing comparison " + ( entity == MetaverseClient.GetInstance().iMyReference ).ToString() + " " + entity.iReference.ToString() + " " + MetaverseClient.GetInstance().iMyReference.ToString() );
             return(entity == MetaverseClient.GetInstance().myavatar);
         }
         else
         {
             //    Test.Debug(  "IsPartOfAvatar() looking up parent " + entity.Parent.ToString() ); // Test.Debug
             return(IsPartOfAvatar(entity.Parent));
         }
     }
     else
     {
         Test.Debug("no object found!");    // Test.Debug
         return(false);
     }
 }
Пример #3
0
        //! Draws all non-hardcoded objects in world - including avatars - into the 3D world of OpenGL
        void DrawEntities()
        {
            //Test.Debug("drawobjects");
            Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_AMBIENT_AND_DIFFUSE, new float[] { 1.0f, 0.0f, 0.5f, 1.0f });

            Gl.glEnable(Gl.GL_TEXTURE_2D);

            Avatar myavatar = MetaverseClient.GetInstance().myavatar;

            Picker3dController picker3dcontroller = Picker3dController.GetInstance();

            for (int i = 0; i < worldmodel.entities.Count; i++)
            {
                if (worldmodel.entities[i].iParentReference == 0)
                {
                    // dont draw own avatar in mouselook mode
                    if (worldmodel.entities[i] != myavatar)
                    {
                        //LogFile.WriteLine("render entity " + i);
                        Gl.glRasterPos3f((float)worldmodel.entities[i].pos.x, (float)worldmodel.entities[i].pos.y, (float)worldmodel.entities[i].pos.z);
                        picker3dcontroller.AddHitTarget(worldmodel.entities[i]);
                        worldmodel.entities[i].Draw();
                        picker3dcontroller.EndHitTarget();
                        graphics.Bind2DTexture(0);
                    }
                    else
                    {
                        Gl.glRasterPos3f((float)worldmodel.entities[i].pos.x, (float)worldmodel.entities[i].pos.y, (float)worldmodel.entities[i].pos.z);
                        picker3dcontroller.AddHitTarget(worldmodel.entities[i]);
                        worldmodel.entities[i].Draw();
                        picker3dcontroller.EndHitTarget();
                        graphics.Bind2DTexture(0);
                    }
                }
            }
        }
Пример #4
0
        public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentrex, double brushcentrey, bool israising, double milliseconds)
        {
            if (heightscale == null)
            {
                return;
            }
            double targetheight = heightscale.Value;

            Console.WriteLine("height scale value: " + targetheight);
            int x = (int)(brushcentrex);
            int y = (int)(brushcentrey);

            for (int i = -brushsize; i <= brushsize; i++)
            {
                for (int j = -brushsize; j <= brushsize; j++)
                {
                    double brushcontribution = brushshape.GetStrength(
                        (double)i / brushsize, (double)j / brushsize);
                    if (brushcontribution > 0)
                    {
                        int thisx = x + i;
                        int thisy = y + j;
                        if (thisx >= 0 && thisy >= 0 &&
                            thisx < MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightMapWidth&&
                            thisy < MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightMapHeight)
                        {
                            double oldheight = MetaverseClient.GetInstance().worldstorage.terrainmodel.Map[thisx, thisy];
                            double newheight = oldheight + (targetheight - oldheight) *
                                               speed * milliseconds / 50 * brushcontribution;
                            MetaverseClient.GetInstance().worldstorage.terrainmodel.Map[thisx, thisy] = newheight;
                        }
                    }
                }
            }
            MetaverseClient.GetInstance().worldstorage.terrainmodel.OnHeightMapInPlaceEdited(x - brushsize, y - brushsize, x + brushsize, y + brushsize);
        }
Пример #5
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
        }
 public void ObjectDeleted(int reference, string typename)
 {
     MetaverseClient.GetInstance().netreplicationcontroller.ObjectDeletedRpc(connection,
                                                                             reference, typename);
 }
Пример #7
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
        }
 public void ObjectCreatedServerToCreatorClient(int clientreference, int globalreference)
 {
     MetaverseClient.GetInstance().netreplicationcontroller.ObjectCreatedRpcServerToCreatorClient(connection,
                                                                                                  clientreference, globalreference);
 }
 public void ObjectModified(int reference, string typename, int attributebitmap, byte[] entity)
 {
     MetaverseClient.GetInstance().netreplicationcontroller.ObjectModifiedRpc(connection,
                                                                              reference, typename, attributebitmap, entity);
 }
Пример #10
0
 void STUNResponseForOwnInterface( IPAddress ipaddress, int port )
 {
     LogFile.WriteLine( "showserverdialog.STUNResponseForOwnInterface( " + ipaddress + " " + port + " )" );
     MetaverseClient.GetInstance().imimplementation.SendPrivateMessage( servername,
         XmlCommands.GetInstance().Encode( new XmlCommands.PingMe( ipaddress, port ) ) );
 }
Пример #11
0
 public TextureController()
 {
     Il.ilInit();
     MetaverseClient.GetInstance().Tick += new MetaverseClient.TickHandler(TextureController_Tick);
 }
Пример #12
0
        // see description of function by same name in Editing3dPos
        public void InteractiveHandleEdit(Axis axis, int mousex, int mousey)
        {
            Entity entity = selectionmodel.GetFirstSelectedEntity();

            if (entity == null)
            {
                return;
            }

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

            // what is the scaling from screen pixels to world pixels, at the distance of the object from us
            // obviously this is only approximate for nearish objects, which is most objects...
            double fDistanceFromUsToObject = (entity.pos - ourpos).Det();
            double fScalingFromPosToScreen = graphics.GetScalingFrom3DToScreen(fDistanceFromUsToObject);

            // Create a 3d vector represeting our mouse drag, in avatar coordinates, in screen pixels
            Vector3 mousemovescreenaxes = new Vector3(0,
                                                      -(double)(mousex - editing3d.iDragStartX),
                                                      -(double)(mousey - editing3d.iDragStartY));

            // transform into a 3d vector, in avatar coordinates, in "world units"
            Vector3 mousemoveavaxes = mousemovescreenaxes * (1 / fScalingFromPosToScreen);

            // Get handleaxis in avatar axes:
            Vector3 handleaxisentityaxes = axis.ToVector();

            handleaxisentityaxes.x = Math.Abs(handleaxisentityaxes.x);
            handleaxisentityaxes.y = Math.Abs(handleaxisentityaxes.y);
            handleaxisentityaxes.z = Math.Abs(handleaxisentityaxes.z);
            Vector3 handleaxisworldaxes = handleaxisentityaxes * entity.rot.Inverse();
            Vector3 handleaxisavaxes    = handleaxisworldaxes * ourrot;

            // we project our handleaxis onto the screen, then project our mousemove onto this
            // to get mousemove2 (see function description for more info)
            Vector3 handleaxisprojectedtoscreen = new Vector3(0, handleaxisavaxes.y, handleaxisavaxes.z);
            Vector3 mousemove2 = handleaxisprojectedtoscreen.Unit() * Vector3.DotProduct(mousemoveavaxes, handleaxisprojectedtoscreen.Unit());

            // now we are going to find the ratio between our mousemovement size and how far we need to move along the handleaxis
            double entitymovetomousemoveratio = Vector3.DotProduct(handleaxisavaxes.Unit(), mousemove2.Unit());

            // This gives us the ratio between mouse move distance and entity move distance, now we can calculate the change in entity scale:

            if (Math.Abs(entitymovetomousemoveratio) < 0.05)    // prevent infinite scaling..
            {
                return;
            }
            Vector3 scalechange = (mousemove2.Det() / entitymovetomousemoveratio) * handleaxisentityaxes;
            Vector3 newscale    = null;

            if (axis.IsPositiveAxis)
            {
                newscale = editing3d.startscale + scalechange;
            }
            else
            {
                newscale = editing3d.startscale - scalechange;
            }
            newscale.x = Math.Max(0.05, newscale.x);
            newscale.y = Math.Max(0.05, newscale.y);
            newscale.z = Math.Max(0.05, newscale.z);

            Vector3 finalscalechange          = newscale - editing3d.startscale;
            Vector3 finalscalechangeworldaxes = finalscalechange * entity.rot.Inverse();

            if (axis.IsPositiveAxis)
            {
                entity.pos = editing3d.startpos + (finalscalechangeworldaxes) / 2;
            }
            else
            {
                entity.pos = editing3d.startpos - (finalscalechangeworldaxes) / 2;
            }

            // scale is defined in entity local axes, so no need to transform into world axes
            entity.scale = newscale;
            MetaverseClient.GetInstance().worldstorage.OnModifyEntity(entity);
        }
Пример #13
0
 public UserChatDialog()
 {
     imimplementation = MetaverseClient.GetInstance().imimplementation;
     logindialog      = new LoginDialog(this);
     //Login( "hugh", "" );
 }
Пример #14
0
 public void Show()
 {
     MetaverseClient.GetInstance().imimplementation.GetUserList( new WhoCallback( ShowServersCallback ) );
     //ShowServersCallback( new string[] { "srv_antartic", "srv_iceland" } );
 }
Пример #15
0
 public Sm3Persistence()
 {
     terrain = MetaverseClient.GetInstance().worldstorage.terrainmodel;
 }
Пример #16
0
        public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentrex, double brushcentrey, bool israising, double milliseconds)
        {
            if (thistexture != null && maptexturestage != null)
            {
                double timemultiplier = milliseconds * speed;

                double directionmultiplier = 1.0;
                if (!israising)
                {
                    directionmultiplier = -1.0;
                }

                int mapx               = (int)(brushcentrex);
                int mapy               = (int)(brushcentrey);
                int mapwidth           = MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightMapWidth - 1;
                int mapheight          = MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightMapHeight - 1;
                int texturex           = (int)(texturewidth * mapx / mapwidth);
                int texturey           = (int)(textureheight * mapy / mapheight);
                int texturebrushwidth  = (int)(texturewidth * brushsize / mapwidth);
                int texturebrushheight = (int)(textureheight * brushsize / mapheight);
                for (int i = -texturebrushwidth; i <= texturebrushwidth; i++)
                {
                    for (int j = -texturebrushheight; j <= texturebrushheight; j++)
                    {
                        double brushshapecontribution = brushshape.GetStrength((double)i / texturebrushwidth,
                                                                               (double)j / texturebrushheight);
                        if (brushshapecontribution > 0)
                        {
                            int thisx = texturex + i;
                            int thisy = texturey + j;
                            //      Console.WriteLine(thisx + " " + thisy);
                            if (thisx >= 0 && thisy >= 0 && thisx < texturewidth &&
                                thisy < textureheight)
                            {
                                // we update our double array then set the int array iwthin ITexture itself
                                //LogFile.WriteLine( speed + " " + directionmultiplier + " " + timemultiplier + " " + brushshapecontribution );
                                alphadata[thisx, thisy] += speed * directionmultiplier * timemultiplier * brushshapecontribution;
                                if (alphadata[thisx, thisy] >= 255)
                                {
                                    alphadata[thisx, thisy] = 255;
                                }
                                else if (alphadata[thisx, thisy] < 0)
                                {
                                    alphadata[thisx, thisy] = 0;
                                }
                                thistexture.SetPixel(thisx, thisy, (byte)alphadata[thisx, thisy], (byte)alphadata[thisx, thisy], (byte)alphadata[thisx, thisy], 255);
                                //LogFile.WriteLine( "setting pixel " + thisx + " " + thisy + " to " + (byte)alphadata[thisx, thisy] );
                                //thistexture.AlphaData[thisx, thisy] = (byte)alphadata[thisx, thisy];
                                //  Console.WriteLine(thisx + " " + thisy + " " + (byte)alphadata[thisx, thisy]);
                            }
                        }
                    }
                }

                thistexture.Save("editedblend.jpg");

                //thistexture.ReloadAlpha();
                maptexturestage.onChanged();
                //thistexture.Modified = true;
                MetaverseClient.GetInstance().worldstorage.terrainmodel.OnBlendMapInPlaceEdited(maptexturestage, mapx - brushsize, mapy - brushsize, mapx + brushsize, mapy + brushsize);
            }
        }
Пример #17
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);
            }
        }
Пример #18
0
        public void MovePlayer()
        {
            double fRight   = 0.0;
            double fUp      = 0.0;
            double fForward = 0.0;

            if (kMovingLeft)
            {
                fRight      -= 1.0;
                bAvatarMoved = true;
            }
            if (kMovingRight)
            {
                fRight      += 1.0;
                bAvatarMoved = true;
            }
            if (kMovingForwards)
            {
                bAvatarMoved = true;
                fForward    += 1.0;
            }
            if (kMovingBackwards)
            {
                fForward    -= 1.0;
                bAvatarMoved = true;
            }
            if (kMovingUpZAxis)
            {
                fUp         += 1.0;
                bAvatarMoved = true;
            }
            if (kMovingDownZAxis)
            {
                fUp         -= 1.0;
                bAvatarMoved = true;
            }

            double fTimeSlotMultiplier = (double)timekeeper.ElapsedTime / 100; // PLACEHOLDER

            if (bAvatarMoved)
            {
                switch (camera.viewpoint)
                {
                case Camera.Viewpoint.MouseLook:
                    //case Camera.Viewpoint.BehindPlayer:
                    Vector3 accelerationavaxes          = new Vector3(fForward, -fRight, 0) * fTimeSlotMultiplier * fAvatarAcceleration;
                    Vector3 accelerationvectorworldaxes = accelerationavaxes * MetaverseClient.GetInstance().myavatar.rot.Inverse();

                    accelerationvectorworldaxes.z = fUp * fAvatarAcceleration * fTimeSlotMultiplier;

                    currentvelocity   = currentvelocity / (1 + fTimeSlotMultiplier * fDeceleration) + accelerationvectorworldaxes;
                    currentvelocity.x = Math.Max(Math.Min(currentvelocity.x, fAvatarMoveSpeed), -fAvatarMoveSpeed);
                    currentvelocity.y = Math.Max(Math.Min(currentvelocity.y, fAvatarMoveSpeed), -fAvatarMoveSpeed);
                    currentvelocity.z = Math.Max(Math.Min(currentvelocity.z, fVerticalMoveSpeed), -fVerticalMoveSpeed);

                    avatarpos = avatarpos + currentvelocity * fTimeSlotMultiplier;

                    avatarpos.x = Math.Max(avatarpos.x, WorldBoundingBoxMin.x);
                    avatarpos.y = Math.Max(avatarpos.y, WorldBoundingBoxMin.y);
                    avatarpos.z = Math.Max(avatarpos.z, WorldBoundingBoxMin.z);

                    avatarpos.x = Math.Min(avatarpos.x, WorldBoundingBoxMax.x);
                    avatarpos.y = Math.Min(avatarpos.y, WorldBoundingBoxMax.y);
                    avatarpos.z = Math.Min(avatarpos.z, WorldBoundingBoxMax.z);

                    avatarpos.z = Math.Max(avatarpos.z, MetaverseClient.GetInstance().worldstorage.terrainmodel.Map[
                                               (int)avatarpos.x, (int)avatarpos.y] + avatarradius);

                    break;

                    //case Camera.Viewpoint.ThirdParty:
                    //  camera.fThirdPartyViewZoom += fForward;
                    //camera.fThirdPartyViewRotate += fRight * 3.0;
                    //break;
                }
                UpdateAvatarObjectRotAndPos();
            }
        }
Пример #19
0
 public QueryServer()
 {
     chat    = MetaverseClient.GetInstance().imimplementation;
     handler = new IMReceivedHandler(imimplementation_IMReceived);
 }
Пример #20
0
 public FixedHeight()
 {
     speed = Config.GetInstance().HeightEditingSpeed;
     MetaverseClient.GetInstance().worldstorage.terrainmodel.TerrainModified += new TerrainModel.TerrainModifiedHandler(FixedHeight_TerrainModified);
 }
Пример #21
0
 public void DeleteClick(object source, ContextMenuArgs e)
 {
     MetaverseClient.GetInstance().worldstorage.DeleteEntity(entity);
 }
Пример #22
0
        // note to self: move this to subscriber?
        void DrawMinimap()
        {
            TerrainModel terrain = MetaverseClient.GetInstance().worldstorage.terrainmodel;

            if (DateTime.Now.Subtract(LastMinimapUpdate).TotalMilliseconds > 1000)
            //if( true )
            {
                List <RendererPass> rendererpasses = new List <RendererPass>();
                bool multipass = true; // force multipass for now for simplicity
                int  maxtexels = RendererSdl.GetInstance().MaxTexelUnits;
                if (multipass)
                {
                    for (int i = 0; i < terrain.texturestages.Count; i++)
                    {
                        MapTextureStageModel maptexturestage = terrain.texturestages[i];
                        int numtexturestagesrequired         = maptexturestage.NumTextureStagesRequired;
                        if (numtexturestagesrequired > 0) // exclude Nops
                        {
                            RendererPass rendererpass = new RendererPass(maxtexels);
                            for (int j = 0; j < maptexturestage.NumTextureStagesRequired; j++)
                            {
                                rendererpass.AddStage(new RendererTextureStage(maptexturestage, j, true, mapwidth, mapheight));
                            }
                            rendererpasses.Add(rendererpass);
                        }
                    }
                }

                GraphicsHelperGl g = new GraphicsHelperGl();

                //g.ApplyOrtho(windowwidth, windowheight, RendererSdl.GetInstance().OuterWindowWidth, RendererSdl.GetInstance().OuterWindowHeight);

                g.EnableBlendSrcAlpha();
                Gl.glDepthFunc(Gl.GL_LEQUAL);

                int chunkwidth  = minimapwidth / numchunks;
                int chunkheight = minimapheight / numchunks;

                float[] ambientLight  = new float[] { 0.4f, 0.4f, 0.4f, 1.0f };
                float[] diffuseLight  = new float[] { 0.6f, 0.6f, 0.6f, 1.0f };
                float[] specularLight = new float[] { 0.2f, 0.2f, 0.2f, 1.0f };
                float[] position      = new float[] { -1.0f, 0.2f, -0.4f, 1.0f };

                Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_AMBIENT, ambientLight);
                Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_DIFFUSE, diffuseLight);
                Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_SPECULAR, specularLight);
                Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, position);

                foreach (RendererPass rendererpass in rendererpasses)
                {
                    rendererpass.Apply();

                    for (int x = 0; x + chunkwidth < minimapwidth; x += chunkwidth)
                    {
                        for (int y = 0; y + chunkheight < minimapheight; y += chunkheight)
                        {
                            Gl.glBegin(Gl.GL_QUADS);

                            //double ul = 0;
                            //double ur = mapwidth * Terrain.SquareSize;
                            //double vt = 0;
                            //double vb = mapheight * Terrain.SquareSize;
                            double ul = (double)x / minimapwidth * mapwidth;
                            double ur = (double)(x + chunkwidth) / minimapwidth * mapwidth;
                            double vt = (double)y / minimapheight * mapheight;
                            double vb = (double)(y + chunkheight) / minimapheight * mapheight;

                            double xl = minimapx + x;
                            double xr = minimapx + x + minimapwidth / (double)numchunks;
                            double yt = minimapy + y;
                            double yb = minimapy + y + minimapheight / (double)numchunks;

                            Gl.glTexCoord2d(ul, vt);
                            Gl.glMultiTexCoord2dARB(Gl.GL_TEXTURE1_ARB, ul, vt);
                            g.Normal(renderableheightmap.GetNormal(x * mapwidth / minimapwidth, y * mapheight / minimapheight));
                            //g.Normal(renderableheightmap.normalsperquad[, ]);
                            Gl.glVertex2d(xl, yt);

                            Gl.glTexCoord2d(ul, vb);
                            Gl.glMultiTexCoord2dARB(Gl.GL_TEXTURE1_ARB, ul, vb);
                            g.Normal(renderableheightmap.GetNormal(x * mapwidth / minimapwidth, (y + chunkheight) * mapheight / minimapheight));
                            //g.Normal( renderableheightmap.normalsperquad[x * mapwidth / minimapwidth, (y + 1) * mapheight / minimapheight ] );
                            Gl.glVertex2d(xl, yb);

                            Gl.glTexCoord2d(ur, vb);
                            Gl.glMultiTexCoord2dARB(Gl.GL_TEXTURE1_ARB, ur, vb);
                            g.Normal(renderableheightmap.GetNormal((x + chunkwidth) * mapwidth / minimapwidth, (y + chunkheight) * mapheight / minimapheight));
                            //g.Normal(renderableheightmap.normalsperquad[(x + 1) * mapwidth / minimapwidth, (y + 1) * mapheight / minimapheight]);
                            Gl.glVertex2d(xr, yb);

                            Gl.glTexCoord2d(ur, vt);
                            Gl.glMultiTexCoord2dARB(Gl.GL_TEXTURE1_ARB, ur, vt);
                            g.Normal(renderableheightmap.GetNormal((x + chunkwidth) * mapwidth / minimapwidth, y * mapheight / minimapheight));
                            //g.Normal(renderableheightmap.normalsperquad[(x + 1) * mapwidth / minimapwidth, y * mapheight / minimapheight]);
                            Gl.glVertex2d(xr, yt);

                            Gl.glEnd();
                        }
                    }
                }

                g.ActiveTexture(0);
                Gl.glBindTexture(Gl.GL_TEXTURE_2D, minimaptexture);
                Gl.glCopyTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, minimapx,
                                    RendererSdl.GetInstance().WindowHeight - minimapy - minimapsize,
                                    minimapsize, minimapsize, 0);
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_NEAREST);
                LastMinimapUpdate = DateTime.Now;

//                g.RemoveOrtho();

                g.ActiveTexture(1);
                g.DisableTexture2d();
                g.SetTextureScale(1);
                g.ActiveTexture(0);
                g.SetTextureScale(1);

                g.EnableModulate();

                Gl.glDisable(Gl.GL_BLEND);
            }
            else
            {
                GraphicsHelperGl g = new GraphicsHelperGl();

                //Gl.glMatrixMode(Gl.GL_PROJECTION);
                //Gl.glPushMatrix();
                //Gl.glLoadIdentity();
                //Gl.glOrtho(0, windowwidth, windowheight - RendererSdl.GetInstance().OuterWindowHeight, 0, -1, 1); // we'll just draw the minimap directly onto our display
                //Gl.glOrtho(0, windowwidth, windowheight, windowheight - RendererSdl.GetInstance().OuterWindowHeight, -1, 1); // we'll just draw the minimap directly onto our display

                //Gl.glMatrixMode(Gl.GL_MODELVIEW);
                //Gl.glPushMatrix();
                //Gl.glLoadIdentity();

                g.ActiveTexture(0);
                g.EnableTexture2d();
                Gl.glBindTexture(Gl.GL_TEXTURE_2D, minimaptexture);
                //Gl.glBindTexture(Gl.GL_TEXTURE_2D, (terrain.texturestages[0].texture as GlTexture).GlReference);
                Gl.glDisable(Gl.GL_LIGHTING);
                Gl.glBegin(Gl.GL_QUADS);

                Gl.glTexCoord2d(0, 1);
                Gl.glVertex2i(minimapx, minimapy);

                Gl.glTexCoord2d(0, 1 - minimapwidth / (double)minimapsize);
                Gl.glVertex2i(minimapx, minimapy + minimapheight);

                Gl.glTexCoord2d(minimapwidth / (double)minimapsize, 1 - minimapheight / (double)minimapsize);
                Gl.glVertex2i(minimapx + minimapwidth, minimapy + minimapheight);

                Gl.glTexCoord2d(minimapwidth / (double)minimapsize, 1);
                Gl.glVertex2i(minimapx + minimapwidth, minimapy);

                Gl.glEnd();

                Gl.glEnable(Gl.GL_LIGHTING);

                //Gl.glMatrixMode(Gl.GL_PROJECTION);
                //Gl.glPopMatrix();
                //Gl.glMatrixMode(Gl.GL_MODELVIEW);
                //Gl.glPopMatrix();
            }
        }