public override void Update(Timer timer)
        {
            Entity[] entities = GetEntities();

            SingletonConfigVar  configVar  = WorldRef.GetSingletonComponent <SingletonConfigVar>();
            SingletonInput      input      = WorldRef.GetSingletonComponent <SingletonInput>();
            SingletonFrameScene frameScene = WorldRef.GetSingletonComponent <SingletonFrameScene>();

            frameScene.FrameData.Reset();

            Transform transform;
            Camera    camera;

            foreach (var entity in entities)
            {
                camera    = entity.GetComponent <Camera>();
                transform = entity.GetComponent <Transform>();

                UpdateCamera(timer.DeltaTime, camera, transform, input, configVar);
                frameScene.FrameData.AddCameraData(new StandardFrameData.CameraData()
                {
                    View                   = camera.View,
                    Projection             = camera.Projection,
                    ViewProjection         = camera.ViewProjection,
                    PreviousView           = camera.PreviousView,
                    PreviousViewProjection = camera.PreviousViewProjection,
                    Position               = transform.Position,
                    Forward                = transform.Direction,
                    Frustrum               = new BoundingFrustum(camera.ViewProjection),
                });
            }
        }
Beispiel #2
0
 public override void PreUpdate(GameTime time)
 {
     if (WorldRef == null)
     {
         return;
     }
     physicsBodies = WorldRef.GetAllWithComponent(typeof(PhysicsBody));
 }
        public override void Update(Timer timer)
        {
            SingletonInput input = WorldRef.GetSingletonComponent <SingletonInput>();

            Entity[] entities = GetEntities();

            Transform     transform;
            TestComponent test;

            foreach (Entity entity in entities)
            {
                test = entity.GetComponent <TestComponent>();

                /* if (input.IsButtonDown(SingletonInput.Buttons.LEFT))
                 * {
                 *   test.HorizontalDirection = -1;
                 * }
                 * if (input.IsButtonDown(SingletonInput.Buttons.RIGHT))
                 * {
                 *   test.HorizontalDirection = 1;
                 * }
                 *
                 * if (input.IsButtonDown(SingletonInput.Buttons.DOWN))
                 * {
                 *   test.VerticalDirection = -1;
                 * }
                 * if (input.IsButtonDown(SingletonInput.Buttons.UP))
                 * {
                 *   test.VerticalDirection = 1;
                 * }*/

                transform           = entity.GetComponent <Transform>();
                transform.Rotation *= Quaternion.RotationYawPitchRoll(timer.DeltaTime * test.HorizontalDirection, 0, 0);//timer.DeltaTime * test.VerticalDirection
                //transform.Scale = Vector3.One * ((float)Math.Sin(timer.Time * 3f) * 0.05f + 0.2f);
                transform.Position += (Vector3.ForwardLH + Vector3.Left) * 4 * (float)Math.Cos(timer.Time) * 0.01f;
            }
        }
Beispiel #4
0
 public override void PreUpdate(GameTime time)
 {
     player = WorldRef.GetFirstWithComponent(typeof(Player));
 }
        public override void Update(Timer timer)
        {
            Entity[]            entities   = GetEntities();
            SingletonFrameScene frameScene = WorldRef.GetSingletonComponent <SingletonFrameScene>();

            Transform transform;
            Light     light;

            entities = entities.OrderBy(a => a.GetComponent <Light>().Type).ToArray();

            int            index = 0;
            bool           culled;
            BoundingSphere boundingSphere;

            foreach (var entity in entities)
            {
                culled    = true;
                transform = entity.GetComponent <Transform>();
                light     = entity.GetComponent <Light>();

                foreach (var camera in frameScene.FrameData.CamerasList)
                {
                    boundingSphere = new BoundingSphere(transform.Position, light.Radius * 2);
                    if (light.Type != Light.LightType.Directional && !camera.Frustrum.Intersects(ref boundingSphere))
                    {
                        continue;
                    }
                    culled = false;
                    frameScene.FrameData.AddLightDataToCamera(camera.index, index);
                }

                if (culled)
                {
                    continue;
                }

                if (light.IsCastShadows)
                {
                    light.ViewProjection = Matrix.LookAtLH(
                        transform.Position,
                        transform.Position + transform.Direction,
                        Vector3.Up
                        );
                    //light.ViewProjection *= Matrix.PerspectiveFovLH(MathUtil.PiOverTwo, 1.0f, 0.01f, 10000f);
                    light.ViewProjection *= Matrix.OrthoLH(110f, 110f, 0.5f, 300f);
                }

                frameScene.FrameData.AddLightData(new StandardFrameData.LightData()
                {
                    Type           = light.Type,
                    Radius         = light.Radius,
                    IsCastShadows  = light.IsCastShadows,
                    ViewProjection = light.ViewProjection,
                    Frustrum       = new BoundingFrustum(light.ViewProjection),
                    Position       = transform.Position,
                    Direction      = transform.Direction,
                    Color          = light.Color,
                    Intensity      = light.Intensity,
                });
                index++;
            }
        }
Beispiel #6
0
        public override void Update(Timer timer)
        {
            SingletonFrameScene frameScene = WorldRef.GetSingletonComponent <SingletonFrameScene>();

            Transform transform;
            Renderer  renderer;

            //TODO: faster ordering optimization

            /*Entity[] entities = GetEntities();
             * entities = entities.OrderBy(a => a.GetComponent<Renderer>().materialInfo.Queue)
             *      .ThenBy(a => a.GetComponent<Renderer>().materialInfo.Name)
             *      .ThenBy(a => a.GetComponent<Renderer>().meshInfo.Name).ToArray();*/

            int  index = 0;
            bool culled;

            foreach (Entity entity in SortedByRendererEntities)
            {
                culled = true;

                transform = entity.GetComponent <Transform>();
                renderer  = entity.GetComponent <Renderer>();

                renderer.Bounds = BoundsBox.TransformAABBFast(renderer.meshInfo.Bounds, transform.TransformMatrix);

                foreach (var camera in frameScene.FrameData.CamerasList)
                {
                    if (camera.Frustrum.Intersects(ref renderer.Bounds.boundingBox))
                    {
                        culled = false;
                        frameScene.FrameData.AddRendererDataToCamera(camera.index, index);
                    }
                }

                foreach (var light in frameScene.FrameData.LightsList)
                {
                    if (!light.IsCastShadows)
                    {
                        continue;
                    }
                    if (light.Frustrum.Intersects(ref renderer.Bounds.boundingBox))
                    {
                        culled = false;
                        frameScene.FrameData.AddRendererDataToLight(light.index, index);
                    }
                }

                if (culled)
                {
                    continue;
                }

                frameScene.FrameData.AddRendererData(new StandardFrameData.RendererData()
                {
                    EntityId = entity.ID,
                    PreviousTransformMatrix = transform.PreviousTransformMatrix,
                    TransformMatrix         = transform.TransformMatrix,
                    MeshName      = renderer.meshInfo.Name,
                    MaterialName  = renderer.materialInfo.Name,
                    MaterialQueue = renderer.materialInfo.Queue,
                    IsDynamic     = renderer.IsDynamic,
                });
                index++;
            }
        }