Exemplo n.º 1
0
        // Flexible create methods for the game
        private Gobject GetB_4_2_3(Vector3 pos, Vector3 orientYPR)
        {
            Gobject brick = assetManager.GetNewInstance(AssetTypes.B_4_2_3);

            brick.MoveTo(pos, Matrix.CreateFromQuaternion(Quaternion.CreateFromYawPitchRoll(orientYPR.X, orientYPR.Y, orientYPR.Z)));
            return(brick);
        }
Exemplo n.º 2
0
        public override void ProcessMouseDown(object sender, System.Windows.Forms.MouseEventArgs e, System.Drawing.Rectangle bounds)
        {
            try
            {
                Viewport view  = new Viewport(bounds.X, bounds.Y, bounds.Width, bounds.Height);
                Vector2  mouse = new Vector2(e.Location.X, e.Location.Y);
                Microsoft.Xna.Framework.Ray r = cameraManager.currentCamera.GetMouseRay(mouse, view);
                float         dist            = 0;
                Vector3       pos;
                Vector3       norm;
                CollisionSkin cs = new CollisionSkin();

                lock (physicsManager.PhysicsSystem)
                {
                    if (physicsManager.PhysicsSystem.CollisionSystem.SegmentIntersect(out dist, out cs, out pos, out norm, new Segment(r.Position, r.Direction * 1000), new Helper.Physics.DefaultCollisionPredicate()))
                    {
                        Body b = cs.Owner;
                        if (b == null)
                        {
                            return;
                        }
                        Gobject go = b.ExternalData as Gobject;
                        SelectGameObject(go);
                    }
                }
            }
            catch (Exception E)
            {
                System.Diagnostics.Debug.WriteLine(E.StackTrace);
            }
        }
Exemplo n.º 3
0
        private Gobject GetLaserPickup(Vector3 pos)
        {
            Gobject laser = assetManager.GetNewInstance(AssetTypes.Laser1Pickup);

            laser.Position = pos;
            return(laser);
        }
Exemplo n.º 4
0
        private void SpawnCircleHouse()
        {
            Vector3 HouseLocation = new Vector3(40, 0, 0);

            int   circumferenceBlockCount = 20;
            float blockLength             = 1.12f;
            float circumference           = circumferenceBlockCount * blockLength;
            float radius      = circumference / (float)Math.PI;
            float circPoint   = 0;
            float intervals   = (float)Math.PI * 2.0f / (float)circumferenceBlockCount;
            int   rows        = 5;
            float blockHeight = .1f;

            for (int y = 0; y < rows; y++)
            {
                if (y % 2 == 0)
                {
                    circPoint = 0;
                }
                else
                {
                    circPoint = intervals / 2.0f;
                }

                for (int c = 0; c < circumferenceBlockCount; c++)
                {
                    Vector3 brickLocation  = new Vector3((float)Math.Cos(circPoint), (blockHeight * y) - 1.5f, (float)Math.Sin(circPoint));
                    Vector3 brickOrientYPR = new Vector3((float)(-circPoint), 0, 0);
                    Gobject brick          = GetB_4_2_3(HouseLocation + (radius * brickLocation), brickOrientYPR);
                    circPoint += intervals;
                    physicsManager.AddNewObject(brick);
                }
            }
        }
Exemplo n.º 5
0
        private void SpawnPickups()
        {
            Random r = new Random((int)DateTime.Now.ToOADate());
            float  x, z;
            int    pickups = 10;

            for (int i = 0; i < pickups; i++)
            {
                x = (float)(r.NextDouble() - .5);
                z = (float)(r.NextDouble() - .5);

                x = x * 250;
                z = z * 250;

                Gobject box = GetLaserPickup(new Vector3(x, 3.0f, z));
                physicsManager.AddNewObject(box);
            }


            for (int i = 0; i < pickups; i++)
            {
                x = (float)(r.NextDouble() - .5);
                z = (float)(r.NextDouble() - .5);

                x = x * 250;
                z = z * 250;


                Gobject sphere = GetRadarPickup(new Vector3(x, 3.0f, z));
                physicsManager.AddNewObject(sphere);
            }
        }
Exemplo n.º 6
0
        private void PlayMouseDown(System.Windows.Forms.MouseEventArgs e, System.Drawing.Rectangle bounds)
        {
            try
            {
                Viewport view  = new Viewport(bounds.X, bounds.Y, bounds.Width, bounds.Height);
                Vector2  mouse = new Vector2(e.Location.X, e.Location.Y);
                Microsoft.Xna.Framework.Ray r = cameraManager.currentCamera.GetMouseRay(mouse, view);
                float         dist            = 0;
                Vector3       pos;
                Vector3       norm;
                CollisionSkin cs = new CollisionSkin();

                if (GetClickedPoint(out dist, out cs, out pos, out norm, new Segment(r.Position, r.Direction * 1000)))
                {
                    Body b = cs.Owner;
                    if (b == null)
                    {
                        return;
                    }
                    Gobject go = b.ExternalData as Gobject;
                    SelectGameObject(go);
                }
            }
            catch (Exception E)
            {
                System.Diagnostics.Debug.WriteLine(E.StackTrace);
            }
        }
Exemplo n.º 7
0
        private Gobject GetRadarPickup(Vector3 pos)
        {
            Gobject radar = assetManager.GetNewInstance(AssetTypes.Radar1Pickup);

            radar.Position = pos;
            return(radar);
        }
Exemplo n.º 8
0
        /// <summary>
        /// CLIENT SIDE  and  SERVER SIDE
        /// Called when a client receives an object update for an object it does not know about, instantiate one!
        /// Called when a server goes to add an object requested by a client
        /// </summary>
        /// <param name="objectid"></param>
        /// <param name="asset"></param>
        public override void AddNewObject(int objectid, int asset)
        {
            if (assetManager == null)
            {
                return;
            }
            // if our client is already using this object id for some reason
            if (assetManager.isObjectIdInUse(objectid))
            {
                // forget it, the next update will prompt it again, it will get added when it's safe.
                return;
            }

            if (Content == null)
            {
                return;
            }

            Gobject newobject = assetManager.GetNewInstance((AssetTypes)asset);

            if (newobject == null)
            {
                return;
            }

            newobject.isOnClient = isClient;
            newobject.isOnServer = isServer;
            newobject.ID         = objectid; // override whatever object ID the assetManager came up with, if it is safe to do so
            physicsManager.AddNewObject(newobject);
        }
Exemplo n.º 9
0
 public void Reactive()
 {
     if (Gobject.activeSelf)
     {
         Gobject.SetActive(false);
     }
     Gobject.SetActive(true);
 }
Exemplo n.º 10
0
 private void OnItemVariantChanged(ItemVariant variant)
 {
     foreach (var Gobject in ObjectsPreviewing)
     {
         //HERE WE APPLY VARIANT ON THE MODEL!
         Gobject.GetComponent <MeshRenderer>().material.color = variant.color;
     }
     activeVariant = variant;
 }
Exemplo n.º 11
0
        public override void Update()
        {
            base.Update();
            Gobject gob = GetFirstGobject();

            if (gob == null)
            {
                return;
            }

            LookAtLocation(gob.BodyPosition(), Vector3.Up);
        }
Exemplo n.º 12
0
        private Gobject SpawnCar(int ownerid, int objectid)
        {
            Gobject newobject = physicsManager.GetCar(carModel, wheelModel);

            newobject.ID = objectid;
            physicsManager.AddNewObject(newobject);
            if (ownerid == MyClientID) // Only select the new car if its OUR new car
            {
                myCar = (CarObject)newobject;
                SelectGameObject(myCar);
            }
            return(newobject);
        }
Exemplo n.º 13
0
        private Gobject SpawnRover(int ownerid, int objectid)
        {
            Gobject newobject = GetRover(new Vector3(90, 20, 20));

            newobject.ID = objectid;
            physicsManager.AddNewObject(newobject);
            Debug.WriteLine("Selecting: owner" + ownerid + " mine" + MyClientID);
            if (ownerid == MyClientID) // Only select the new car if its OUR new car
            {
                myRover = (RoverObject)newobject;
                SelectGameObject(myRover);
            }
            return(newobject);
        }
Exemplo n.º 14
0
        private Gobject SpawnPlane(int ownerid, int objectid)
        {
            // test code for client-side aircraft/plane spawning
            Gobject newobject = physicsManager.GetAircraft(airplane);

            newobject.ID = gameObjects.Count;
            physicsManager.AddNewObject(newobject);
            if (ownerid == MyClientID) // Only select the new car if its OUR new car
            {
                myPlane = (Aircraft)newobject;
                SelectGameObject(myPlane);
            }
            return(newobject);
        }
Exemplo n.º 15
0
        private Gobject CreateSmallSphere()
        {
            float   radius          = .4f;
            Sphere  spherePrimitive = new Sphere(Vector3.Zero, radius);
            Gobject sphere          = new Gobject(
                Vector3.Zero,
                Vector3.One * radius,
                spherePrimitive,
                sphereModel,
                true,
                0);

            return(sphere);
        }
Exemplo n.º 16
0
        public Gobject GetSphere(Vector3 pos, float radius, Model model, bool moveable)
        {
            Sphere  spherePrimitive = new Sphere(pos, radius);
            Gobject sphere          = new Gobject(
                pos,
                Vector3.One * radius,
                spherePrimitive,
                model,
                moveable,
                0);

            //newObjects.Add(sphere.ID, sphere);
            return(sphere);
        }
Exemplo n.º 17
0
 public void SelectGameObject(Gobject go)
 {
     if (go == null)
     {
         return;
     }
     if (currentSelectedObject != null)
     {
         currentSelectedObject.Selected = false;
     }
     Debug.WriteLine("SelectGameObject id:" + go.ID);
     currentSelectedObject          = go;
     currentSelectedObject.Selected = true;
     //objectCam.TargetPosition = currentSelectedObject.Position;
 }
Exemplo n.º 18
0
        /// <summary>
        /// CLIENT SIDE
        /// client should do something oriented to the specific game here, like player bullets or cars.
        /// The server has granted the object request and this is where we handle the response it has sent back to the client
        /// This is called from the Network code, thus in the Network threads
        /// </summary>
        /// <param name="objectid"></param>
        /// <param name="asset"></param>
        public override void ProcessObjectAdded(int ownerid, int objectid, int asset)
        {
            Gobject newobject = assetManager.GetNewInstance((AssetTypes)asset);

            newobject.ID = objectid;
            physicsManager.AddNewObject(newobject);
            if (ownerid == MyClientID) // Only select the new car if its OUR new car
            {
                if (newobject is LunarVehicle)
                {
                    lander = (LunarVehicle)newobject;
                    SelectGameObject(lander);
                }
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// CLIENT SIDE
        /// client should do something oriented to the specific game here, like player bullets or cars.
        /// The server has granted the object request and this is where the client handle the response the server has sent back
        /// This is called from the Network code, thus in the Network threads
        /// </summary>
        /// <param name="objectid"></param>
        /// <param name="asset"></param>
        public override void ProcessObjectAdded(int ownerid, int objectid, int asset)
        {
            Debug.WriteLine("Process Object Added: owner:" + ownerid + " id:" + objectid + " asset:" + asset);
            Gobject newobject = assetManager.GetNewInstance((AssetTypes)asset);

            newobject.ID = objectid;
            physicsManager.AddNewObject(newobject);
            if (ownerid == MyClientID) // Only select the new car if its OUR new car
            {
                if (newobject is RoverObject)
                {
                    myRover = (RoverObject)newobject;
                    SelectGameObject(myRover);
                }
            }
        }
Exemplo n.º 20
0
        public override void Update()
        {
            base.Update();
            Gobject gob = GetFirstGobject();

            if (gob == null)
            {
                return;
            }
            // bodyPosition is the physical location of the body
            Vector3 bodyPosition    = gob.BodyPosition();
            Matrix  bodyOrientation = gob.BodyOrientation();

            try
            {
                // the location of where it's headed
                Vector3 ObjectDirection = gob.BodyVelocity(); // this * 2 value is pointless I think

                if (ObjectDirection.Length() < 2)             // this may be here just to prevent slow velocities from making a stalker camera
                {
                    ObjectDirection = gob.BodyOrientation().Forward;
                }

                Vector3 WhereItsHeaded = bodyPosition + ObjectDirection;

                // a vector pointing toward the direction of travel
                //Vector3 Direction = (WhereItsHeaded - bodyPosition);
                ObjectDirection.Normalize();
                ObjectDirection *= 10f; // this may need to be adjustable per object (planes go faster than cars)
                Vector3 WhereItCameFrom = bodyPosition - (ObjectDirection);

                Vector3 offset = new Vector3(0, 2, 0);
                if (profiles.ContainsKey(gob.type))
                {
                    offset = profiles[gob.type].PositionOffset;
                }
                offset = Vector3.Transform(offset, bodyOrientation);
                // get the correction value from the profile
                WhereItCameFrom += offset;
                TargetPosition   = WhereItCameFrom; // this line caused a problem at one time.
                TargetLookAt     = WhereItsHeaded;
            }
            catch (Exception E)
            {
                System.Diagnostics.Debug.WriteLine(E.StackTrace);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Adds a new object to the physics system
        /// </summary>
        /// <param name="gob"></param>
        /// <returns></returns>
        public bool AddNewObject(Gobject gob)
        {
            lock (gameObjects)
            {
                lock (ObjectsToAdd)
                {
                    if (gameObjects.ContainsKey(gob.ID) ||
                        ObjectsToAdd.ContainsKey(gob.ID))
                    {
                        return(false);
                    }

                    ObjectsToAdd.Add(gob.ID, gob);
                }
            }
            return(true);
        }
Exemplo n.º 22
0
        public Gobject GetBox(Vector3 pos, Vector3 size, Matrix orient, Model model, bool moveable)
        {
            // position of box was upper leftmost corner
            // body has world position
            // skin is relative to the body
            Box boxPrimitive = new Box(-.5f * size, orient, size); // relative to the body, the position is the top left-ish corner instead of the center, so subtract from the center, half of all sides to get that point.

            Gobject box = new Gobject(
                pos,
                size / 2,
                boxPrimitive,
                model,
                moveable,
                0
                );


            return(box);
        }
Exemplo n.º 23
0
        bool CollisionSkin_callbackFn(CollisionSkin skin0, CollisionSkin skin1)
        {
            RoverObject rover = null;
            Gobject     obj   = null;

            if (skin0.Owner.ExternalData is RoverObject)
            {
                rover = skin0.Owner.ExternalData as RoverObject;
            }
            if (skin1.Owner == null)
            {
                return(true);
            }
            if (skin1.Owner.ExternalData is Gobject)
            {
                obj = skin1.Owner.ExternalData as Gobject;
            }

            if (rover == null || obj == null)
            {
                return(true);
            }

            if (objectsToDelete.Contains(obj.ID)) // if the object is going to be deleted soon,
            {
                return(false);                    // don't bother doing any collision with it
            }
            int type = obj.type;

            if ((AssetTypes)type == AssetTypes.Laser1Pickup)
            {
                rover.SetLaser(true);
                DeleteObject(obj.ID);
                return(false);
            }
            if ((AssetTypes)type == AssetTypes.Radar1Pickup)
            {
                rover.SetRadar(true);
                DeleteObject(obj.ID);
                return(false);
            }
            return(true);
        }
Exemplo n.º 24
0
        private Gobject CreateHighFrictionCube()
        {
            Vector3 size = new Vector3(1, 1, 1);
            // position of box was upper leftmost corner
            // body has world position
            // skin is relative to the body
            Box boxPrimitive = new Box(-.5f * size, Matrix.Identity, size); // relative to the body, the position is the top left-ish corner instead of the center, so subtract from the center, half of all sides to get that point.

            Gobject box = new Gobject(
                Vector3.Zero, // position can be setup just following call to assetManager.GetNewInstance
                size / 2,
                boxPrimitive,
                MaterialTable.MaterialID.NotBouncyRough,
                cubeModel,
                0 // asset name is set automatically by asset manager when requested
                );

            return(box);
        }
Exemplo n.º 25
0
        public override void Update()
        {
            base.Update();
            Vector3 orientAdjustment   = Vector3.Zero;
            Vector3 positionAdjustment = Vector3.Zero;

            Gobject gob = GetFirstGobject();

            if (gob == null)
            {
                return;
            }


            int assetname = gob.type;

            // if this camera has a profile for this asset,
            if (profiles.ContainsKey(assetname))
            {
                // get the adjustment value from the profile
                orientAdjustment = profiles[assetname].OrientationOffset;
                // get the adjustment value from the profile
                positionAdjustment = profiles[assetname].PositionOffset;
            }


            // create an adjustment quat for the orientation
            Quaternion orientOffset = Quaternion.CreateFromYawPitchRoll(orientAdjustment.Y, orientAdjustment.X, orientAdjustment.Z);// YXZ
            // combine body orientation and adjustment quat
            Quaternion newOrientation = Quaternion.CreateFromRotationMatrix(gob.BodyOrientation()) * orientOffset;

            // update the orientation
            SetTargetOrientation(newOrientation);

            // put the adjustment vector for the position into body coordinates
            positionAdjustment = Vector3.Transform(positionAdjustment, newOrientation);
            // update the position
            CurrentPosition = gob.BodyPosition() + positionAdjustment;
        }
Exemplo n.º 26
0
        /// <summary>
        /// The physics engine is about to integrate, so we need to process things from the server about "reality"
        /// now is the time for the client to send ObjectActionPackets the server about inputs
        /// now is the tine for the client to process ObjectAttributePackets from the server about changes (shape, mode, behavior).
        /// now is the time for the client to process ObjectUpdatePackets from the server about pos/orient/vel
        /// now is the time for the server to process ObjectActionPackets the client about pos/orient/vel
        /// </summary>
        void physicsManager_PreIntegrate()
        {
            if (isClient)
            {
                lock (gameObjects)
                {
                    #region Send Action Updates to the server
                    foreach (int i in clientControlledObjects)
                    {
                        if (!gameObjects.ContainsKey(i))
                        {
                            continue;
                        }
                        Gobject go = gameObjects[i];
                        if (!go.actionManager.actionApplied)
                        {
                            continue;
                        }

                        if (go is RoverObject)
                        {
                        }
                        object[] vals = go.actionManager.GetActionValues();
                        go.actionManager.ValueSwap();
                        commClient.SendObjectAction(go.ID, vals);
                    }
                    #endregion

                    #region Process packets from the server
                    List <object> ShouldRetry = new List <object>();
                    lock (MultiplayerUpdateQueue)
                    {
                        while (MultiplayerUpdateQueue.Count > 0)
                        {
                            Packet p = MultiplayerUpdateQueue[0] as Packet;
                            MultiplayerUpdateQueue.RemoveAt(0);

                            if (p is ObjectUpdatePacket)
                            {
                                #region Process Update Packets from the server
                                ObjectUpdatePacket oup = p as ObjectUpdatePacket;

                                if (!gameObjects.ContainsKey(oup.objectId))
                                {
                                    AddNewObject(oup.objectId, oup.assetName);
                                    ShouldRetry.Add(oup);
                                    continue;
                                    // TODO -  Should we continue instead of not updating this frame?
                                }
                                // (can't yet due to AddNewObject waiting until the next integrate to actually add it)
                                Gobject go = gameObjects[oup.objectId];
                                if (go.hasNotDoneFirstInterpoladation)
                                {
                                    go.Interpoladate(oup.position, oup.orientation, oup.velocity, 1.0f); // Server knows best!
                                }
                                else
                                {
                                    go.Interpoladate(oup.position, oup.orientation, oup.velocity); // split realities 50/50
                                }
                                #endregion
                            }
                            else if (p is ObjectAttributePacket)
                            {
                                #region Process Attribute Packets from the server
                                ObjectAttributePacket oap = p as ObjectAttributePacket;
                                if (gameObjects.ContainsKey(oap.objectId))
                                {
                                    Gobject go = gameObjects[oap.objectId];
                                    bool    locallyOwnedAndOperated = false;

                                    if (go.OwningClientId == MyClientID)
                                    {
                                        locallyOwnedAndOperated = true;
                                    }
                                    go.SetObjectAttributes(oap.booleans, oap.ints, oap.floats, locallyOwnedAndOperated);
                                }
                                #endregion
                            }
                        }
                        while (ShouldRetry.Count > 0)
                        {
                            MultiplayerUpdateQueue.Add(ShouldRetry[0]);
                            ShouldRetry.RemoveAt(0);
                        }
                    }



                    #endregion
                }
            }
            else if (isServer)
            {
                lock (gameObjects)
                {
                    #region Process Action Updates from the client
                    lock (MultiplayerUpdateQueue)
                    {
                        while (MultiplayerUpdateQueue.Count > 0)
                        {
                            ObjectActionPacket oap = MultiplayerUpdateQueue[0] as ObjectActionPacket;
                            if (!gameObjects.ContainsKey(oap.objectId))
                            {
                                continue; // TODO - infinite loop if this is hit
                            }
                            Gobject go = gameObjects[oap.objectId];
                            go.actionManager.ProcessActionValues(oap.actionParameters);
                            MultiplayerUpdateQueue.RemoveAt(0);
                        }
                    }
                    #endregion
                }
            }
        }
Exemplo n.º 27
0
        private void SpawnRectangleHouse()
        {
            Vector3 HouseLocation             = new Vector3(0, 0, 0);
            int     LongWallLengthBrickCount  = 4;
            int     ShortWallLengthBrickCount = 2;
            float   blockLength = 2.0f;
            int     rows        = 2;
            float   blockHeight = 1f;
            Vector3 WallPoint   = new Vector3(0, 0, 0);
            int     count       = 0;

            for (int y = 0; y < rows; y++)
            {
                WallPoint.Z = 0;
                if (y % 2 == 0)
                {
                    WallPoint.X -= blockLength / 4.0f;

                    count = LongWallLengthBrickCount;
                }
                else
                {
                    WallPoint.X += blockLength / 4.0f;
                    count        = LongWallLengthBrickCount;
                }

                // increase x
                for (int b = 0; b < count; b++)
                {
                    Vector3 brickLocation  = new Vector3(WallPoint.X, (y * blockHeight) - 10.5f, WallPoint.Z);
                    Vector3 brickOrientYPR = new Vector3((float)Math.PI / 2.0f, 0, 0);
                    Gobject brick          = GetB_4_2_3(HouseLocation + brickLocation, brickOrientYPR);
                    WallPoint.X += blockLength;
                    physicsManager.AddNewObject(brick);
                }

                if (y % 2 == 0)
                {
                    WallPoint.Z -= 0;
                    count        = ShortWallLengthBrickCount;
                }
                else
                {
                    WallPoint.Z -= blockLength / 2.0f;
                    count        = ShortWallLengthBrickCount;
                }

                // increase Z
                for (int b = 0; b < count; b++)
                {
                    Vector3 brickLocation  = new Vector3(WallPoint.X, (y * blockHeight) - 10.5f, WallPoint.Z);
                    Vector3 brickOrientYPR = new Vector3(0, 0, 0);
                    Gobject brick          = GetB_4_2_3(HouseLocation + brickLocation, brickOrientYPR);
                    WallPoint.Z += blockLength;
                    physicsManager.AddNewObject(brick);
                }

                if (y % 2 == 0)
                {
                    WallPoint.X -= 0;
                    count        = LongWallLengthBrickCount;
                }
                else
                {
                    WallPoint.X -= blockLength / 2.0f;
                    count        = LongWallLengthBrickCount;
                }

                // decrease x
                for (int b = 0; b < count; b++)
                {
                    Vector3 brickLocation  = new Vector3(WallPoint.X, (y * blockHeight) - 10.5f, WallPoint.Z);
                    Vector3 brickOrientYPR = new Vector3((float)Math.PI / 2.0f, 0, 0);
                    Gobject brick          = GetB_4_2_3(HouseLocation + brickLocation, brickOrientYPR);
                    WallPoint.X -= blockLength;
                    physicsManager.AddNewObject(brick);
                }


                if (y % 2 == 0)
                {
                    WallPoint.Z -= 0;
                    count        = ShortWallLengthBrickCount;
                }
                else
                {
                    WallPoint.Z -= blockLength / 2.0f;
                    count        = ShortWallLengthBrickCount;
                }

                // decrease Z
                for (int b = 0; b < count; b++)
                {
                    Vector3 brickLocation  = new Vector3(WallPoint.X, (y * blockHeight) - 10.5f, WallPoint.Z);
                    Vector3 brickOrientYPR = new Vector3(0, 0, 0);
                    Gobject brick          = GetB_4_2_3(HouseLocation + brickLocation, brickOrientYPR);
                    WallPoint.Z -= blockLength;
                    physicsManager.AddNewObject(brick);
                }
            }
        }