Exemple #1
0
        private void GenerateFloorObjectFromFloorShapes(List <GameTile> tiles)
        {
            GameObject      finalFloorShape = new GameObject();
            ProceduralShape finalShape      = new ProceduralShape();

            ProceduralPlane plane = new ProceduralPlane();

            plane.SetColor(Color.LightGray.ChangeTone(RandomHelper.GetRandomInt(-20, 20)));
            plane.Scale(tiles[0].Scale);
            plane.Translate(tiles[0].Center);


            finalShape = plane;
            AddLineBatch(plane);


            for (int i = 1; i < tiles.Count; i++)
            {
                ProceduralPlane newPlane = new ProceduralPlane();
                newPlane.SetColor(Color.LightGray.ChangeTone(RandomHelper.GetRandomInt(-20, 20)));
                newPlane.Scale(tiles[i].Scale);
                newPlane.Translate(tiles[i].Center);
                finalShape = ProceduralShape.Combine(finalShape, newPlane);
                AddLineBatch(newPlane);
            }

            finalFloorShape.AddComponent(new RenderGeometryComponent(finalShape));
            finalFloorShape.AddComponent(new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded")));
            finalFloorShape.AddComponent(new ShadowCasterComponent());
            SystemCore.GameObjectManager.AddAndInitialiseGameObject(finalFloorShape);
        }
        public GameObject AddShapeToScene(ProceduralShape shape)
        {
            GameObject o = GameObjectFactory.CreateRenderableGameObjectFromShape(shape, EffectLoader.LoadSM5Effect("flatshaded"));

            SystemCore.GameObjectManager.AddAndInitialiseGameObject(o);
            return(o);
        }
        /// <summary>
        /// Fully simulated physics object.
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="effect"></param>
        /// <param name="meshType"></param>
        /// <returns></returns>
        public static GameObject CreateSimulatedObject(ProceduralShape shape, Effect effect, PhysicsMeshType meshType)
        {
            var ob = CreateRenderableGameObjectFromShape(shape, effect);

            ob.AddComponent(new PhysicsComponent(true, true, meshType));
            return(ob);
        }
        public static GameObject CreateRenderableGameObjectFromShape(string name, ProceduralShape shape, Effect effect)
        {
            var obj = CreateRenderableGameObjectFromShape(shape, effect);

            obj.Name = name;
            return(obj);
        }
        public static GameObject CreateRenderableGameObjectFromShape(int id, ProceduralShape shape, Effect effect)
        {
            var ob = CreateRenderableGameObjectFromShape(shape, effect);

            ob.ID = id;
            return(ob);
        }
Exemple #6
0
        private static void SaveShape(string name, ProceduralShape combined)
        {
            BinaryFormatter bf = new BinaryFormatter();

            using (FileStream fs = new FileStream(name + ".shape", FileMode.Create))
            {
                bf.Serialize(fs, combined);
            }
        }
Exemple #7
0
        private void AddPolygon()
        {
            shapeBuilder.AddFaceWithColor(currentColour, currentVertices.ToArray());
            currentVertices.Clear();

            ProceduralShape s = shapeBuilder.BakeShape();

            RehydrateShape(s);

            shapeBuilder.Clear();
        }
Exemple #8
0
        private static void CreateTestArena()
        {
            float arenaSize = 40f;


            ProceduralCuboid a = new ProceduralCuboid(arenaSize, 1, arenaSize / 5);

            a.Translate(new Vector3(0, arenaSize / 5, arenaSize));
            a.SetColor(Color.LightGray);

            ProceduralShape b = a.Clone();

            b.Translate(new Vector3(0, 0, -arenaSize * 2));

            ProceduralShape c = ProceduralShape.Combine(a, b);
            ProceduralShape d = b.Clone();

            d.Transform(MonoMathHelper.RotateNinetyDegreesAroundUp(true));

            ProceduralShape e = ProceduralShape.Combine(c, d);



            var side2 = e.Clone();
            var side3 = e.Clone();
            var side4 = e.Clone();

            e.Translate(new Vector3(-arenaSize * 2, 0, 0));

            side2.Transform(MonoMathHelper.RotateHundredEightyDegreesAroundUp(true));
            side2.Translate(new Vector3(arenaSize * 2, 0, 0));
            side3.Transform(MonoMathHelper.RotateNinetyDegreesAroundUp(true));
            side3.Translate(new Vector3(0, 0, arenaSize * 2));
            side4.Transform(MonoMathHelper.RotateNinetyDegreesAroundUp(false));
            side4.Translate(new Vector3(0, 0, -arenaSize * 2));



            var final = ProceduralShape.Combine(e, side2, side3, side4);

            var arenaObject = GameObjectFactory.CreateRenderableGameObjectFromShape(final,
                                                                                    EffectLoader.LoadSM5Effect("flatshaded"));


            arenaObject.AddComponent(new StaticMeshColliderComponent(arenaObject, final.GetVertices(),
                                                                     final.GetIndicesAsInt().ToArray(), Vector3.Zero));

            arenaObject.AddComponent(new ShadowCasterComponent());


            SystemCore.GameObjectManager.AddAndInitialiseGameObject(arenaObject);
        }
Exemple #9
0
        public void BakeAndSaveCurrentShape(string name)
        {
            List <ProceduralShape> shapes = shapesToBake.Values.ToList();

            ProceduralShape combined = shapes[0];

            for (int i = 1; i < shapes.Count; i++)
            {
                combined = ProceduralShape.Combine(combined, shapes[i]);
            }

            SaveShape(name, combined);
        }
Exemple #10
0
        public static ProceduralShape LoadShape(string name)
        {
            BinaryFormatter bf = new BinaryFormatter();

            ProceduralShape s = null;

            if (File.Exists(name + ".shape"))
            {
                using (FileStream fs = new FileStream(name + ".shape", FileMode.Open))
                {
                    s = bf.Deserialize(fs) as ProceduralShape;
                }
            }

            return(s);
        }
Exemple #11
0
        public RenderTestScreen()
            : base()
        {
            SystemCore.CursorVisible = false;
            fpsLabel.Visible         = true;
            SystemCore.ActiveScene.SetUpBasicAmbientAndKey();

            var effect = EffectLoader.LoadSM5Effect("FlatShaded");


            mouseCamera = new MouseFreeCamera(new Vector3(0, 0, 0));
            SystemCore.SetActiveCamera(mouseCamera);

            var shape = new ProceduralSphere(20, 20);

            shape.SetColor(SystemCore.ActiveColorScheme.Color5);



            //create 100 cubes, add collision and collision visualiser components, give them random position and velocity
            for (int i = 0; i < 100; i++)
            {
                var gameObject = new GameObject();
                gameObject.AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(shape), BufferBuilder.IndexBufferBuild(shape), shape.PrimitiveCount));

                gameObject.AddComponent(new EffectRenderComponent(effect));
                //gameObject.AddComponent(new BasicEffectRenderComponent(effect));
                gameObject.Transform.SetPosition(RandomHelper.GetRandomVector3(Vector3.One * -100, Vector3.One * 100));
                gameObject.AddComponent(new RotatorComponent(Vector3.Up));
                SystemCore.GetSubsystem <GameObjectManager>().AddAndInitialiseGameObject(gameObject);

                gameObject.Transform.Scale    = 5f;
                gameObject.Transform.Velocity = RandomHelper.GetRandomVector3(-Vector3.One, Vector3.One) * 0.01f;
            }


            AddInputBindings();

            Model           geoDesicModel = SystemCore.ContentManager.Load <Model>("Models/geodesic");
            ProceduralShape geodesicShape = ModelMeshParser.GetShapeFromModelNoUVs(geoDesicModel);

            geodesicShape.Scale(20f);
            geodesicShape.InsideOut();
            GameObject geoDesic = GameObjectFactory.CreateRenderableGameObjectFromShape(geodesicShape, EffectLoader.LoadSM5Effect("cockpitscreen"));

            SystemCore.GameObjectManager.AddAndInitialiseGameObject(geoDesic);
        }
        /// <summary>
        /// No physics component.
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="effect"></param>
        /// <returns></returns>
        public static GameObject CreateRenderableGameObjectFromShape(ProceduralShape shape, Effect effect)
        {
            var ob = new GameObject();

            ob.AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(shape), BufferBuilder.IndexBufferBuild(shape), shape.PrimitiveCount));


            if (shape is LineBatch)
            {
                ob.AddComponent(new LineRenderComponent(effect as BasicEffect));
            }

            ob.AddComponent(new EffectRenderComponent(effect));


            return(ob);
        }
Exemple #13
0
        private void RehydrateShape(ProceduralShape shape)
        {
            //take the translation expressed in the verts, and switch it over to
            //the world transform so the physics collision works.
            //then translate back for when we bake out again.
            var midPoint = shape.GetMidPoint();

            shape.Translate(-midPoint);

            var gameObj = GameObjectFactory.CreateRenderableGameObjectFromShape(shape,
                                                                                EffectLoader.LoadSM5Effect("flatshaded"));

            gameObj.Transform.Translate(midPoint);

            gameObj.AddComponent(new PhysicsComponent(false, false, PhysicsMeshType.box));
            SystemCore.GameObjectManager.AddAndInitialiseGameObject(gameObj);

            shapesToBake.Add(gameObj, shape);
            shape.Translate(midPoint);
        }
Exemple #14
0
        public static ProceduralShape GetShapeFromModelWithUVs(Model model)
        {
            foreach (ModelMesh modelMesh in model.Meshes)
            {
                ProceduralShape shape = null;
                foreach (ModelMeshPart part in modelMesh.MeshParts)
                {
                    VertexPositionNormalTexture[] array =
                        new VertexPositionNormalTexture[part.VertexBuffer.VertexCount];

                    VertexPositionColorTextureNormal[] newArray = new VertexPositionColorTextureNormal[part.VertexBuffer.VertexCount];

                    short[] indices = new short[part.IndexBuffer.IndexCount];
                    part.IndexBuffer.GetData <short>(indices);

                    part.VertexBuffer.GetData <VertexPositionNormalTexture>(array);


                    for (int i = 0; i < array.Length; i++)
                    {
                        newArray[i] = new VertexPositionColorTextureNormal(array[i].Position, Color.DarkGray,
                                                                           array[i].TextureCoordinate, array[i].Normal);
                    }



                    if (shape == null)
                    {
                        shape = new ProceduralShape(newArray, indices);
                    }
                    else
                    {
                        shape = ProceduralShape.Combine(shape, new ProceduralShape(newArray, indices));
                    }

                    return(shape);
                }
            }
            return(null);
        }
Exemple #15
0
        public MainGameScreen()
            : base()
        {
            SystemCore.ActiveScene.SetUpBasicAmbientAndKey();

            SystemCore.AddNewUpdateRenderSubsystem(new SkyDome(Color.Black, Color.Black, Color.Black));


            ship = new Ship("ship");
            SystemCore.SetActiveCamera(ship.shipCameraObject.GetComponent <ComponentCamera>());



            Model           geoDesicModel = SystemCore.ContentManager.Load <Model>("Models/geodesic2");
            ProceduralShape geodesicShape = ModelMeshParser.GetShapeFromModelWithUVs(geoDesicModel);

            geodesicShape.Scale(1f);
            geodesicShape.InsideOut();

            ship.AddComponent(new RenderGeometryComponent(geodesicShape));
            //var cockpitEffectComponent = new EffectRenderComponent(EffectLoader.LoadEffect("cockpitscreen"));
            //cockpitEffectComponent.DrawOrder = 100;
            //ship.AddComponent(cockpitEffectComponent);

            oldPos = ship.GetComponent <HighPrecisionPosition>().Position;
            SystemCore.GameObjectManager.AddAndInitialiseGameObject(ship);


            testPlanetSurfacePosition           = new PlanetSurfacePosition();
            testPlanetSurfacePosition.Latitude  = 40;
            testPlanetSurfacePosition.Longitude = -90;

            solarSystem            = new SolarSystem();
            solarSystem.PlayerShip = ship;
            ship.SolarSystem       = solarSystem;
            SystemCore.AddNewGameComponent(solarSystem);
            ship.Transform.Rotate(Vector3.Up, MathHelper.PiOver2);
        }
Exemple #16
0
 public RenderGeometryComponent(ProceduralShape shape)
 {
     this.VertexBuffer   = BufferBuilder.VertexBufferBuild(shape);
     this.IndexBuffer    = BufferBuilder.IndexBufferBuild(shape);
     this.PrimitiveCount = shape.PrimitiveCount;
 }
Exemple #17
0
        private static GameObject CreateTestArena(float arenaSize)
        {
            ProceduralShapeBuilder floor = new ProceduralShapeBuilder();

            floor.AddSquareFace(new Vector3(arenaSize, 0, arenaSize), new Vector3(-arenaSize, 0, arenaSize),
                                new Vector3(arenaSize, 0, -arenaSize), new Vector3(-arenaSize, 0, -arenaSize));

            ProceduralShape arenaFloor = floor.BakeShape();

            arenaFloor.SetColor(Color.DarkOrange);

            ProceduralCuboid a = new ProceduralCuboid(arenaSize, 1, arenaSize / 5);

            a.Translate(new Vector3(0, arenaSize / 5, arenaSize));
            a.SetColor(Color.LightGray);

            ProceduralShape b = a.Clone();

            b.Translate(new Vector3(0, 0, -arenaSize * 2));

            ProceduralShape c = ProceduralShape.Combine(a, b);
            ProceduralShape d = b.Clone();

            d.Transform(MonoMathHelper.RotateNinetyDegreesAroundUp(true));

            ProceduralShape e = ProceduralShape.Combine(arenaFloor, c, d);



            var side2 = e.Clone();
            var side3 = e.Clone();
            var side4 = e.Clone();

            e.Translate(new Vector3(-arenaSize * 2, 0, 0));

            side2.Transform(MonoMathHelper.RotateHundredEightyDegreesAroundUp(true));
            side2.Translate(new Vector3(arenaSize * 2, 0, 0));
            side3.Transform(MonoMathHelper.RotateNinetyDegreesAroundUp(true));
            side3.Translate(new Vector3(0, 0, arenaSize * 2));
            side4.Transform(MonoMathHelper.RotateNinetyDegreesAroundUp(false));
            side4.Translate(new Vector3(0, 0, -arenaSize * 2));



            var final = ProceduralShape.Combine(e, side2, side3, side4, arenaFloor);

            var arenaObject = GameObjectFactory.CreateRenderableGameObjectFromShape(final,
                                                                                    EffectLoader.LoadSM5Effect("flatshaded"));


            arenaObject.AddComponent(new StaticMeshColliderComponent(arenaObject, final.GetVertices(),
                                                                     final.GetIndicesAsInt().ToArray()));


            // arenaObject.AddComponent(new RotatorComponent(Vector3.Up, 0.0001f));

            SystemCore.GameObjectManager.AddAndInitialiseGameObject(arenaObject);


            LineBatch  l          = new LineBatch(new Vector3(-arenaSize, 0.1f, -arenaSize), new Vector3(-arenaSize, 0.1f, arenaSize), new Vector3(arenaSize, 0.1f, arenaSize), new Vector3(arenaSize, 0.1f, -arenaSize), new Vector3(-arenaSize, 0.1f, -arenaSize));
            GameObject lineObject = SystemCore.GameObjectManager.AddLineBatchToScene(l);

            arenaObject.AddChild(lineObject);



            return(arenaObject);
        }