// Verify the collision with the box and its children ( if previousIntersection is farest than the intersection with the box )
    public AbstractObject collision(CubeStaticObject box, AbstractObject obj)
    {
        // Intersection to external box Cube
        bool collideBox = this.getBoundingBox().collision(box);

        // Calculate internal intersection if the external one if smaller than the previousIntersection
        if (collideBox)
        {
            // If the box has only one child, check its intersection
            if (this.inside != null)
            {
                // This box is the same as inside
                if (obj != this.inside)
                {
                    return(this.inside);
                }
            }
            // If the box has boxes as children, check their intersection
            else
            {
                for (int i = 0; i < this.boxes.Count; i++)
                {
                    AbstractObject collObj = this.boxes[i].collision(box, obj);
                    if (collObj != null)
                    {
                        return(collObj);
                    }
                }
            }
        }
        return(null);
    }
 public bool collision(CubeStaticObject other)
 {
     // For each vertex of the cube
     foreach (Vector3 v in other.vertices())
     {
         if (this.isPointInside(v))
         {
             return(true);
         }
     }
     foreach (Vector3 v in this.vertices())
     {
         if (other.isPointInside(v))
         {
             return(true);
         }
     }
     if (this.isPointInside(other.Position))
     {
         return(true);
     }
     if (other.isPointInside(this.Position))
     {
         return(true);
     }
     return(false);
 }
Пример #3
0
    public PhysicsObject(float mass, Vector3 startPosition, CubeStaticObject boundingBox)
        : base(startPosition)
    {
        this.mass = mass;

        this.position     = startPosition;
        this.speed        = new Vector3(0, 0, 0);
        this.acceleration = new Vector3(0, 0, 0);

        this.boundingBox = boundingBox;
    }
    public PhysicsObject(float mass, float radius, Vector3 startPosition, Vector3 startSpeed, CubeStaticObject boundingBox)
        : base(startPosition)
    {
        this.mass   = mass;
        this.radius = radius;

        this.position   = startPosition;
        this.speed      = startSpeed;
        this.temp_speed = startSpeed;

        this.acceleration = new Vector3(0, 0, 0);

        this.boundingBox = boundingBox;

        internalForces   = new List <Vector3>();
        currentNeighbors = new List <PhysicsObjectGraphics>();
    }
Пример #5
0
    public void evaluate(List <Vector3> forces, float deltaTSeconds, WorldManager world)
    {
        // calculate Acceleration
        Vector3 newAcceleration = new Vector3(0, 0, 0);

        foreach (Vector3 force in forces)
        {
            newAcceleration += force;
        }
        newAcceleration /= mass;
        // calculate Speed
        Vector3 newSpeed = this.speed + newAcceleration * deltaTSeconds;
        // calculate Position
        Vector3 newPosition = this.position + newSpeed * deltaTSeconds;

        // Calculate Collision
        bool             collisionTrigger  = false;
        CubeStaticObject futureBoundingBox = new CubeStaticObject(newPosition, this.boundingBox.Width, this.boundingBox.Height, this.boundingBox.Depth);

        /*foreach( AbstractObject obj in world.Objects ){
         *      // Same object
         *      if( obj != this ){
         *              bool col = futureBoundingBox.collision( obj.getBoundingBox() );
         *              if( col ){
         *                      collisionTrigger = true;
         *              }
         *      }
         * }*/
        AbstractObject collisionObj = world.BbTree.collision(futureBoundingBox, this);

        collisionTrigger = collisionObj != null;

        if (!collisionTrigger)
        {
            // Update info : new one
            this.speed                = newSpeed;
            this.position             = newPosition;
            this.boundingBox.Position = newPosition;
        }
        else
        {
            // Update info : 0
            this.speed = new Vector3(0, 0, 0);
        }
    }
 public PhysicsObject(float mass, float radius, Vector3 startPosition, CubeStaticObject boundingBox)
     : this(mass, radius, startPosition, new Vector3(0, 0, 0), boundingBox)
 {
 }
Пример #7
0
 void Awake()
 {
     staticObj = new CubeStaticObject(this.transform.position, this.transform.localScale.x, this.transform.localScale.y, this.transform.localScale.z);
 }