Exemplo n.º 1
0
        public static void ComponentTest()
        {
            XEngineComponentTest testGame = new XEngineComponentTest();

            ScenegraphManager scenegraph = new ScenegraphManager( testGame ); ;
            Entity entity1 = null;
            Entity entity2 = null;
            Entity entity3 = null;
            testGame.InitDelegate = delegate {
                scenegraph.Initialize();

                entity1 = new Entity();
                PrimitiveRenderComponent.AddTestComponent( entity1, GeometricPrimitiveType.Sphere, 1.0f);
                MoveComponent.AddTestComponent( entity1 );
                entity1.Initialize();
                scenegraph.AddEntity( entity1, null );

                entity2 = new Entity();
                PrimitiveRenderComponent.AddTestComponent( entity2, GeometricPrimitiveType.Cube, 1.0f );
                entity2.Initialize();
                Transform transform2 = entity2.GetAttribute<Transform>( Attributes.TRANSFORM );
                transform2.Position = new Vector3( 0, 1.0f, 0 );
                transform2.Rotation = Matrix.CreateRotationY( MathHelper.PiOver4 );
                transform2.Scale = new Vector3( 0.5f );
                scenegraph.AddEntity( entity2, entity1 );

                entity3 = new Entity();
                PrimitiveRenderComponent.AddTestComponent( entity3, GeometricPrimitiveType.Cube, 1.0f );
                entity3.Initialize();
                Transform transform3 = entity3.GetAttribute<Transform>( Attributes.TRANSFORM );
                transform3.Position = new Vector3( 1.5f, 0, 0 );
                scenegraph.AddEntity( entity3, entity2 );

            };
            testGame.UpdateDelegate = delegate( GameTime gameTime ) {
                entity1.Update( gameTime );
                entity2.Update( gameTime );
                entity3.Update( gameTime );
                scenegraph.Update( gameTime );
            };
            testGame.DrawDelegate = delegate( GameTime gameTime ) {
                entity1.Draw( gameTime );
                entity2.Draw( gameTime );
                entity3.Draw( gameTime );
            };
            testGame.Run();
        }
Exemplo n.º 2
0
        protected override void Initialize()
        {
            if ( m_setupDefaultComponents ) {

                // Initialize Camera
                Camera camera = new Camera( this );
                this.Components.Add( camera );
                ServiceLocator.Camera = camera;

                // Initialize InputManager
                InputManager inputManager = new InputManager( this );
                this.Components.Add( inputManager );
                ServiceLocator.InputManager = inputManager;

                // Initialize CameraController
                this.Components.Add( CameraController.Factory( m_cameraType, this) );

                // Initialize EntityManager
                EntityManager entityManager = new EntityManager( this );
                this.Components.Add( entityManager );
                ServiceLocator.EntityManager = entityManager;

                // Initialize Scenegraph
                ScenegraphManager scenegraph = new ScenegraphManager( this );
                this.Components.Add( scenegraph );
                ServiceLocator.ScenegraphManager = scenegraph;

                // Initialize DebugHUD
                DebugHUD debugHUD = new DebugHUD( this );
                this.Components.Add( new DebugHUD( this ) );

                // Initialize SettingsManager
                ServiceLocator.SettingsManager = new SettingsManager();
            }

            base.Initialize();

            if (m_initDelegate != null) {
                m_initDelegate();
            }
        }