protected override void InitScreen(GraphicInfo GraphicInfo, EngineStuff engine)
        {
            base.InitScreen(GraphicInfo, engine);

            SkyBox skybox = new SkyBox();

            engine.AddComponent(skybox);

            InputAdvanced ia = new InputAdvanced();

            engine.AddComponent(ia);
        }
Example #2
0
        public void Update(IUpdateArgs args, SkyBox skyRenderer)
        {
            var entities = Entities.Values.ToArray();

            foreach (var entity in entities)
            {
                if (entity is Entity e)
                {
                    e.ModelRenderer.DiffuseColor = Color.White.ToVector3() * World.BrightnessModifier;
                }
                entity.Update(args);
            }
        }
Example #3
0
        public void Update(UpdateArgs args)
        {
            if (_destroyed)
            {
                return;
            }

            var camera = Camera;

            args.Camera = camera;

            /*if (Math.Abs(Player.FOVModifier - _fovModifier) > 0f)
             * {
             *      _fovModifier = Player.FOVModifier;
             *
             *      camera.FOV += _fovModifier;
             *      camera.UpdateProjectionMatrix();
             *      camera.FOV -= _fovModifier;
             * }*/
            camera.Update(args);

            //_brightnessMod = SkyRenderer.BrightnessModifier;

            SkyBox.Update(args);
            ChunkManager.Update(args);

            EntityManager.Update(args);
            PhysicsEngine.Update(args.GameTime);

            if (Math.Abs(_brightnessMod - SkyBox.BrightnessModifier) > 0f)
            {
                _brightnessMod = SkyBox.BrightnessModifier;

                var diffuseColor = Color.White.ToVector3() * SkyBox.BrightnessModifier;
                ChunkManager.AmbientLightColor = diffuseColor;

                if (Math.Abs(ChunkManager.Shaders.BrightnessModifier - SkyBox.BrightnessModifier) > 0f)
                {
                    ChunkManager.Shaders.BrightnessModifier = SkyBox.BrightnessModifier;
                }

                var modelRenderer = Player?.ModelRenderer;

                if (modelRenderer != null)
                {
                    modelRenderer.DiffuseColor = diffuseColor;
                }
            }

            Player?.Update(args);
        }
        protected override void InitScreen(GraphicInfo GraphicInfo, EngineStuff engine)
        {
            base.InitScreen(GraphicInfo, engine);

            SkyBox skybox = new SkyBox();

            engine.AddComponent(skybox);

            SoundMasterOptionDescription sod = engine.GetSoundMasterOptionDescription();

            sod.MasterVolume  = 0.9f;
            sod.DistanceScale = 200;
            engine.SetSoundMasterOptionDescription(ref sod);
        }
Example #5
0
        /// <summary>
        /// Loads the content.
        /// </summary>
        protected override void LoadContent()
        {
            // Instantiate a SpriteBatch
            spriteBatch = ToDisposeContent(new SpriteBatch(GraphicsDevice));

            arial16Font = Content.Load<SpriteFont>("Fonts/Arial16");
            camera = new Camera(this.GraphicsDevice, this.graphicsDeviceManager.PreferredBackBufferWidth, this.graphicsDeviceManager.PreferredBackBufferHeight, keyboard, mouse);
            shadowCamera = new ShadowCamera(this.graphicsDeviceManager.PreferredBackBufferWidth, this.graphicsDeviceManager.PreferredBackBufferHeight);

            gameCore = new GameCore(this.GraphicsDevice, this.Content, this.camera, this.shadowCamera, this.keyboard, this.mouse);

            terrain = new Terrain(this.gameCore);
            grass = new GrassController(this.gameCore);
            skyBox = new SkyBox(this.gameCore);
            base.LoadContent();
        }
Example #6
0
        // Load all the models and then reset game
        public void Load(ContentManager content)
        {
            // Camera shall be far of in the distance and focus on the left side of the grid
            _camera = new ChaseCamera(new Vector3(0, 2000, 4000), new Vector3(-1000, 0, 0), Vector3.Zero, gd);

            // The grid shall start at an area of 5
            _grid       = new Grid(5, 1, 200, content, gd);
            _snake      = new Snake(content, gd, _grid);
            _blob       = new Blob(content, gd, _grid);
            _background = new SkyBox(content, gd, content.Load <TextureCube>("Models/Background_0"));
            // Reset game (See line 308)
            ResetGame();

            // Load the font for the score text in the upper part of the screen
            mainFont = content.Load <SpriteFont>(@"Fonts/Main");
        }
Example #7
0
    /* Main Widget Init */
    protected virtual void OnGlwidgetInit(object sender, System.EventArgs e)
    {
        Trace.Listeners.Add(new TextWriterTraceListener("C:\\dupa.txt"));
        Trace.AutoFlush = true;

        GraphicsContext.ShareContexts = true;

        // open GL setup
        InitOrUpdateProjectionMatrix();

        GL.Enable(EnableCap.DepthTest);
        GL.Enable(EnableCap.CullFace);
        GL.CullFace(CullFaceMode.Back);

        /* In some cases, you might want to disable depth testing and still allow the depth buffer updated while you are rendering your objects.
         * It turns out that if you disable depth testing (glDisable(GL_DEPTH_TEST)​), GL also disables writes to the depth buffer.
         * The correct solution is to tell GL to ignore the depth test results with glDepthFunc(GL_ALWAYS)​.
         * Be careful because in this state, if you render a far away object last, the depth buffer will contain the values of that far object.
         */
        GL.DepthFunc(DepthFunction.Always);
        GL.ShadeModel(ShadingModel.Smooth);         //smooth or flat

        GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);

        // set background colour
        GL.ClearColor(backgroundColour[0], backgroundColour[1], backgroundColour[2], backgroundColour[3]);

        // setup the scene

        // init SkyBox
        skyBox = new SkyBox(50.0f);          //used with VBO
        InitScene();

        // init mouse
        mouse = new Mouse();

        if (vsync)
        {
            OpenTK.Graphics.GraphicsContext.CurrentContext.SwapInterval = 1;             //vsync enabled
        }
        else
        {
            OpenTK.Graphics.GraphicsContext.CurrentContext.SwapInterval = 0;             //vsync disabled
        }
        initted = true;
        Trace.WriteLine(OpenTK.Graphics.GraphicsContext.CurrentContext.GraphicsMode.ToString());
    }
Example #8
0
        public void Update(IUpdateArgs args, SkyBox skyRenderer)
        {
            var lightColor = new Color(245, 245, 225).ToVector3();

            var entities = Entities.Values.ToArray();

            foreach (var entity in entities)
            {
                if (entity.ModelRenderer != null)
                {
                    entity.ModelRenderer.DiffuseColor = (new Color(245, 245, 225).ToVector3() * ((1f / 16f) * entity.SurroundingLightValue))
                                                        * World.BrightnessModifier;
                }

                entity.Update(args);
            }
        }
Example #9
0
        /// <summary>
        /// Loads any component specific content
        /// </summary>
        protected override void LoadContent()
        {
            fSpriteBatch = new SpriteBatch(Game.GraphicsDevice);

            fModels = new List <Model>();
            foreach (string model in MODELS)
            {
                if (model.Contains("/"))
                {
                    fModels.Add(this.Game.Content.Load <Model>(model));
                }
                else
                {
                    fModels.Add(this.Game.Content.Load <Model>(String.Format("MyShader/{0}", model)));
                }
            }
            fShaders = new List <Effect>();
            foreach (string shader in SHADERS)
            {
                if (shader.Contains("*"))
                {
                    fShaders.Add(null);
                }
                else
                {
                    fShaders.Add(this.Game.Content.Load <Effect>(String.Format("MyShader/{0}", shader)));
                }
            }

            // Special
            fNormalMap = this.Game.Content.Load <Texture2D>("MyShader/HelicopterNormalMap");

            // SkyBox
            fSkyBoxTextures = new List <TextureCube>();
            foreach (string skybox in SKYBOXES)
            {
                fSkyBoxTextures.Add(this.Game.Content.Load <TextureCube>(String.Format("SkyBoxes/{0}", skybox)));
            }
            fSkyBox = new SkyBox(GraphicsDevice, fSkyBoxTextures[0], this.Game.Content, 5000f);

            InitializeTransform();
            InitializeEffect();


            base.LoadContent();
        }
        //setRoom1 creates a new room when the player runs through the previous door
        public void setRoom1( )
        {
            //remove critters and wall
            Biota.purgeCritters("cCritterWall");
            Biota.purgeCritters("cCritter3Dcharacter");

            setBorder(64.0f, 16.0f, 64.0f); // size of the world

            //create new room 'shell'
            cRealBox3 skeleton = new cRealBox3();

            skeleton.copy(_border);
            setSkyBox(skeleton);

            //set textures and graphics
            SkyBox.setSideTexture(cRealBox3.HIZ, BitmapRes.Wall3);    //Make the near HIZ transparent
            SkyBox.setSideTexture(cRealBox3.LOZ, BitmapRes.Wall3);    //Far wall
            SkyBox.setSideTexture(cRealBox3.LOX, BitmapRes.Wall3);    //left wall
            SkyBox.setSideTexture(cRealBox3.HIX, BitmapRes.Wall3);    //right wall
            SkyBox.setSideTexture(cRealBox3.LOY, BitmapRes.Concrete); //floor
            SkyBox.setSideTexture(cRealBox3.HIY, BitmapRes.Concrete); //ceiling

            //set number of critters to be created. Adjust numbers for increasing difficulty between rooms
            _seedcount = 7;

            WrapFlag = cCritter.BOUNCE;
            setPlayer(new cCritter3DPlayer(this));
            _ptreasure = new cCritterTreasure(this);

            //create a door at a new position in the room
            cCritterDoor pdwall = new cCritterDoor(
                new cVector3(_border.Lox, _border.Loy, _border.Midz),
                new cVector3(_border.Lox, _border.Midy - 3, _border.Midz),
                0.1f, 2, this);
            cSpriteTextureBox pspritedoor =
                new cSpriteTextureBox(pdwall.Skeleton, BitmapRes.Door);

            pdwall.Sprite = pspritedoor;

            //move player to new position in next room
            Player.moveTo(new cVector3(0.0f, -10.0f, 32.0f));

            //set collision flag and reset age of new room
            wentThrough  = true;
            startNewRoom = Age;
        }
Example #11
0
        protected override void LoadContent()
        {
            SpriteFont = Content.Load <SpriteFont>(ContentFolderSpriteFonts + "Arial");
            // Aca es donde deberiamos cargar todos los contenido necesarios antes de iniciar el juego.
            SpriteBatch = new SpriteBatch(GraphicsDevice);
            MatrixWorld = new List <Matrix>();
            // ObstaculoCubo = ObstaculoMovil.CrearObstaculoRecorridoCircular(Sphere, Matrix.CreateScale(0.1f, 0.1f, 0.1f) * Matrix.CreateRotationY(MathHelper.Pi) * Matrix.CreateTranslation(new Vector3(0, 13, -40)));
            LoadPhysics();
            generateMatrixWorld();
            Floor = new Floor(this);

            Sphere = Content.Load <Model>(ContentFolder3D + "geometries/sphere");

            GreenTexture = Content.Load <Texture2D>(ContentFolderTextures + "green");

            EnableDefaultLighting(Sphere);


            // Cargo un efecto basico propio declarado en el Content pipeline.
            // En el juego no pueden usar BasicEffect de MG, deben usar siempre efectos propios.
            Efecto = Content.Load <Effect>(ContentFolderEffects + "BasicShader");


            var skyBox        = Content.Load <Model>("3D/skybox/cube");
            var skyBoxTexture = Content.Load <TextureCube>(ContentFolderTextures + "skyboxes/skybox/skybox");
            var skyBoxEffect  = Content.Load <Effect>(ContentFolderEffects + "SkyBox");

            Skybox = new SkyBox(skyBox, skyBoxTexture, skyBoxEffect, Camera.FarPlane / 2);
            //Skybox = new SkyBox(skyBox, skyBoxTexture, skyBoxEffect, 1000);
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            SongName = "funkorama";
            Song     = Content.Load <Song>(ContentFolderMusic + SongName);
            MediaPlayer.Play(Song);
            // Asigno el efecto que cargue a cada parte del mesh.
            // Un modelo puede tener mas de 1 mesh internamente.
            //foreach (var mesh in Cube.Meshes)
            // Un mesh puede tener mas de 1 mesh part (cada 1 puede tener su propio efecto).
            //foreach (var meshPart in mesh.MeshParts)
            //  meshPart.Effect = Efecto;



            base.LoadContent();
        }
Example #12
0
        public void setTestRoom()
        {
            Biota.purgeCritters("cCritterWall");
            Biota.purgeCritters("cCritter3Dcharacter");
            setBorder(50.0f, 20.0f, 100.0f);
            cRealBox3 skeleton = new cRealBox3();

            skeleton.copy(_border);
            setSkyBox(skeleton);
            SkyBox.setSideTexture(cRealBox3.BOX_HIX, BitmapRes.Wood2);
            SkyBox.setSideTexture(cRealBox3.BOX_LOX, BitmapRes.Graphics2);
            SkyBox.setSideTexture(cRealBox3.BOX_HIY, BitmapRes.Sky);
            SkyBox.setSideTexture(cRealBox3.BOX_LOY, BitmapRes.Metal);
            SkyBox.setSideTexture(cRealBox3.BOX_HIZ, BitmapRes.Wall1);
            SkyBox.setSideTexture(cRealBox3.BOX_LOZ, BitmapRes.Graphics3);
            _seedcount = 0;
            Player.setMoveBox(new cRealBox3(50.0f, 20.0f, 100.0f));
        }
Example #13
0
        /// <summary>
        /// Init Screen
        /// </summary>
        /// <param name="GraphicInfo">The graphic info.</param>
        /// <param name="engine"></param>
        protected override void InitScreen(GraphicInfo GraphicInfo, EngineStuff engine)
        {
            base.InitScreen(GraphicInfo, engine);

            SkyBox skybox = new SkyBox();

            engine.AddComponent(skybox);

            ///Controls some master option of the engine sound player
            SoundMasterOptionDescription sod = engine.GetSoundMasterOptionDescription();

            ///between 0 and 1
            sod.MasterVolume = 0.9f;
            ///varies according to your game scale
            ///Used in 3D sounds
            sod.DistanceScale = 200;
            engine.SetSoundMasterOptionDescription(ref sod);
        }
Example #14
0
        public void Update(UpdateArgs args, SkyBox skyRenderer)
        {
            args.Camera = Camera;
            if (Player.FOVModifier != _fovModifier)
            {
                _fovModifier = Player.FOVModifier;

                Camera.FOV += _fovModifier;
                Camera.UpdateProjectionMatrix();
                Camera.FOV -= _fovModifier;
            }
            Camera.Update(args, Player);

            BrightnessMod = skyRenderer.BrightnessModifier;
            ChunkManager.Update(args);
            EntityManager.Update(args, skyRenderer);
            PhysicsEngine.Update(args.GameTime);

            var diffuseColor = Color.White.ToVector3() * BrightnessModifier;

            ChunkManager.AmbientLightColor = diffuseColor;

            Player.ModelRenderer.DiffuseColor = diffuseColor;
            Player.Update(args);

            if (Player.IsInWater)
            {
                ChunkManager.FogColor    = new Vector3(0.2666667F, 0.6862745F, 0.9607844F) * BrightnessModifier;
                ChunkManager.FogDistance = (float)Math.Pow(Options.VideoOptions.RenderDistance, 2) * 0.15f;
            }
            else
            {
                ChunkManager.FogColor    = skyRenderer.WorldFogColor.ToVector3();
                ChunkManager.FogDistance = (float)Math.Pow(Options.VideoOptions.RenderDistance, 2) * 0.8f;
            }

            if (Ticker.Update(args))
            {
                if (!FreezeWorldTime)
                {
                    WorldInfo.Time++;
                }
            }
        }
Example #15
0
        public void setRoom3()
        {
            Biota.purgeCritters("cCritterWall");
            Biota.purgeCritters("cCritter3Dcharacter");
            Biota.purgeCritters("cCritterBoss");
            setBorder(50.0f, 20.0f, 50.0f);
            cRealBox3 skeleton = new cRealBox3();

            skeleton.copy(_border);
            setSkyBox(skeleton);
            SkyBox.setAllSidesTexture(BitmapRes.Graphics3, 2);
            SkyBox.setSideTexture(cRealBox3.LOY, BitmapRes.Concrete);
            SkyBox.setSideSolidColor(cRealBox3.HIY, Color.Blue);
            _seedcount = 0;
            Player.setMoveBox(new cRealBox3(50.0f, 20.0f, 50.0f));

            wentThrough  = true;
            startNewRoom = Age;

            cCritterDoor pdwall = new cCritterDoor(
                new cVector3(_border.Midx, _border.Loy, _border.Loz),
                new cVector3(_border.Midx, _border.Midy - 3, _border.Loz),
                2.0f, 2, this);
            cSpriteTextureBox pspritedoor =
                new cSpriteTextureBox(pdwall.Skeleton, BitmapRes.Door);

            pdwall.Sprite = pspritedoor;

            float             height        = 0.1f * _border.YSize;
            float             ycenter       = -_border.YRadius + height / 2.0f;
            float             wallthickness = cGame3D.WALLTHICKNESS + 1.0f;
            cCritterSlideWall pwall         = new cCritterSlideWall(new cVector3(_border.Midx, ycenter - 10, _border.Midz + 10), new cVector3(_border.Hix + 50, ycenter - 10, _border.Midz + 10),
                                                                    height, wallthickness, this, cCritterSlideWall.TYPE.HARMFUL, new cVector3(0.0f, -0.05f, 0.0f), false, 200);
            cSpriteTextureBox pspritebox = new cSpriteTextureBox(pwall.Skeleton, BitmapRes.Wood2, 16);

            pwall.Sprite = pspritebox;

            seedCritters();

            _ptreasure = new cCritterMedpack(this, new cVector3(_border.Midx, _border.Midy - 2.0f,
                                                                _border.Loz - 1.5f * cGame3D.TREASURERADIUS));

            cCritterBossDragonKnight boss = new cCritterBossDragonKnight(this, new cVector3(_border.Midx, _border.Loy, _border.Midz - 5), new DragonBullet(1.0f));
        }
        public LabirynthGame(Game game)
        {
            keys        = new List <Key>();
            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                TextureEnabled         = true,
                World                  = Matrix.Identity,
                PreferPerPixelLighting = true
            };

            basicEffect.EnableDefaultLighting();
            basicEffect.DirectionalLight0.Enabled       = true;
            basicEffect.DirectionalLight0.SpecularColor = new Vector3(0, 0, 0);
            basicEffect.DirectionalLight1.Enabled       = true;
            basicEffect.DirectionalLight2.Enabled       = true;
            //basicEffect.AmbientLightColor = new Vector3(0.2f, 0.2f, 0.2f);
            //basicEffect.EmissiveColor = new Vector3(1, 0, 0);

            AssetHolder.Instance.GandalfMusicInstance.IsLooped    = true;
            AssetHolder.Instance.KeyPickupfMusicInstance.IsLooped = false;
            this.game      = game;
            gameManager    = (IGameManager)game.Services.GetService(typeof(IGameManager));
            screenManager  = (IScreenManager)game.Services.GetService(typeof(IScreenManager));
            controlManager = (IControlManager)game.Services.GetService(typeof(IControlManager));
            labirynth      = new LabirynthCreator(game);
            player         = new Player(new Vector3(), 2.0f, game);
            finish         = new Vector3();
            if (gameManager.Type == LabiryntType.Recursive)
            {
                CollisionChecker.Instance.Walls = labirynth.ModelMap;
            }
            else if (gameManager.Type == LabiryntType.Prim)
            {
                CollisionChecker.Instance.VertexWalls = labirynth.VertexMap;
            }

            skyBox      = new SkyBox(new Vector3((float)DifficultyLevel.Hard / 2, (float)DifficultyLevel.Hard / 2, 0), new Vector3(90, 0, 0), new Vector3(5f));
            finishPoint = new Finish(finish, game.GraphicsDevice, game);
            keys        = labirynth.GetKeys(gameManager.Type, game.GraphicsDevice, game);
            ground      = new Ground(game, labirynth.GroundMap);
            minimap     = new Minimap(labirynth.getMap(gameManager.Type), game, screenManager);
        }
Example #17
0
        public void Render(SBViewport viewport, float frame = 0)
        {
            if (IsActive && PropertyGrid.SelectedObject != null && PropertyGrid.SelectedObject is SBSurface surface)
            {
                OpenTK.Graphics.OpenGL.GL.Disable(OpenTK.Graphics.OpenGL.EnableCap.DepthTest);

                if (surface.IsCubeMap)
                {
                    SkyBox.RenderSkyBox(viewport.Camera, (TextureCubeMap)surface.GetRenderTexture(), MipLevel.Value);
                }
                else
                {
                    ScreenTriangle.RenderTexture(DefaultTextures.Instance.defaultWhite);

                    ScreenTriangle.RenderTexture(surface.GetRenderTexture(),
                                                 R.BackColor != Color.Gray, G.BackColor != Color.Gray, B.BackColor != Color.Gray, A.BackColor != Color.Gray,
                                                 MipLevel.Value, surface.IsSRGB);
                }
            }
        }
Example #18
0
        public MGLevel(SkyBox sb)
        {
            normal.textureEnabled   = false;
            normal.scrollingEnabled = false;

            for (int i = 0; i < sb.faces.Count; i++)
            {
                List <VertexPositionColorTexture> tri = new List <VertexPositionColorTexture>();
                tri.Add(DataConverter.ToVptc(sb.verts[sb.faces[i].X], new CTRFramework.Shared.Vector2b(0, 0), 0.01f));
                tri.Add(DataConverter.ToVptc(sb.verts[sb.faces[i].Y], new CTRFramework.Shared.Vector2b(0, 0), 0.01f));
                tri.Add(DataConverter.ToVptc(sb.verts[sb.faces[i].Z], new CTRFramework.Shared.Vector2b(0, 0), 0.01f));

                normal.PushTri(tri);
            }

            normal.Seal();

            wire = new TriList(normal);
            wire.SetColor(Color.Red);
        }
Example #19
0
        public void Load()
        {
            _camera = new Camera();
            _camera.PositionSpeed = 5;
            _camera.Move(_camera.Up, 400);
            _camera.Move(_camera.Backward, 1500);
            _camera.Move(_camera.Backward, 300);

            _skybox         = new SkyBox();
            _skybox.Scale.X = 10000;
            _skybox.Scale.Y = 10000;
            _skybox.Scale.Z = 10000;
            _skybox.Left    = TextureManager.Get("SkyboxLeft");
            _skybox.Right   = TextureManager.Get("SkyboxRight");
            _skybox.Front   = TextureManager.Get("SkyboxFront");
            _skybox.Back    = TextureManager.Get("SkyboxBack");
            _skybox.Top     = TextureManager.Get("SkyboxTop");

            _terrain             = StaticModelManager.GetModel("Terrain");
            _terrain.Scale       = new Vector <float>(500, 20, 500);
            _terrain.Orientation = new Quaternion <float>(0, 0, 0, 0);
            _terrain.Position    = new Vector <float>(0, 0, 0);

            _mountain             = StaticModelManager.GetModel("Mountain");
            _mountain.Scale       = new Vector <float>(5000, 5000, 5000);
            _mountain.Orientation = new Quaternion <float>(0, 0, 0, 0);
            _mountain.Position    = new Vector <float>(4000, 0, 1000);

            _mountain2             = StaticModelManager.GetModel("Mountain2");
            _mountain2.Scale       = new Vector <float>(3500, 3500, 3500);
            _mountain2.Orientation = new Quaternion <float>(0, 0, 0, 0);
            _mountain2.Position    = new Vector <float>(0, 0, 2500);

            GenerateUnits();

            Renderer.Font = TextManager.GetFont("Calibri");

            // ONCE YOU ARE DONE LOADING, BE SURE TO SET YOUR READY
            // PROPERTY TO TRUE SO MY ENGINE DOESN'T SCREAM AT YOU
            _isReady = true;
        }
        public cGame3D()
        {
            doorcollision = false;
            _menuflags   &= ~cGame.MENU_BOUNCEWRAP;
            _menuflags   |= cGame.MENU_HOPPER;           //Turn on hopper listener option.
            _spritetype   = cGame.ST_MESHSKIN;
            setBorder(64.0f, 16.0f, 64.0f);              // size of the world

            cRealBox3 skeleton = new cRealBox3();

            skeleton.copy(_border);
            setSkyBox(skeleton);

            /* In this world the coordinates are screwed up to match the screwed up
             * listener that I use.  I should fix the listener and the coords.
             * Meanwhile...
             * I am flying into the screen from HIZ towards LOZ, and
             * LOX below and HIX above and
             * LOY on the right and HIY on the left. */
            SkyBox.setSideTexture(cRealBox3.HIZ, BitmapRes.Wall3);    //Make the near HIZ transparent
            SkyBox.setSideTexture(cRealBox3.LOZ, BitmapRes.Wall3);    //Far wall
            SkyBox.setSideTexture(cRealBox3.LOX, BitmapRes.Wall3);    //left wall
            SkyBox.setSideTexture(cRealBox3.HIX, BitmapRes.Wall3);    //right wall
            SkyBox.setSideTexture(cRealBox3.LOY, BitmapRes.Concrete); //floor
            SkyBox.setSideTexture(cRealBox3.HIY, BitmapRes.Concrete); //ceiling

            WrapFlag   = cCritter.BOUNCE;
            _seedcount = 7;
            setPlayer(new cCritter3DPlayer(this));
            _ptreasure = new cCritterTreasure(this);

            cCritterDoor pdwall = new cCritterDoor(
                new cVector3(_border.Lox, _border.Loy, _border.Midz),
                new cVector3(_border.Lox, _border.Midy - 3, _border.Midz),
                0.1f, 2, this);
            cSpriteTextureBox pspritedoor =
                new cSpriteTextureBox(pdwall.Skeleton, BitmapRes.Door);

            pdwall.Sprite = pspritedoor;
        }
 public override void CreateGameObject(ObjectCreationRequest request)
 {
     if (request.ObjectType == typeof(Planet))
     {
         var item = new Planet(_idTally++, Bus);
         lock (GameObjectsLock)
         {
             GameObjects.Add(item);
         }
         Bus.Add(new ObjectCreated(request.TimeSent, item));
     }
     else if (request.ObjectType == typeof(SkyBox))
     {
         var item = new SkyBox(_idTally++, Bus);
         lock (GameObjectsLock)
         {
             GameObjects.Add(item);
         }
         Bus.Add(new ObjectCreated(request.TimeSent, item));
     }
     base.CreateGameObject(request);
 }
Example #22
0
        /// <summary>
        /// Génération de la Skybox.
        /// </summary>
        private void GenerateSkyBox()
        {
            if (_level.SkyboxType != SkyboxType.None)
            {
                string[] skyAssets;

                if (_level.SkyboxType == SkyboxType.Day)
                {
                    skyAssets = Assets.SkyboxLand;
                }
                else
                {
                    skyAssets = Assets.SkyboxNight;
                }

                _skybox = new SkyBox(Math.Max(_level.Width * _level.BlockSizes.Width, _level.Depth * _level.BlockSizes.Depth) * 4.5f, skyAssets);
                _skybox.LoadContent();
                _skybox.SetLightEnable(false);
                _skybox.Position = new Vector3((_level.Width * _level.BlockSizes.Width), 0, (_level.Depth * _level.BlockSizes.Depth));
                Add(_skybox);
            }
        }
        private void loadContent(PlanetParameters planetParams, ContentManager content)
        {
            this.planets = new List <Planet>();
            this.rings   = new List <PlanetRing>();

            VAO planetVao = content.GetVao("sphere");

            skybox = new SkyBox("content/textures/skybox");

            sun = new Sun("sun", planetParams, null, planetVao, content.getTexture("sun"));
            Planet mercury = new Planet("mercury", planetParams, sun, planetVao, content.getTexture("mercury"));
            Planet venus   = new Planet("venus", planetParams, sun, planetVao, content.getTexture("venus"));

            earth = new Earth("earth", planetParams, sun, planetVao, content.getTexture("earth"), content.getTexture("earth_spec"),
                              content.getTexture("earth_night"), content.getTexture("earth_normal"), content.getTexture("earth_clouds"));
            Planet moon    = new Planet("moon", planetParams, earth, planetVao, content.getTexture("moon"));
            Planet mars    = new Planet("mars", planetParams, sun, planetVao, content.getTexture("mars"));
            Planet jupiter = new Planet("jupiter", planetParams, sun, planetVao, content.getTexture("jupiter"));
            Planet saturn  = new Planet("saturn", planetParams, sun, planetVao, content.getTexture("saturn"));
            Planet uranus  = new Planet("uranus", planetParams, sun, planetVao, content.getTexture("uranus"));
            Planet neptune = new Planet("neptune", planetParams, sun, planetVao, content.getTexture("neptune"));
            Planet pluto   = new Planet("pluto", planetParams, sun, planetVao, content.getTexture("pluto"));

            //PlanetRing saturnRings = new PlanetRing(content.GetVao("saturnRings"), content.getTexture("saturnRings.png"), saturn);
            //PlanetRing uranusRings = new PlanetRing(content.GetVao("uranusRings"), content.getTexture("uranusRings.png"), uranus);

            planets.Add(mercury);
            planets.Add(venus);
            planets.Add(moon);
            planets.Add(mars);
            planets.Add(jupiter);
            planets.Add(saturn);
            planets.Add(uranus);
            planets.Add(neptune);
            planets.Add(pluto);

            //rings.Add(saturnRings);
            //rings.Add(uranusRings);
        }
Example #24
0
        public Color Integrate(Ray ray, IIntersectable objects, List <ILight> lights, ISampler sampler, List <List <Sample> > subPathSamples, LightSample lightSample)
        {
            scene        = objects;
            this.lights  = lights;
            this.sampler = sampler;
            HitRecord record = scene.Intersect(ray);

            if (record == null)
            {
                if (SkyBox.IsSkyBoxLoaded())
                {
                    return(SkyBox.GetSkyBoxColor(ray));
                }
                return(new Color(0, 0, 0));
            }

            if (record.HitObject.Light != null)
            {
                return(record.HitObject.Light.LightColor);
            }
            return(PathTrace(ray, record, subPathSamples, lightSample));
        }
Example #25
0
        public TextureScene()
        {
            FileName   = "Assignment4_Texture.jpg";
            Integrator = (IIntegrator)Activator.CreateInstance(Constants.Integrator);

            Texture back   = new Texture("./Textures/Skybox_stars/backmo.jpg", false);
            Texture bottom = new Texture("./Textures/Skybox_stars/botmo.jpg", false);
            Texture front  = new Texture("./Textures/Skybox_stars/frontmo.jpg", false);
            Texture left   = new Texture("./Textures/Skybox_stars/leftmo.jpg", false);
            Texture right  = new Texture("./Textures/Skybox_stars/rightmo.jpg", false);
            Texture top    = new Texture("./Textures/Skybox_stars/topmo.jpg", false);

            SkyBox.LoadSkybox(left, right, top, bottom, front, back);

            //List of objects
            //Sphere sphere = new Sphere(textureMaterial, new Vector3(0, 0, 0), .3f);
            ColladaParser parser = new ColladaParser();

            parser.ParseColladaFile("./geometries/collada/deathstar.dae", 1024);

            Camera = parser.Cameras.Values.First();
            Camera.PreProcess();

            Film = new Film(Camera.ScreenWidth, Camera.ScreenHeight);

            Objects = new IntersectableList();

            foreach (IIntersectable intersectable in parser.Meshes.Values)
            {
                Objects.Add(intersectable);
            }

            Lights = new List <ILight>();
            foreach (ILight light in parser.Lights.Values)
            {
                Lights.Add(light);
            }
        }
        public void setRoom1( )
        {
            Biota.purgeCritters <cCritterWall>();
            Biota.purgeCritters <cCritter3Dcharacter>();
            Biota.purgeCritters <cCritterShape>();
            setBorder(10.0f, 15.0f, 10.0f);
            cRealBox3 skeleton = new cRealBox3();

            skeleton.copy(_border);
            setSkyBox(skeleton);
            SkyBox.setAllSidesTexture(BitmapRes.Graphics1, 2);
            SkyBox.setSideTexture(cRealBox3.LOY, BitmapRes.Concrete);
            SkyBox.setSideSolidColor(cRealBox3.HIY, Color.Blue);
            _seedcount = 0;;;
            Player.setMoveBox(new cRealBox3(10.0f, 15.0f, 10.0f));
            float zpos                 = 0.0f; /* Point on the z axis where we set down the wall.  0 would be center,
                                                * halfway down the hall, but we can offset it if we like. */
            float        height        = 0.1f * _border.YSize;
            float        ycenter       = -_border.YRadius + height / 2.0f;
            float        wallthickness = cGame3D.WALLTHICKNESS;
            cCritterWall pwall         = new cCritterWall(
                new cVector3(_border.Midx + 2.0f, ycenter, zpos),
                new cVector3(_border.Hix, ycenter, zpos),
                height,        //thickness param for wall's dy which goes perpendicular to the
                //baseline established by the frist two args, up the screen
                wallthickness, //height argument for this wall's dz  goes into the screen
                this);
            cSpriteTextureBox pspritebox =
                new cSpriteTextureBox(pwall.Skeleton, BitmapRes.Wall3, 16); //Sets all sides

            /* We'll tile our sprites three times along the long sides, and on the
             * short ends, we'll only tile them once, so we reset these two. */

            pwall.Sprite = pspritebox;
            wentThrough  = true;
            startNewRoom = Age;
        }
        /// <summary>
        /// Loads the content.
        /// </summary>
        public void LoadContent()
        {
            ////this.castles = new Castle[Ballerburg.Gameplay.Constants.NumCastles];
              castles[0] = contentManager.Castle1;
              castles[1] = contentManager.Castle2;
              castles[2] = contentManager.Castle3;
              castles[3] = contentManager.Castle4;
              castles[4] = contentManager.Castle5;
              castles[5] = contentManager.Castle6;
              castles[6] = contentManager.Castle7;
              castles[7] = contentManager.Castle8;

              // Init the cannonball array
              this.activeCannonballs = new Cannonball[MaxCannonBalls];
              for (var i = 0; i < MaxCannonBalls; i++)
              {
            activeCannonballs[i] = new Cannonball(contentManager);
              }

              skyBox = contentManager.SkyBox;

              terrain = new Terrain(contentManager, graphicsDevice);

              explosionBillboard = new AnimatedBillboard(false, contentManager);
              explosionBillboard.LoadContent();
              explosionBillboard.InitGraphics(graphicsDevice.GraphicsDevice);

              explosionBillboard.PrepareAnimation();
              explosionBillboard.Pause();
        }
Example #28
0
 public void setSkyBox(SkyBox skyBox)
 {
     this.skyBox = skyBox;
 }
        // AIR does not yet show anything. why

        public ApplicationSprite()
        {
            //        curityError: Error #2148: SWF file file:///X|/jsc.svn/examples/actionscript/synergy/Flare3DWaterShips/Flare3DWaterShips/bin/Debug/staging/Flare3DWaterShips.ApplicationSprite/web/Flare3DWaterShips.ApplicationSprite.swf cannot access local resource file:///X|/jsc.svn/examples/actionscript/synergy/Flare3DWaterShips/Flare3DWaterShips/bin/Debug/staging/Flare3DWaterShips.ApplicationSprite/web/Flare3DWaterShips.ApplicationSprite.swf/[[DYNAMIC]]/3. Only local-with-filesystem and trusted local SWF files may access local resources.
            //at flash.display::Loader/get content()
            //at flare.core::Texture3D/completeEvent()[Z:\projects\flare3d 2.5\src\flare\core\Texture3D.as:496]


            var scene = new Viewer3D(this, "", 0.2);
            scene.camera = new Camera3D();
            scene.camera.setPosition(120, 40, -30);
            scene.camera.lookAt(0, 0, 0);

            #region mirrorCam
            var mirrorCam = new Camera3D();
            var mirror = new Texture3D(new Point(512, 512));
            mirror.mipMode = Texture3D.MIP_NONE;
            mirror.wrapMode = Texture3D.WRAP_CLAMP;
            mirror.upload(scene);
            #endregion


            #region oceanShader
            var Ocean = KnownEmbeddedResources.Default["assets/Flare3DWaterShips/ocean07.flsl.compiled"];
            var oceanShader = new FLSLMaterial("oceanShader", Ocean.ToByteArrayAsset());
            var oceanShader_params = oceanShader.@params as dynamic;

            // http://www.flare3d.com/docs/flare/core/Texture3D.html
            // http://wiki.flare3d.com/index.php?title=FLAR_Toolkit_integration
            oceanShader_params.skyMap.value = new Texture3D(
                KnownEmbeddedResources.Default[
                "assets/Flare3DWaterShips/highlights.png"
                ].ToBitmapAsset(), false, Texture3D.FORMAT_CUBEMAP);
            oceanShader_params.normalMap.value = new Texture3D(
                KnownEmbeddedResources.Default["assets/Flare3DWaterShips/normalmap.jpg"].ToBitmapAsset());
            oceanShader_params.mirrorMap.value = mirror;
            #endregion

            // http://www.flare3d.com/support/index.php?topic=142.0

            var water = new Plane("water", 3000, 3000, oceanGridSize - 1, oceanShader, "+xz");
            var skybox = new SkyBox(

                KnownEmbeddedResources.Default["assets/Flare3DWaterShips/skybox.png"].ToBitmapAsset(), SkyBox.HORIZONTAL_CROSS, null, 1);

            // http://www.flare3d.com/support/index.php?topic=63.0
            // http://www.flare3d.com/docs/tutorials/loadFromBytes/
            var ship0 = new Flare3DWaterShipComponent.ship();

            // how to make it safe to provide 3rd party assetslibrary builder
            // code templates? which can be selected by KnownEmbeddedResources pattern match?
            // class XFileTemplate<T> where T like foo "*.zf3d"

            var ship1 = new Flare3DWaterShipComponent.ship();
            ship1.x = 40;
            ship1.y = 10;

            var particles = new particles();

            #region initWaves():
            var bytes = new ByteArray();
            bytes.endian = Endian.LITTLE_ENDIAN;
            bytes.length = oceanGridSize * oceanGridSize * 12; // 4 btyes * RGB = 12.

            // http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/ShaderData.html
            //   public static class ShaderData
            //   {
            //       public ShaderData(ByteArray byteCode);
            //   }


            var PBWater = KnownEmbeddedResources.Default["assets/Flare3DWaterShips/water.pbj"];
            var shader = new Shader(PBWater.ToByteArrayAsset());
            var shader_data = shader.data as dynamic;

            shader_data.src.input = bmp;

            var surf = new Surface3D("data");

            // http://www.flare3d.com/docs/flare/core/Surface3D.html
            //     public override int addVertexData(uint dataIndex, int size = -1, Vector<double> vector = null);
            surf.addVertexData(dataIndex: (uint)Surface3D.COLOR0, size: 3);
            surf.vertexBytes = bytes;
            surf.upload(scene);

            water.surfaces[0].sources[Surface3D.COLOR0] = surf;
            #endregion

            ship0.addChild(particles);

            scene.addChild(skybox);
            scene.addChild(water);
            scene.addChild(ship0);
            scene.addChild(ship1);

            var st = new Stopwatch();
            st.Start();

            ship1.setScale(2, 2, 2);

            scene.addEventListener(Scene3D.RENDER_EVENT,

                listener: new Action<Event>(
                    delegate
                    {
                        // render the big waves.
                        #region  renderWaves()
                        {
                            var timer = st.ElapsedMilliseconds;
                            point0.y = timer / 400;
                            point1.y = timer / 640;

                            // flash natives: apply params?
                            bmp.perlinNoise(3, 3, 2, 0, false, true, 7, true, new[] { point0, point1 });

                            var job = new ShaderJob(shader, bytes, oceanGridSize, oceanGridSize);
                            //job.addEventListener( ShaderEvent.COMPLETE, shaderCompleteEvent, false, 0, true );
                            job.complete +=
                                delegate
                                {
                                    if (surf.vertexBuffer != null)
                                        surf.vertexBuffer.uploadFromByteArray(bytes, 0, 0, oceanGridSize * oceanGridSize);
                                };

                            job.start();
                        }
                        #endregion

                        // copy from the main camera and invert in Y axis.
                        mirrorCam.copyTransformFrom(scene.camera);
                        mirrorCam.transform.appendScale(1, -1, 1);

                        // setup the mirror cam to start rendering on the mirror texture.
                        scene.setupFrame(mirrorCam);
                        scene.context.setRenderToTexture(mirror.texture, true);
                        scene.context.clear(0, 0, 0, 0);

                        // get the pixel color height.
                        var color = bmp.getPixel(oceanGridSize / 2, oceanGridSize / 2) & 0xff;

                        // ! .0 marks it as double. otherwise ship will digitally step on water
                        var height = color / 255.0 * 20 + 1;

                        // draw objects into the mirror texture.
                        ship0.y = -height;
                        ship0.draw();
                        ship0.y = height;

                        ship1.z = st.ElapsedMilliseconds * 0.001 - 100;

                        ship1.y = -height;
                        ship1.draw();
                        ship1.y = height;


                        // get back to the main render.
                        scene.context.setRenderToBackBuffer();
                        scene.setupFrame(scene.camera);
                    }
                ).ToFunction()
            );

            // http://www.flare3d.com/support/index.php?topic=1101.0
            this.addChild(new net.hires.debug.Stats());

        }
Example #30
0
        public void LoadLevel(string fileName)
        {
            // Set fade in effect
            GraphicEffect.FadeIn();
            CleanScene();
            var scenesToLoad = new Dictionary <string, bool>();

            string sceneFile = string.Empty;

            if (File.Exists(fileName))
            {
                sceneFile = fileName;
            }
            else if (File.Exists(Path.Combine(Application.StartupPath, fileName)))
            {
                sceneFile = Path.Combine(Application.StartupPath, fileName);
            }

            // First add scene file since we will generate mini map from it.
            scenesToLoad.Add(sceneFile, true);
            // Add global.xml if it exists.
            var globalScene = Path.Combine(new FileInfo(sceneFile).Directory.FullName, "global.xml");

            if (File.Exists(globalScene))
            {
                scenesToLoad.Add(globalScene, false);
            }

            foreach (var scene in scenesToLoad)
            {
                var xDoc = XDocument.Load(scene.Key);

                #region Mesh
                var meshQuery = from e in xDoc.Descendants("Objects")
                                from i in e.Descendants("Object")
                                where Helpers.GetBool(i.Element("IsAnimated").Value) == false
                                select new
                {
                    Name            = i.Element("Name").Value,
                    FileName        = i.Element("FileName").Value,
                    Visible         = Helpers.GetBool(i.Element("Visible").Value),
                    Position        = Helpers.GetVector3D(i.Element("Position").Value),
                    Rotation        = Helpers.GetVector3D(i.Element("Rotation").Value),
                    Scale           = Helpers.GetVector3D(i.Element("Scale").Value),
                    Mass            = Helpers.GetFloat(i.Element("Mass").Value),
                    StaticFriction  = Helpers.GetFloat(i.Element("StaticFriction").Value),
                    KineticFriction = Helpers.GetFloat(i.Element("KineticFriction").Value),
                    Softness        = Helpers.GetFloat(i.Element("Softness").Value),
                    Bounciness      = Helpers.GetFloat(i.Element("Bounciness").Value),
                    Bounding        = Helpers.GetBoundingType(i.Element("Bounding").Value),
                    ScriptEnabled   = Helpers.GetBool(i.Descendants("CustomScript").Select(p => p.Element("Enabled")).FirstOrDefault().Value),
                    Script          = i.Descendants("CustomScript").Select(p => p.Element("Script")).FirstOrDefault().Value,
                    Parameters      = i.Descendants("CustomParameters").Descendants("Parameter").ToList()
                };

                foreach (var e in meshQuery)
                {
                    var entity = new Mesh(Core)
                    {
                        Name            = e.Name,
                        FileName        = e.FileName,
                        Visible         = e.Visible,
                        Position        = e.Position,
                        Rotation        = e.Rotation,
                        Scale           = e.Scale,
                        Mass            = e.Mass,
                        StaticFriction  = e.StaticFriction,
                        KineticFriction = e.KineticFriction,
                        Softness        = e.Softness,
                        Bounciness      = e.Bounciness,
                        Bounding        = e.Bounding,
                        ScriptEnabled   = e.ScriptEnabled,
                        Script          = e.Script
                    };

                    SetCustomParameters(entity, e.Parameters);

                    Core.LoadComponent <Mesh>(entity);
                    gameObjects.Add(entity);
                }
                #endregion

                #region Trigger
                var triggerQuery = from e in xDoc.Descendants("Triggers")
                                   from i in e.Descendants("Trigger")
                                   select new
                {
                    Name          = i.Element("Name").Value,
                    Position      = Helpers.GetVector3D(i.Element("Position").Value),
                    Rotation      = Helpers.GetVector3D(i.Element("Rotation").Value),
                    Scale         = Helpers.GetVector3D(i.Element("Scale").Value),
                    Color         = Helpers.GetVector3D(i.Element("Color").Value),
                    ScriptEnabled = Helpers.GetBool(i.Descendants("CustomScript").Select(p => p.Element("Enabled")).FirstOrDefault().Value),
                    Script        = i.Descendants("CustomScript").Select(p => p.Element("Script")).FirstOrDefault().Value,
                    Parameters    = i.Descendants("CustomParameters").Descendants("Parameter").ToList()
                };

                foreach (var e in triggerQuery)
                {
                    var entity = new Trigger(Core)
                    {
                        Name          = e.Name,
                        Position      = e.Position,
                        Rotation      = e.Rotation,
                        Scale         = e.Scale,
                        Color         = Globals.RGBA(e.Color.x / 255f, e.Color.y / 255f, e.Color.z / 255f, 1),
                        ScriptEnabled = e.ScriptEnabled,
                        Script        = e.Script
                    };

                    SetCustomParameters(entity, e.Parameters);

                    Core.LoadComponent <Trigger>(entity);
                    gameObjects.Add(entity);
                }
                #endregion

                #region DirectionalLight
                var directionalLightQuery = from e in xDoc.Descendants("Lights")
                                            from i in e.Descendants("Directional")
                                            where Helpers.GetBool(i.Element("Visible").Value) == true
                                            select new
                {
                    Name          = i.Element("Name").Value,
                    Direction     = Helpers.GetVector3D(i.Element("Direction").Value),
                    Color         = Helpers.GetVector3D(i.Element("Color").Value),
                    ScriptEnabled = Helpers.GetBool(i.Descendants("CustomScript").Select(p => p.Element("Enabled")).FirstOrDefault().Value),
                    Script        = i.Descendants("CustomScript").Select(p => p.Element("Script")).FirstOrDefault().Value,
                    Parameters    = i.Descendants("CustomParameters").Descendants("Parameter").ToList()
                };

                foreach (var e in directionalLightQuery)
                {
                    var entity = new DirectionalLight(Core)
                    {
                        Name          = e.Name,
                        Direction     = e.Direction,
                        Color         = System.Drawing.Color.FromArgb((int)e.Color.x, (int)e.Color.y, (int)e.Color.z),
                        ScriptEnabled = e.ScriptEnabled,
                        Script        = e.Script
                    };

                    SetCustomParameters(entity, e.Parameters);

                    Core.LoadComponent <DirectionalLight>(entity);
                    gameObjects.Add(entity);
                }
                #endregion

                #region PointLight
                var pointLightQuery = from e in xDoc.Descendants("Lights")
                                      from i in e.Descendants("Point")
                                      where Helpers.GetBool(i.Element("Visible").Value) == true
                                      select new
                {
                    Name          = i.Element("Name").Value,
                    Position      = Helpers.GetVector3D(i.Element("Position").Value),
                    Radius        = Helpers.GetFloat(i.Element("Radius").Value),
                    Color         = Helpers.GetVector3D(i.Element("Color").Value),
                    ScriptEnabled = Helpers.GetBool(i.Descendants("CustomScript").Select(p => p.Element("Enabled")).FirstOrDefault().Value),
                    Script        = i.Descendants("CustomScript").Select(p => p.Element("Script")).FirstOrDefault().Value,
                    Parameters    = i.Descendants("CustomParameters").Descendants("Parameter").ToList()
                };

                foreach (var e in pointLightQuery)
                {
                    var entity = new PointLight(Core)
                    {
                        Name          = e.Name,
                        Position      = e.Position,
                        Radius        = e.Radius,
                        Color         = System.Drawing.Color.FromArgb((int)e.Color.x, (int)e.Color.y, (int)e.Color.z),
                        ScriptEnabled = e.ScriptEnabled,
                        Script        = e.Script
                    };

                    SetCustomParameters(entity, e.Parameters);

                    Core.LoadComponent <PointLight>(entity);
                    gameObjects.Add(entity);
                }
                #endregion

                #region Particle
                var particleQuery = from e in xDoc.Descendants("Particles")
                                    from i in e.Descendants("Particle")
                                    select new
                {
                    Name          = i.Element("Name").Value,
                    FileName      = i.Element("FileName").Value,
                    Position      = Helpers.GetVector3D(i.Element("Position").Value),
                    Rotation      = Helpers.GetVector3D(i.Element("Rotation").Value),
                    Scale         = Helpers.GetVector3D(i.Element("Scale").Value),
                    Visible       = Helpers.GetBool(i.Element("Visible").Value),
                    ScriptEnabled = Helpers.GetBool(i.Descendants("CustomScript").Select(p => p.Element("Enabled")).FirstOrDefault().Value),
                    Script        = i.Descendants("CustomScript").Select(p => p.Element("Script")).FirstOrDefault().Value,
                    Parameters    = i.Descendants("CustomParameters").Descendants("Parameter").ToList()
                };

                foreach (var e in particleQuery)
                {
                    var entity = new Particle(Core)
                    {
                        Name          = e.Name,
                        FileName      = e.FileName,
                        Position      = e.Position,
                        Rotation      = e.Rotation,
                        Scale         = e.Scale,
                        Visible       = e.Visible,
                        ScriptEnabled = e.ScriptEnabled,
                        Script        = e.Script
                    };

                    SetCustomParameters(entity, e.Parameters);

                    Core.LoadComponent <Particle>(entity);
                    gameObjects.Add(entity);
                }
                #endregion

                #region Sound
                var soundQuery = from e in xDoc.Descendants("Sounds")
                                 from i in e.Descendants("Sound")
                                 select new
                {
                    Name          = i.Element("Name").Value,
                    FileName      = i.Element("FileName").Value,
                    Position      = Helpers.GetVector3D(i.Element("Position").Value),
                    Volume        = Helpers.GetFloat(i.Element("Volume").Value),
                    Stopped       = Helpers.GetBool(i.Element("Stopped").Value),
                    Loop          = Helpers.GetBool(i.Element("Loop").Value),
                    Is3D          = Helpers.GetBool(i.Element("Is3D").Value),
                    ScriptEnabled = Helpers.GetBool(i.Descendants("CustomScript").Select(p => p.Element("Enabled")).FirstOrDefault().Value),
                    Script        = i.Descendants("CustomScript").Select(p => p.Element("Script")).FirstOrDefault().Value,
                    Parameters    = i.Descendants("CustomParameters").Descendants("Parameter").ToList()
                };

                foreach (var e in soundQuery)
                {
                    var entity = new Sound(Core)
                    {
                        Name          = e.Name,
                        FileName      = e.FileName,
                        Position      = e.Position,
                        Volume        = e.Volume * Helpers.GameSettings.FXVolume / 100f,
                        Stopped       = e.Stopped,
                        Loop          = e.Loop,
                        Is3D          = e.Is3D,
                        ScriptEnabled = e.ScriptEnabled,
                        Script        = e.Script
                    };

                    SetCustomParameters(entity, e.Parameters);

                    Core.LoadComponent <Sound>(entity);
                    gameObjects.Add(entity);
                }
                #endregion

                #region SkySphere
                var skySphereQuery = from e in xDoc.Descendants("Sky")
                                     from i in e.Descendants("SkySphere")
                                     select new
                {
                    Rotation      = Helpers.GetVector3D(i.Element("Rotation").Value),
                    Scale         = Helpers.GetVector3D(i.Element("Scale").Value),
                    PolyCount     = Helpers.GetInt(i.Element("PolyCount").Value),
                    FileName      = i.Element("Texture").Value,
                    ScriptEnabled = Helpers.GetBool(i.Descendants("CustomScript").Select(p => p.Element("Enabled")).FirstOrDefault().Value),
                    Script        = i.Descendants("CustomScript").Select(p => p.Element("Script")).FirstOrDefault().Value,
                    Parameters    = i.Descendants("CustomParameters").Descendants("Parameter").ToList()
                };

                foreach (var e in skySphereQuery)
                {
                    var entity = new SkySphere(Core)
                    {
                        Rotation      = e.Rotation,
                        Scale         = e.Scale,
                        PolyCount     = e.PolyCount,
                        FileName      = e.FileName,
                        ScriptEnabled = e.ScriptEnabled,
                        Script        = e.Script
                    };

                    SetCustomParameters(entity, e.Parameters);

                    Core.LoadComponent <SkySphere>(entity);
                    gameObjects.Add(entity);
                }
                #endregion

                #region SkyBox
                var skyBoxQuery = from e in xDoc.Descendants("Sky")
                                  from i in e.Descendants("SkyBox")
                                  select new
                {
                    FrontTexture  = i.Element("FrontTexture").Value,
                    BackTexture   = i.Element("BackTexture").Value,
                    LeftTexture   = i.Element("LeftTexture").Value,
                    RightTexture  = i.Element("RightTexture").Value,
                    TopTexture    = i.Element("TopTexture").Value,
                    BottomTexture = i.Element("BottomTexture").Value,
                    ScriptEnabled = Helpers.GetBool(i.Descendants("CustomScript").Select(p => p.Element("Enabled")).FirstOrDefault().Value),
                    Script        = i.Descendants("CustomScript").Select(p => p.Element("Script")).FirstOrDefault().Value,
                    Parameters    = i.Descendants("CustomParameters").Descendants("Parameter").ToList()
                };

                foreach (var e in skyBoxQuery)
                {
                    var entity = new SkyBox(Core)
                    {
                        FrontTexture  = e.FrontTexture,
                        BackTexture   = e.BackTexture,
                        LeftTexture   = e.LeftTexture,
                        RightTexture  = e.RightTexture,
                        TopTexture    = e.TopTexture,
                        BottomTexture = e.BottomTexture,
                        ScriptEnabled = e.ScriptEnabled,
                        Script        = e.Script
                    };

                    SetCustomParameters(entity, e.Parameters);

                    Core.LoadComponent <SkyBox>(entity);
                    gameObjects.Add(entity);
                }
                #endregion

                #region Water
                var waterQuery = from e in xDoc.Descendants("WaterPlanes")
                                 from i in e.Descendants("Water")
                                 select new
                {
                    Position      = Helpers.GetVector3D(i.Element("Position").Value),
                    Scale         = Helpers.GetVector3D(i.Element("Scale").Value),
                    ScriptEnabled = Helpers.GetBool(i.Descendants("CustomScript").Select(p => p.Element("Enabled")).FirstOrDefault().Value),
                    Script        = i.Descendants("CustomScript").Select(p => p.Element("Script")).FirstOrDefault().Value,
                    Parameters    = i.Descendants("CustomParameters").Descendants("Parameter").ToList()
                };

                foreach (var e in waterQuery)
                {
                    var entity = new Water(Core)
                    {
                        Position      = e.Position,
                        Scale         = e.Scale,
                        ScriptEnabled = e.ScriptEnabled,
                        Script        = e.Script
                    };

                    SetCustomParameters(entity, e.Parameters);

                    Core.LoadComponent <Water>(entity);
                    gameObjects.Add(entity);
                }
                #endregion

                // Generate minimap for scene file (not global).
                if (scene.Value == true)
                {
                    var fi        = new FileInfo(scene.Key);
                    var imageFile = Path.Combine(fi.DirectoryName, fi.Name.Replace(fi.Extension, ".png"));
                    //if (!File.Exists(imageFile))
                    {
                        var minimap = Helpers.CreateMinimap(gameObjects);
                        minimap.Save(imageFile, ImageFormat.Png);
                        minimap.Dispose();
                    }
                }

                // Get some information about the scene.
                skySphereExist = gameObjects.FindAll(o => o.GetType().Equals(typeof(SkySphere))).Count > 0;
                skyBoxExist    = gameObjects.FindAll(o => o.GetType().Equals(typeof(SkyBox))).Count > 0;
                waterExists    = Helpers.GetGameObjects <Water>(gameObjects).Count > 0;
            }
        }
Example #31
0
        public World(IServiceProvider serviceProvider, GraphicsDevice graphics, AlexOptions options, Camera camera,
                     INetworkProvider networkProvider)
        {
            Graphics = graphics;
            Camera   = camera;
            Options  = options;

            PhysicsEngine = new PhysicsManager(this);
            ChunkManager  = new ChunkManager(serviceProvider, graphics, this);
            EntityManager = new EntityManager(graphics, this, networkProvider);
            Ticker        = new TickManager();
            PlayerList    = new PlayerList();

            ChunkManager.Start();
            var settings       = serviceProvider.GetRequiredService <IOptionsProvider>();
            var profileService = serviceProvider.GetRequiredService <IPlayerProfileService>();
            var resources      = serviceProvider.GetRequiredService <ResourceManager>();

            EventDispatcher = serviceProvider.GetRequiredService <IEventDispatcher>();

            string username = string.Empty;
            Skin   skin     = profileService?.CurrentProfile?.Skin;

            if (skin == null)
            {
                resources.ResourcePack.TryGetBitmap("entity/alex", out var rawTexture);
                var t = TextureUtils.BitmapToTexture2D(graphics, rawTexture);
                skin = new Skin()
                {
                    Texture = t,
                    Slim    = true
                };
            }

            if (!string.IsNullOrWhiteSpace(profileService?.CurrentProfile?.Username))
            {
                username = profileService.CurrentProfile.Username;
            }

            Player = new Player(graphics, serviceProvider.GetRequiredService <Alex>().InputManager, username, this, skin, networkProvider, PlayerIndex.One, camera);

            Player.KnownPosition = new PlayerLocation(GetSpawnPoint());
            Camera.MoveTo(Player.KnownPosition, Vector3.Zero);

            Options.FieldOfVision.ValueChanged += FieldOfVisionOnValueChanged;
            Camera.FOV = Options.FieldOfVision.Value;

            PhysicsEngine.AddTickable(Player);

            if (networkProvider is BedrockClient)
            {
                Player.SetInventory(new BedrockInventory(46));
            }
            //	Player.Inventory.IsPeInventory = true;

            /*if (ItemFactory.TryGetItem("minecraft:diamond_sword", out var sword))
             * {
             *      Player.Inventory[Player.Inventory.SelectedSlot] = sword;
             *      Player.Inventory.MainHand = sword;
             * }
             * else
             * {
             *      Log.Warn($"Could not get diamond sword!");
             * }*/

            EventDispatcher.RegisterEvents(this);

            FormManager = new BedrockFormManager(networkProvider, serviceProvider.GetRequiredService <GuiManager>(), serviceProvider.GetService <Alex>().InputManager);

            SkyRenderer = new SkyBox(serviceProvider, graphics, this);
            //SkyLightCalculations = new SkyLightCalculations();

            UseDepthMap = options.VideoOptions.Depthmap;
            options.VideoOptions.Depthmap.Bind((old, newValue) => { UseDepthMap = newValue; });

            ServerType = (networkProvider is BedrockClient) ? ServerType.Bedrock : ServerType.Java;
        }
        public cGame3D()
        {
            doorcollision = false;
            _menuflags   &= ~cGame.MENU_BOUNCEWRAP;
            _menuflags   |= cGame.MENU_HOPPER;           //Turn on hopper listener option.
            _spritetype   = cGame.ST_MESHSKIN;
            setBorder(64.0f, 16.0f, 64.0f);              // size of the world

            cRealBox3 skeleton = new cRealBox3();

            skeleton.copy(_border);
            setSkyBox(skeleton);

            /* In this world the coordinates are screwed up to match the screwed up
             * listener that I use.  I should fix the listener and the coords.
             * Meanwhile...
             * I am flying into the screen from HIZ towards LOZ, and
             * LOX below and HIX above and
             * LOY on the right and HIY on the left. */
            SkyBox.setSideSolidColor(cRealBox3.HIZ, Color.Aqua);        //Make the near HIZ transparent
            SkyBox.setSideSolidColor(cRealBox3.LOZ, Color.Aqua);        //Far wall
            SkyBox.setSideSolidColor(cRealBox3.LOX, Color.DarkOrchid);  //left wall
            SkyBox.setSideTexture(cRealBox3.HIX, BitmapRes.Wall2, 2);   //right wall
            SkyBox.setSideTexture(cRealBox3.LOY, BitmapRes.Graphics3);  //floor
            SkyBox.setSideTexture(cRealBox3.HIY, BitmapRes.Sky);        //ceiling

            WrapFlag   = cCritter.BOUNCE;
            _seedcount = 7;
            setPlayer(new cCritter3DPlayer(this));
            _ptreasure   = new cCritterTreasure(this);
            shape        = new cCritterShape(this);
            shape.Sprite = new cSphere(3, Color.DarkBlue);
            shape.moveTo(new cVector3(Border.Midx, Border.Hiy, Border.Midz));

            /* In this world the x and y go left and up respectively, while z comes out of the screen.
             * A wall views its "thickness" as in the y direction, which is up here, and its
             * "height" as in the z direction, which is into the screen. */
            //First draw a wall with dy height resting on the bottom of the world.
            float zpos                 = 0.0f; /* Point on the z axis where we set down the wall.  0 would be center,
                                                * halfway down the hall, but we can offset it if we like. */
            float        height        = 0.1f * _border.YSize;
            float        ycenter       = -_border.YRadius + height / 2.0f;
            float        wallthickness = cGame3D.WALLTHICKNESS;
            cCritterWall pwall         = new cCritterWall(
                new cVector3(_border.Midx + 2.0f, ycenter, zpos),
                new cVector3(_border.Hix, ycenter, zpos),
                height,                 //thickness param for wall's dy which goes perpendicular to the
                                        //baseline established by the frist two args, up the screen
                wallthickness,          //height argument for this wall's dz  goes into the screen
                this);
            cSpriteTextureBox pspritebox =
                new cSpriteTextureBox(pwall.Skeleton, BitmapRes.Wall3, 16);                   //Sets all sides

            /* We'll tile our sprites three times along the long sides, and on the
             * short ends, we'll only tile them once, so we reset these two. */

            pwall.Sprite = pspritebox;


            //Then draw a ramp to the top of the wall.  Scoot it over against the right wall.
            float planckwidth = 0.75f * height;

            pwall = new cCritterWall(
                new cVector3(_border.Hix - planckwidth / 2.0f, _border.Loy, _border.Hiz - 2.0f),
                new cVector3(_border.Hix - planckwidth / 2.0f, _border.Loy + height, zpos),
                planckwidth,                 //thickness param for wall's dy which is perpenedicualr to the baseline,
                                             //which goes into the screen, so thickness goes to the right
                wallthickness,               //_border.zradius(),  //height argument for wall's dz which goes into the screen
                this);
            cSpriteTextureBox stb = new cSpriteTextureBox(pwall.Skeleton,
                                                          BitmapRes.Wood2, 2);

            pwall.Sprite = stb;

            cCritterDoor pdwall = new cCritterDoor(
                new cVector3(_border.Lox, _border.Loy, _border.Midz),
                new cVector3(_border.Lox, _border.Midy - 3, _border.Midz),
                0.1f, 2, this);
            cSpriteTextureBox pspritedoor =
                new cSpriteTextureBox(pdwall.Skeleton, BitmapRes.Door);

            pdwall.Sprite = pspritedoor;
        }
Example #33
0
        private void CreateObjects()
        {
            texture1 = TextureLoader.LoadTexture2D(Resources.GreenTexture);
            texture2 = TextureLoader.LoadTexture2D(Resources.RockTexture);
            Texture skyBoxTexture1 = TextureLoader.LoadCubeMap(Resources.SkyCubeMapTextures);
            Texture TreeTexture    = TextureLoader.LoadTexture2D(Resources.TreeTexture);

            ///Terain
            terrain = new Terrain(Resources.MountainsHeightMap)
            {
                Texture = texture1,
            };
            float TerrainLength = 300f;
            float TerrainHeight = 20f;

            terrain.ScaleObject(new Vector3(TerrainLength, TerrainLength, TerrainHeight));
            terrain.Pitch(-MathHelper.PiOver2);


            ///FirstAircraft
            aircraft                   = new Aircraft();
            aircraft.Speed             = 0.6f;
            aircraft.HumanControlSpeed = 20f;
            aircraft.ScaleObject(100f);
            aircraft.RotateByY(MathHelper.PiOver2);
            aircraft.RotateByZ(MathHelper.PiOver2);
            aircraft.Translate(Vector3.UnitX);
            aircraft.Semimajor = 50f;
            aircraft.Semiminor = 50f;
            aircraft.Translate(aircraft.Up * 8f);
            aircraft.EllipseY = aircraft.Position.Y;

            Sphere sphere = new Sphere(20);

            sphere.ScaleObject(5);
            sphere.Color            = Vector3.UnitX;
            sphere.SpecularExponent = 10f;
            sphere.SetPosition(new Vector3(-50f, 8f, 50f));
            sphere.InitalPosition = sphere.Position;

            Sphere sphere2 = new Sphere(20);

            sphere2.ScaleObject(5);
            sphere2.Color            = Vector3.UnitY;
            sphere2.SpecularExponent = 500f;
            sphere2.SetPosition(new Vector3(50f, 8f, 50f));
            sphere2.InitalPosition = sphere2.Position;

            Cube cube = new Cube();

            cube.Color            = Vector3.One;
            cube.SpecularExponent = 1f;
            cube.ScaleObject(new Vector3(1.2f, 10f, 1.2f));
            cube.SetPosition(new Vector3(60f, 5f, 0f));

            Sphere sphere3 = new Sphere(20);

            sphere3.ScaleObject(5);
            sphere3.Color            = Vector3.UnitY;
            sphere3.SpecularExponent = 1000f;
            sphere3.Translate(cube.Position);
            sphere3.Translate(cube.Up * (cube.Scale.Y + 4.5f));
            sphere3.InitalPosition = sphere3.Position;

            SkyBox skybox = new SkyBox(TerrainLength);

            skybox.Texture = skyBoxTexture1;

            ///RenderObjects
            renderObjects.Add(terrain);
            renderObjects.Add(aircraft);

            for (int i = 0; i < 500; i++)
            {
                Tree tree = new Tree();
                tree.Texture = TreeTexture;
                float X = rnd.Next(2 * (int)TerrainLength);
                X -= TerrainLength / 2;
                X *= 2;
                float Z = rnd.Next(2 * (int)TerrainLength);
                Z -= TerrainLength / 2;
                Z *= 2;
                tree.SetPosition(new Vector3(X, 2f, Z));
                renderObjects.Add(tree);
            }

            renderObjects.Add(sphere);
            renderObjects.Add(sphere2);
            renderObjects.Add(cube);
            renderObjects.Add(sphere3);

            ///render last
            renderObjects.Add(skybox);

            /* MovingCamera moveCamera = new MovingCamera()
             * {
             *   CameraPosition = new Vector3(-2.2f, 45.8f, 90.39f),
             *   MoveSpeed = 1.5f
             * };*/

            Camera staticCamera = new Camera()
            {
                CameraPosition = new Vector3(30f, 51.8f, -71.13f)
            };

            Camera staticFollowCamera = new StaticFollowCamera(aircraft)
            {
                CameraPosition = new Vector3(0f, 20f, 10f)
            };

            Camera staticFollowCamera2 = new Camera()
            {
                CameraPosition = new Vector3(sphere.Position.X, sphere.Position.Y + 15f, sphere.Position.Z - 20),
            };

            staticFollowCamera2.CameraTarget = sphere.Position;

            BehindCamera behindCamera = new BehindCamera(aircraft)
            {
                Dist  = 20f,
                Angle = MathHelper.PiOver6
            };

            //Cameras
            //cameras.Add(moveCamera);

            cameras.Add(staticCamera);
            cameras.Add(staticFollowCamera);
            cameras.Add(staticFollowCamera2);
            cameras.Add(behindCamera);

            cameras[activeCameraIndex].IsActive = true;

            //Lights
            Light light = new Light()
            {
                Position          = 50f * Vector3.UnitY,
                Color             = Vector3.One,
                LightType         = LightTypes.PointLight,
                AmbientIntensity  = 0.1f,
                DiffuseIntensity  = 0.8f,
                SpecularIntensity = 0.1f,
            };

            light.Direction = (Vector3.Zero - light.Position).Normalized();
            lights.Add(light);
            lights.AddRange(aircraft.Light);
        }