Example #1
0
        public Model GetModel(int id)
        {
            Asset a = Assets[id];

            if (a == null)
            {
                return(null);
            }
            Gobject go = a.GetNewGobject();

            return(go.Model);
        }
Example #2
0
        //public Gobject GetNewInstance<T>(T type, int owningClientId) where T : int
        //{
        //    return GetNewInstance(type, owningClientId);
        //}

        /// <summary>
        /// returns an instance of the specified asset type
        /// </summary>
        /// <param name="e"></param>
        /// <param name="owningClientId"></param>
        /// <returns></returns>
        private Gobject GetNewInstance(int id, int owningClientId)
        {
            if (!Assets.ContainsKey(id))
            {
                Debug.WriteLine("Aborting load of asset unkown to AssetManager: " + id);
                return(null);
            }

            Asset a = Assets[id];

            if (a == null)
            {
                return(null);
            }

            Gobject go = a.GetNewGobject();

            go.OwningClientId = owningClientId;
            go.type           = id; // THIS IS WRONG BUT SO CHEAP! - Colby.
            go.ID             = GetAvailableObjectId();

            if (!ObjectIdsByOwningClient.ContainsKey(owningClientId))
            {
                ObjectIdsByOwningClient.Add(owningClientId, new List <int>());
            }

            List <int> ownedIds = ObjectIdsByOwningClient[owningClientId];

            ownedIds.Add(go.ID);
            if (!OwningClientsByObjectId.ContainsKey(go.ID))
            {
                OwningClientsByObjectId.Add(go.ID, owningClientId);
            }

            // we should centralize all object addition here. (but still return the Gobject)
            // Maybe the baseGame should call PostIntegrate and PreIntegrate methods overridden in the specific game so that Specific-Game can call AssetManager.GetNewInstance() at the appropriate time.
            return(go);
        }
Example #3
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;
 }
Example #4
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;
 }
Example #5
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;
        }
Example #6
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;
        }
Example #7
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;
        }
Example #8
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;
        }