Ejemplo n.º 1
0
        public override void UpdateEntity(int entity)
        {
            CPosition  position  = (CPosition)positions[entity];
            CDimension dimension = (CDimension)dimensions[entity];

            partitioner.Insert(new PartitionerEntry(entity, position, dimension));
        }
Ejemplo n.º 2
0
        private void Integrate(CPosition position, CKinetic kinetic, Integrator integrator, float deltaTime)
        {
            switch (integrator)
            {
            case Integrator.SemiImplictEuler:
                SemiImplictEulerIntegration();
                break;

            case Integrator.VelocityVerlet:
                VelocityVerletIntegration();
                break;
            }

            void SemiImplictEulerIntegration()
            {
                kinetic.Velocity += kinetic.Acceleration * deltaTime;

                position.X += kinetic.Velocity.X * deltaTime;
                position.Y += kinetic.Velocity.Y * deltaTime;
            }

            void VelocityVerletIntegration()
            {
                position.X += kinetic.Velocity.X * deltaTime + 0.5f * kinetic.Acceleration.X * deltaTime * deltaTime;
                position.Y += kinetic.Velocity.Y * deltaTime + 0.5f * kinetic.Acceleration.Y * deltaTime * deltaTime;

                kinetic.Velocity += kinetic.Acceleration * deltaTime;
            }
        }
Ejemplo n.º 3
0
        public override void UpdateEntity(int entity)
        {
            CPosition  position  = (CPosition)positions[entity];
            CDimension dimension = (CDimension)dimensions[entity];
            CTransform transform = (CTransform)transforms[entity];
            CColor     color     = (CColor)colors[entity];

            vertexBuffer[entity] = new VertexTransformColor(position, dimension, transform, color);
        }
Ejemplo n.º 4
0
        public override void UpdateEntity(int entity)
        {
            CPosition  position  = (CPosition)positions[entity];
            CDimension dimension = (CDimension)dimensions[entity];
            CTransform transform = (CTransform)transforms[entity];

            List <int> queryResult = binPartitioner.Query(CreateQueryBounds());

            if (queryResult.Count == 0)
            {
                return;
            }

            SchemaShape2D collisionInformation = SchemaShape2DHelper.CreateShapeSchema(CBoxColliderHelper.ShapeData, position, dimension, transform);
            Shape         shape = new Shape(collisionInformation);

            SchemaShape2D theirCollisionInformation;
            Shape         theirShape;
            CPosition     theirPosition;
            CDimension    theirDimension;
            CTransform    theirTransform;

            for (int i = 0; i < queryResult.Count; i++)
            {
                if (!scene.EntityContains(queryResult[i], typeof(CTransform), typeof(CBoxCollider)))
                {
                    continue;
                }

                if (entity == queryResult[i])
                {
                    continue;
                }

                theirPosition  = (CPosition)positions[queryResult[i]];
                theirDimension = (CDimension)dimensions[queryResult[i]];
                theirTransform = (CTransform)transforms[queryResult[i]];

                theirCollisionInformation = SchemaShape2DHelper.CreateShapeSchema(CBoxColliderHelper.ShapeData, theirPosition, theirDimension, theirTransform);
                theirShape = new Shape(theirCollisionInformation);

                ProcessResolution(CollisionHelper.GetResolution(shape, theirShape));
            }

            RectangleF CreateQueryBounds()
            {
                return(new RectangleF(position.X - queryBuffer, position.Y - queryBuffer, dimension.Width + queryBuffer * 2, dimension.Height + queryBuffer * 2));
            }

            void ProcessResolution(Vector2 resolution)
            {
                position.X += resolution.X;
                position.Y += resolution.Y;
            }
        }
Ejemplo n.º 5
0
        private void Simultate(int entity)
        {
            CPosition position = (CPosition)positions[entity];
            CKinetic  kinetic  = (CKinetic)kinetics[entity];

            kinetic.Accumulator += (float)(Engine.TotalGameTime - kinetic.LastUpdate).TotalSeconds;
            kinetic.LastUpdate   = new TimeSpan(Engine.TotalGameTime.Ticks);

            while (kinetic.Accumulator >= target)
            {
                Integrate(position, kinetic, integrator, target);
                kinetic.Accumulator -= target;
            }
        }
Ejemplo n.º 6
0
 public PartitionerEntry(int entity, CPosition position, CDimension dimension)
 {
     Identifier = entity;
     Bounds     = new RectangleF(position.X, position.Y, dimension.Width, dimension.Height);
 }