Пример #1
0
        public void Motion(ComponentTransform pos, ComponentRigidbody vel)
        {
            Vector3 currentPos = pos.Position;
            Vector3 velocity   = vel.Velocity;

            pos.PhysicsMove(currentPos + velocity * TimeManager.dt);
        }
Пример #2
0
        public void OnAction(Entity entity, float dt)
        {
            if ((entity.Mask & MASK) == MASK)
            {
                List <IComponent> components = entity.Components;

                //gets the transform of the tower to extract the transform so I can do maths in tower space
                IComponent transfromComponent = components.Find(delegate(IComponent component)
                {
                    return(component.ComponentType == ComponentTypes.COMPONENT_TRANSFORM);
                });
                ComponentTransform transform = (ComponentTransform)transfromComponent;

                Vector3 position = transform.Position;
                Vector3 rotation = transform.Rotation;
                Vector3 scale    = transform.Scale;

                Matrix4 modelMatrix = Matrix4.CreateScale(scale) *
                                      Matrix4.CreateRotationX(rotation.X) *
                                      Matrix4.CreateRotationY(rotation.Y) *
                                      Matrix4.CreateRotationZ(rotation.Z) *
                                      Matrix4.CreateTranslation(position);

                UpdateBoxCollsion(modelMatrix);
            }
        }
Пример #3
0
        public void Update(GameTime gameTime)
        {
            ComponentTransform temp     = _entityManager.GetEntity("testEntity").GetComponent <ComponentTransform>();
            ComponentPhysics   tempPhys = _entityManager.GetEntity("testEntity").GetComponent <ComponentPhysics>();

            //Vector2 tempPos = ((MouseInput.CurrentPos - temp.GetPos()).Normalized().MultiplyLength(100.0).MultiplyLength(gameTime.ElapsedGameTime.TotalSeconds));


            if (MouseInput.CheckLeftPressed())
            {
                temp.Pos = MouseInput.CurrentPos;
            }

            if (KeyboardInput.CheckIsKeyDown(Keys.A))
            {
                tempPhys.AddVelocity(new Vector2(-20.0f, 0.0f));
            }
            if (KeyboardInput.CheckIsKeyDown(Keys.D))
            {
                tempPhys.AddVelocity(new Vector2(20.0f, 0.0f));
            }
            if (KeyboardInput.CheckIsKeyDown(Keys.Space))
            {
                tempPhys.AddVelocity(new Vector2(0.0f, -30.0f));
            }

            _entityManager.Update(gameTime);

            if (KeyboardInput.CheckIsPressed(Keys.Escape))
            {
                Game1.State = State.MAIN_MENU;
            }
        }
Пример #4
0
        public void OnAction(Entity entity)
        {
            if ((entity.Mask & MASK) == MASK)
            {
                ComponentGeometry geometryComponent = (ComponentGeometry)entity.FindComponent(ComponentTypes.COMPONENT_GEOMETRY);
                Geometry          geometry          = geometryComponent.Geometry();

                ComponentTransform transformComponent = (ComponentTransform)entity.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
                //Vector3 position = transformComponent.Position;
                //Vector3 scale = transformComponent.Scale;
                //Vector3 rotation = transformComponent.Rotation;

                //Matrix4 translateMatrix = Matrix4.CreateTranslation(position);
                //Matrix4 scaleMatrix = Matrix4.CreateScale(scale);
                //Matrix4 xRotMatrix = Matrix4.CreateRotationX(rotation.X);
                //Matrix4 yRotMatrix = Matrix4.CreateRotationY(rotation.Y);
                //Matrix4 zRotMatrix = Matrix4.CreateRotationZ(rotation.Z);
                //Matrix4 rotMatrix = xRotMatrix * yRotMatrix * zRotMatrix;

                //Matrix4 world = rotMatrix * scaleMatrix * translateMatrix;
                Matrix4 world = transformComponent.Transform;

                ComponentTexture textureComponent = (ComponentTexture)entity.FindComponent(ComponentTypes.COMPONENT_TEXTURE);
                int texture = textureComponent.Texture;

                Draw(world, geometry, texture);
            }
        }
Пример #5
0
        /// <summary>
        /// Checks if the player is in the FOV of the drone
        /// </summary>
        /// <param name="ai"> the ai component of this entity </param>
        /// <param name="transform"> the transform component of this entity </param>
        /// <returns> true if the player is in the drones FOV </returns>
        private bool PlayerInFOV(ComponentAI ai, ComponentTransform transform)
        {
            //Finds the direction from the drone to the player
            Vector3 direction = (player.GetTransform().Translation - transform.Translation).Normalized();
            //Finds the angle between the target direction and the agent forward vector
            float angle = (float)(Math.Atan2(direction.X, direction.Z) - Math.Atan2(transform.Forward.X, transform.Forward.Z));

            //if the angle is over 180 in either direction then invert it to be a smaller angle in the opposite direction
            if (angle > Math.PI)
            {
                angle -= (float)(2 * Math.PI);
            }
            if (angle < -Math.PI)
            {
                angle += (float)(2 * Math.PI);
            }

            angle = MathHelper.RadiansToDegrees(angle);

            //if the player is in sight return true
            if (angle < ai.FOV && angle > -angle)
            {
                //Console.WriteLine("player spotted");
                return(true);
            }
            return(false);
        }
Пример #6
0
        private void RespondPlayerGhost(Entity player, Entity ghost)
        {
            //Debug.WriteLine("collision between player and ghost");

            //if ghost is chasing
            {
                //play ghost sound
                ComponentTransform ghostTransform = (ComponentTransform)ghost.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
                ComponentAudio     ghostAudio     = (ComponentAudio)ghost.FindComponent(ComponentTypes.COMPONENT_AUDIO);

                Vector3 emitterPosition = (ghostTransform).Position;
                int     source          = (ghostAudio).Source;

                AL.Source(source, ALSource3f.Position, ref emitterPosition);

                ghostAudio.Play();

                //kill player
                ComponentLives livesComponent = (ComponentLives)player.FindComponent(ComponentTypes.COMPONENT_LIVES);
                livesComponent.Lives -= 1;

                ComponentTransform transformComponent = (ComponentTransform)player.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
                transformComponent.Position = new Vector3(0, 1, 2);
                ComponentMovement movementComponent = (ComponentMovement)player.FindComponent(ComponentTypes.COMPONENT_MOVEMENT);
                movementComponent.DesiredLocation = new Vector3(0, 1, 2);
            }
            //else if ghost is fleeing
            //kill ghost
            //add 100 points to player
        }
Пример #7
0
        private bool CircleSquareCheck(Entity circle, Entity square)
        {
            //square
            ComponentTransform    squareTransformComponent = (ComponentTransform)square.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
            ComponentCollisionBox collisionBoxComponent    = (ComponentCollisionBox)square.FindComponent(ComponentTypes.COMPONENT_COLLISION_BOX);
            Matrix4 squareTransform = squareTransformComponent.Transform;
            Vector4 point1          = squareTransform * new Vector4(collisionBoxComponent.Point1, 1);
            Vector4 point2          = squareTransform * new Vector4(collisionBoxComponent.Point2.X, point1.Y, point1.Z, 1);
            Vector4 point3          = squareTransform * new Vector4(point1.X, point1.Y, collisionBoxComponent.Point2.Z, 1);
            Vector4 point4          = squareTransform * new Vector4(collisionBoxComponent.Point2, 1);

            Vector3[] points = { point1.Xyz, point2.Xyz, point3.Xyz, point4.Xyz };

            //circle
            ComponentTransform       circleTransformComponent = (ComponentTransform)circle.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
            ComponentCollisionCircle collisionCircleComponent = (ComponentCollisionCircle)circle.FindComponent(ComponentTypes.COMPONENT_COLLISION_CIRCLE);
            Vector3 circlePosition = circleTransformComponent.Position;
            float   radius         = collisionCircleComponent.Radius * circleTransformComponent.Scale.X;

            //WARNING: radius scales off of X, not the largest scalar

            return(IsPointInPolygon(points, circlePosition) ||
                   IsIntersectingCircle(circlePosition, radius, point1.Xyz, point2.Xyz) ||
                   IsIntersectingCircle(circlePosition, radius, point2.Xyz, point3.Xyz) ||
                   IsIntersectingCircle(circlePosition, radius, point3.Xyz, point4.Xyz) ||
                   IsIntersectingCircle(circlePosition, radius, point4.Xyz, point1.Xyz));
        }
Пример #8
0
        private void RespondPlayerFood(Entity player, Entity food)
        {
            //play food sound
            ComponentTransform foodTransform = (ComponentTransform)food.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
            ComponentAudio     foodAudio     = (ComponentAudio)food.FindComponent(ComponentTypes.COMPONENT_AUDIO);

            Vector3 emitterPosition = (foodTransform).Position;
            int     source          = (foodAudio).Source;

            AL.Source(source, ALSource3f.Position, ref emitterPosition);

            foodAudio.Play();

            //increase the score
            ComponentScore scoreComponent = (ComponentScore)player.FindComponent(ComponentTypes.COMPONENT_SCORE);
            float          score          = scoreComponent.Score;

            ComponentValue valueComponent = (ComponentValue)food.FindComponent(ComponentTypes.COMPONENT_VALUE);
            float          value          = valueComponent.Value;

            score += value;

            scoreComponent.Score = score;
            food.Enabled         = false;
        }
Пример #9
0
        public void OnAnimate(ComponentAnimation animation, Vector3 position, ComponentTransform transform)
        {
            Matrix4 mat = Matrix4.CreateRotationX(animation.AnimateRotation.X * animation.Speed);

            mat *= Matrix4.CreateRotationY(animation.AnimateRotation.Y * animation.Speed);
            mat *= Matrix4.CreateRotationZ(animation.AnimateRotation.Z * animation.Speed);
            transform.Transform *= mat;
        }
Пример #10
0
        /// <summary>
        /// Each entity MUST have a Transform component
        /// </summary>
        /// <param name="name"></param>
        public Entity(string name)
        {
            this.name = name;

            // add the default transform component
            transform = new ComponentTransform();
            componentList.Add(transform);
            mask |= transform.ComponentType;
        }
Пример #11
0
        public override void OnAction(Entity entity)
        {
            var allComponents = entity.Components;

            ComponentTransform pos = entity.Transform;
            ComponentRigidbody vel = entity.GetComponent <ComponentRigidbody>();

            Motion(pos, vel);
        }
Пример #12
0
        /// <summary>
        /// Works out which 1x1 unit tiles of the map can be walked on by the AI
        /// </summary>
        void CalculateTraversableTiles()
        {
            // This method works in a similar idea to battleships to set units in the
            // 2D grid to say if something is there or not, in this case it will be true if its clear, false if its blocked
            //Entity[] test = Collidables;
            for (int x = 0; x < Traversable.GetLength(0); x++)
            {
                for (int z = 0; z < Traversable.GetLength(1); z++)
                {
                    Traversable[x, z] = true;
                }
            }

            foreach (Entity entity in Collidables)
            {
                ComponentTransform t = (ComponentTransform)entity.Components.Find(delegate(IComponent component)
                {
                    return(component.ComponentType == ComponentTypes.COMPONENT_TRANSFORM);
                });
                ComponentPosition p = (ComponentPosition)entity.Components.Find(delegate(IComponent component)
                {
                    return(component.ComponentType == ComponentTypes.COMPONENT_POSITION);
                });

                // Works out position of each entity and the starting point of the shape (e.g. position is centra of entity)
                Vector3 scale = new Vector3(t.Transform.ExtractScale().X, 0.0f, t.Transform.ExtractScale().Z);
                Vector3 start = new Vector3((p.Position.X - (scale.X)), 0.0f, (p.Position.Z - (scale.Z)));
                // Offset changes from world coords to grid coords (e.g. a 50x50 world would centre at 0,0 but grid centre would be 25,25)
                int xOffset = (int)start.X + (mWidth / 2);
                int zOffset = (int)start.Z + (mHeight / 2);

                if (!(xOffset >= Traversable.GetLength(0)) && !(zOffset > Traversable.GetLength(1)) && !(xOffset < 0) && !(zOffset < 0))
                {
                    // This sets units where a collidable entity is to false to say the AI cannot traverse this unit
                    for (int x = xOffset; x < (xOffset + t.Transform.ExtractScale().X * 2); x++)
                    {
                        for (int z = zOffset; z < (zOffset + t.Transform.ExtractScale().Z * 2); z++)
                        {
                            float xSize = (Traversable.GetLength(0)) - 2;
                            float zSize = (Traversable.GetLength(1)) - 2;

                            xSize++;
                            zSize++;
                            if (!(x <= 0) && !(x >= xSize) && !(z <= 0) && !(z >= zSize))
                            {
                                // This creates the cube for AI to avoid apposed to avoid just a single vertex
                                Traversable[z, x + 1]     = false;
                                Traversable[z + 1, x]     = false;
                                Traversable[z + 1, x + 1] = false;
                            }
                            Traversable[z, x] = false;
                        }
                    }
                }
            }
        }
        private void UpdateCylinder(ComponentCollsion collsionComp, Matrix4 cylinderMatrix)
        {
            for (int i = 0; i < m_EntityList.Count; i++)
            {
                List <IComponent> components        = m_EntityList[i].Components;
                IComponent        CylinderCollision = components.Find(delegate(IComponent component)
                {
                    return(component.ComponentType == ComponentTypes.COMPONENT_CYLINDERCOLLSION);
                });
                if (CylinderCollision != null)
                {
                    IComponent SphereTransfrom = components.Find(delegate(IComponent component)
                    {
                        return(component.ComponentType == ComponentTypes.COMPONENT_TRANSFORM);
                    });
                    ComponentTransform sphere         = (ComponentTransform)SphereTransfrom;
                    Vector3            spherePosition = sphere.Position;

                    IComponent physicsComp = components.Find(delegate(IComponent component)
                    {
                        return(component.ComponentType == ComponentTypes.COMPONENT_PHYSICS);
                    });
                    ComponentPhysics spherePhys = (ComponentPhysics)physicsComp;



                    Vector3 circleInCollsionSpace = Vector3.TransformPosition(spherePosition, cylinderMatrix.Inverted());
                    Vector3 LNormal = (collsionComp.LinePointOne - collsionComp.LinePointTwo).Normalized();

                    Vector3 A            = Vector3.Dot(circleInCollsionSpace - collsionComp.LinePointTwo, LNormal) * LNormal;
                    float   LowerBoundsA = Vector3.Dot(circleInCollsionSpace - collsionComp.LinePointTwo, LNormal);
                    //red line = ltwo + A - pos
                    Vector3 redLine = (collsionComp.LinePointTwo + A) - circleInCollsionSpace;
                    //if redline < radius of circle
                    if (redLine.Length < (spherePhys.Radius))
                    {
                        if (A.Length > collsionComp.LineDistance.Length || LowerBoundsA < 0)
                        {
                            //do nothing
                        }
                        else
                        {
                            spherePhys.Velocity = Vector3.Transform(spherePhys.Velocity, cylinderMatrix.ExtractRotation().Inverted());
                            Vector3 rad    = new Vector3(spherePhys.Radius, spherePhys.Radius, spherePhys.Radius);
                            Vector3 normal = Vector3.Transform((circleInCollsionSpace - redLine).Normalized(), cylinderMatrix.ExtractRotation().Inverted());
                            //sphere.Position = sphere.OldPosition + rad * normal;

                            spherePhys.Velocity -= 2 * Vector3.Dot(normal, spherePhys.Velocity) * normal;
                            spherePhys.Velocity  = Vector3.Transform(spherePhys.Velocity, cylinderMatrix.ExtractRotation());
                            float   distance  = Math.Abs(Vector3.Dot(circleInCollsionSpace, normal));
                            Vector3 direction = spherePhys.Velocity.Normalized();
                        }
                    }
                }
            }
        }
Пример #14
0
        public void OnAction(Entity entity)
        {
            if ((entity.Mask & mask) == mask)
            {
                ComponentTransform transformComponent = (ComponentTransform)entity.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
                ComponentMovement  movementComponent  = (ComponentMovement)entity.FindComponent(ComponentTypes.COMPONENT_MOVEMENT);

                transformComponent.Position = movementComponent.DesiredLocation;
            }
        }
Пример #15
0
        public Vector3 UpdatePhysicsPosition(ComponentTransform transform, ComponentPhysics physics, float dt)
        {
            Vector3 position = transform.Position;

            transform.OldPosition = position;

            Vector3 velocity = physics.Velocity;

            return(position += (velocity + m_gravity) * dt);
        }
Пример #16
0
        public void OnAction(Entity entity)
        {
            if ((entity.Mask & MASK) == MASK)
            {
                ComponentTransform transform = entity.transform;
                ComponentVelocity  velocity  = entity.GetComponent <ComponentVelocity>();

                Motion(transform, velocity);
            }
        }
        public void OnAction(Entity entity)
        {
            if ((entity.Mask & MASK) == MASK)
            {
                ComponentCube      skyComponent = entity.GetComponent <ComponentCube>();
                ComponentTransform transform    = entity.transform;

                Draw(transform.GetTransformMatrix(), skyComponent.Geometry, skyComponent.Texture, skyComponent.Shader);
            }
        }
Пример #18
0
        public void UpdatePhysicsCollsion(Entity self, ComponentTransform selfPosition, ComponentPhysics selfPhysics)
        {
            for (int i = 0; i < m_EntityList.Count; i++)
            {
                List <IComponent> components   = m_EntityList[i].Components;
                IComponent        physCollsion = components.Find(delegate(IComponent component)
                {
                    return(component.ComponentType == ComponentTypes.COMPONENT_PHYSICSCOLLSION);
                });
                if (physCollsion != null && m_EntityList[i] != self)
                {
                    IComponent sphereTransfrom = components.Find(delegate(IComponent component)
                    {
                        return(component.ComponentType == ComponentTypes.COMPONENT_TRANSFORM);
                    });
                    ComponentTransform collidedWithPosition = (ComponentTransform)sphereTransfrom;

                    IComponent physicsComponent = components.Find(delegate(IComponent component)
                    {
                        return(component.ComponentType == ComponentTypes.COMPONENT_PHYSICS);
                    });

                    ComponentPhysics collidedwithPhysics = (ComponentPhysics)physicsComponent;

                    if ((selfPosition.Position - collidedWithPosition.Position).Length < (selfPhysics.Radius + collidedwithPhysics.Radius))
                    {
                        Vector3 normal = (collidedWithPosition.Position - selfPosition.Position).Normalized();
                        Vector3 rad    = new Vector3(selfPhysics.Radius, selfPhysics.Radius, selfPhysics.Radius);
                        //selfPosition.Position = selfPosition.OldPosition + rad * normal;

                        Vector3 selfVelocityCopy         = selfPhysics.Velocity;
                        Vector3 collidedwithVelocityCopy = collidedwithPhysics.Velocity;

                        selfPhysics.Velocity -= Vector3.Dot(selfPhysics.Velocity, normal) * normal;
                        //velocity two
                        collidedwithPhysics.Velocity -= Vector3.Dot(collidedwithPhysics.Velocity, -normal) * -normal;

                        //velocity of this instance of the sphere
                        //𝑣1 = 𝑚1 * 𝑢1 + 𝑚2 * 𝑢2 + 𝑒 * 𝑚2(𝑢2 − 𝑢1) / 𝑚1 + 𝑚2
                        Vector3 first  = selfPhysics.Mass * selfVelocityCopy;
                        Vector3 second = collidedwithPhysics.Mass * collidedwithVelocityCopy;

                        Vector3 co    = collidedwithPhysics.CoEfficent * collidedwithPhysics.Mass * (collidedwithVelocityCopy - selfVelocityCopy);
                        Vector3 final = (first + second + co) / (selfPhysics.Mass + collidedwithPhysics.Mass);
                        selfPhysics.Velocity = final;

                        //velocity of the second instance of the sphere
                        //𝑣2 = (𝑚2 − 𝑚1 / 𝑚2 + 𝑚1) * 𝑢2 + (2𝑚1 𝑚2 + 𝑚1) * 𝑢1
                        float firstPart  = (collidedwithPhysics.Mass - selfPhysics.Mass) / (collidedwithPhysics.Mass + selfPhysics.Mass);
                        float secondPart = (selfPhysics.Mass * 2) / (collidedwithPhysics.Mass + selfPhysics.Mass);
                        collidedwithPhysics.Velocity = (firstPart * collidedwithVelocityCopy) + (secondPart * selfVelocityCopy);
                    }
                }
            }
        }
        public void UpdateTransform(ComponentTransform transform)
        {
            Matrix4 scaleMat     = Matrix4.CreateScale(transform.Scale);
            Matrix4 rotateMat    = Matrix4.CreateRotationX(transform.Rotation.X) * Matrix4.CreateRotationY(transform.Rotation.Y) * Matrix4.CreateRotationZ(transform.Rotation.Z);
            Matrix4 translateMat = Matrix4.CreateTranslation(transform.Translation);

            transform.Transform = scaleMat * rotateMat * translateMat;

            transform.Up      = new Vector3(transform.Transform[1, 0], transform.Transform[1, 1], transform.Transform[1, 2]).Normalized();
            transform.Forward = -new Vector3(transform.Transform[2, 0], transform.Transform[2, 1], transform.Transform[2, 2]).Normalized();
            transform.Right   = new Vector3(transform.Transform[0, 0], transform.Transform[0, 1], transform.Transform[0, 2]).Normalized();
        }
Пример #20
0
        private void RespondCreatureWall(Entity creature, Entity wall)
        {
            //dont allow them to move
            //Debug.WriteLine("collsion between creature and wall");

            ComponentTransform transformComponent = (ComponentTransform)creature.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
            Vector3            position           = transformComponent.Position;

            ComponentMovement movementComponent = (ComponentMovement)creature.FindComponent(ComponentTypes.COMPONENT_MOVEMENT);
            Vector3           desiredLocation   = movementComponent.DesiredLocation;

            movementComponent.DesiredLocation = position;
        }
Пример #21
0
        public override void OnAction(Entity entity)
        {
            ComponentAudio     audio    = entity.GetComponent <ComponentAudio>();
            ComponentTransform position = entity.Transform;

            if (AudioManager.AudioListener != null)
            {
                audio.UpdatePosition(position.Position, AudioManager.AudioListener.Transform.Position, AudioManager.AudioListener.Transform.Forward, AudioManager.AudioListener.Transform.Up);
            }
            else
            {
                audio.UpdatePosition(position.Position, new Vector3(0, 0, 3), new Vector3(0, 0, -1), Vector3.UnitY);
            }
        }
Пример #22
0
        public Entity(string name, params IComponent[] components)
        {
            this.name = name;

            // add the default transform component
            transform = new ComponentTransform();
            componentList.Add(transform);
            mask |= transform.ComponentType;

            for (int i = 0; i < components.Length; i++)
            {
                AddComponent(components[i]);
            }
        }
Пример #23
0
        //public override void Update(GameTime time)
        //{
        //    base.Update(time);

        //    //_transform.Update(time);

        //}

        //public override bool Initialize()
        //{

        //}

        public override void Draw(SpriteBatch batch)
        {
            Texture2D tex = GetComponent <ComponentSprite>().Texture;

            if (tex != null)
            {
                ComponentTransform trans = GetComponent <ComponentTransform>();
                if (trans != null)
                {
                    Transform worldTrans = trans.WorldTransform;
                    batch.Draw(tex, (worldTrans.Translate), null, Color.White, worldTrans.Rotate, new Vector2(), worldTrans.Scale, SpriteEffects.None, 0.0f);
                }
            }
        }
        public void OnAction(Entity entity)
        {
            if ((entity.Mask & MASK) == MASK)
            {
                ComponentUI ui = entity.GetComponent <ComponentUI>();
                if (!ui.enabled)
                {
                    return;
                }
                ComponentTransform transform = entity.transform;

                Draw(transform.GetTransformMatrix(), ui.Geometry, ui);
            }
        }
Пример #25
0
        public void Collide(ComponentPosition pPos, ComponentTransform transform)
        {
            float xOffset  = pPos.Position.X + (transform.Transform.ExtractScale().X / 2);
            float sxOffset = pPos.Position.X - (transform.Transform.ExtractScale().X / 2);
            float zOffset  = pPos.Position.Z + (transform.Transform.ExtractScale().Z / 2);
            float szOffset = pPos.Position.Z - (transform.Transform.ExtractScale().Z / 2);

            if (mObject.X >= sxOffset && mObject.X <= xOffset)
            {
                if (mObject.Z > szOffset && mObject.Z < zOffset)
                {
                    Console.WriteLine("Collision Detected");
                }
            }
        }
Пример #26
0
        public void OnAction(Entity entity)
        {
            if ((entity.Mask & MASK) == MASK)
            {
                ComponentTransform transformComponent = (ComponentTransform)entity.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
                Vector3            location           = transformComponent.Position;

                ComponentMovement movementComponent = (ComponentMovement)entity.FindComponent(ComponentTypes.COMPONENT_MOVEMENT);
                Vector3           velocity          = movementComponent.Velocity;
                velocity.Y = 0;

                location += velocity * SceneManager.dt;
                movementComponent.DesiredLocation = location;
            }
        }
Пример #27
0
        private Vector3 GetPosition(Entity entity)
        {
            Vector3 position;

            if (entity.HasComponent(ComponentTypes.COMPONENT_MOVEMENT))
            {
                ComponentMovement movementComponent = (ComponentMovement)entity.FindComponent(ComponentTypes.COMPONENT_MOVEMENT);
                position = movementComponent.DesiredLocation;
            }
            else
            {
                ComponentTransform transformComponent = (ComponentTransform)entity.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
                position = transformComponent.Position;
            }

            return(position);
        }
Пример #28
0
        public void OnAction(Entity entity, float dt)
        {
            if ((entity.Mask & MASK) == MASK)
            {
                List <IComponent> components = entity.Components;

                IComponent DoomSphereTransfrom = components.Find(delegate(IComponent component)
                {
                    return(component.ComponentType == ComponentTypes.COMPONENT_TRANSFORM);
                });
                ComponentTransform transform = (ComponentTransform)DoomSphereTransfrom;
                Vector3            position  = transform.Position;
                float radius = transform.Radius;

                UpdateDoomSphere(position, radius);
            }
        }
Пример #29
0
 public void Update()
 {
     if (owner == null && ownerID.Length != 0)
     {
         AttachTo(ownerID);
     }
     if (owner != null)
     {
         if (owner.HasComponent(ComponentTypes.COMPONENT_TRANSFORM))
         {
             ComponentTransform transformComponent = (ComponentTransform)owner.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
             Vector3            ownerPos           = transformComponent.Position;
             Vector3            ownerDirection     = transformComponent.Direction;
             position  = ownerPos + new Vector3(0, 0.7f, 0);
             direction = ownerDirection;
         }
     }
     view = Matrix4.LookAt(position, position + direction, up);
 }
Пример #30
0
        public void InitLocation()
        {
            //TEST START
            for (int i = 0; i < _world.ObjectMemory; i++)
            {
                if (_monitoredGameObjects[i])
                {
                    _transComps[i] = new ComponentTransform(ref _modelCompsStatic[i]);
                }
            }

            //_transComps[0].RotationXComp.InterpolateRotation(-5f, 30f, InterpolationMode.LINEAR);
            //_transComps[0].RotationYComp.InterpolateRotation(2f, 30f, InterpolationMode.LINEAR);
            //_transComps[0].LocationComp.InterpolateTranslation(new Vector3(3, 0, 0), 30, InterpolationMode.LINEAR);

            //_transComps[1].RotationXComp.InterpolateRotation(5f, 5f, InterpolationMode.LINEAR);
            //_transComps[1].LocationComp.InterpolateTranslation(new Vector3(0, 0, 20), 15, InterpolationMode.LINEAR);
            //TEST END
        }