Esempio n. 1
0
    public bool PlaceObject(GameObject obj, bool respectMaxRobotReachability)
    {
        Bounds planeBounds = plane.GetComponent <Renderer>().bounds;

        if (obj.activeInHierarchy)
        {
            // try to sample a valid point
            Bounds objBounds        = obj.GetComponent <Renderer>().bounds;
            float  radius           = objBounds.extents.magnitude;
            float  heightAbovePlane = objBounds.extents.y;

            List <PlacementConstraint> constraints = GetAllConstraints(respectMaxRobotReachability);
            Vector3?point = SampleValidGlobalPointOnPlane(radius, constraints, planeBounds, respectMaxRobotReachability);

            if (point.HasValue)
            {
                // place object
                Vector3 foundPoint = point ?? Vector3.zero;
                obj.transform.position = new Vector3(foundPoint.x, foundPoint.y + heightAbovePlane, foundPoint.z);

                // update constraints so subsequently placed object cannot collide with this one
                CollisionConstraint newConstraint = new CollisionConstraint();
                newConstraint.x      = foundPoint.x;
                newConstraint.z      = foundPoint.z;
                newConstraint.radius = radius;
                collisionConstraints.Add(newConstraint);
            }
            else
            {
                return(false);
            }
        }
        return(true);
    }
Esempio n. 2
0
        ///<summary>
        /// Creates a new simulator that can handle up to the given
        /// number of contacts per frame. You can also optionally give
        /// a number of contact-resolution iterations to use. If you
        /// don't give a number of iterations, then four times the
        /// number of detected contacts will be used for each frame.
        ///<summary>
        public RigidBodyEngine(int maxContacts)
        {
            Bodies      = new List <RigidBody>();
            ForceAreas  = new List <RigidForceArea>();
            Forces      = new List <RigidForce>();
            Constraints = new List <RigidConstraint>();
            Resolver    = new RigidContactResolver();

            Collisions = new CollisionConstraint();
            Constraints.Add(Collisions);

            m_contacts = new RigidContact[maxContacts];
            for (int i = 0; i < maxContacts; i++)
            {
                m_contacts[i] = new RigidContact();
            }
        }