예제 #1
0
    def myNextCollider(self):
        # If the previous calculation of the next collider is still valid,
        # return the cached value.

        if self.nextCollider:
            return self.nextCollider

        which = None
        dMin = Inf

        for o in self.gs.obstacles:
            if self.me == o:
                continue  # Don't include me!

            self.ip = o.nearestIntersection(self.me, self.ip)

            # Infinity is used to indicate no intersection.
            if vec.length(self.ip) < Inf:
                p = self.ip - self.myPosition()

                d = vec.length(p) - self.myMaxExtent()
                if d < dMin:
                    dMin = d
                    which = o
                    vec.copy(self.ip, self.cp)

        # We must at least be on a collision course with one of the sides.
        # TODO: turn side collisions back on
        # if false and not which:
        #    print self.myPosition(), "; ", self.myOrientation()
        #    pause
        #    assert which

        # Computing the nearest collider is expensive so cache the result
        # in case it's needed again.

        # TODO: Could also be worth caching dMin as the distance to the
        # nearest collider.

        self.nextCollider = which
        return which
    def myNextCollider(self):
        # If the previous calculation of the next collider is still valid,
        # return the cached value.

        if self.nextCollider:
            return self.nextCollider

        which = None
        dMin = Inf

        for o in self.gs.obstacles:
            if self.me == o:
                continue # Don't include me!

            self.ip = o.nearestIntersection(self.me, self.ip)

            # Infinity is used to indicate no intersection.
            if vec.length(self.ip) < Inf:
                p = self.ip - self.myPosition()

                d = vec.length(p) - self.myMaxExtent()
                if d < dMin:
                    dMin = d
                    which = o
                    vec.copy(self.ip, self.cp)

        # We must at least be on a collision course with one of the sides.
        # TODO: turn side collisions back on
        # if false and not which:
        #    print self.myPosition(), "; ", self.myOrientation()
        #    pause
        #    assert which

        # Computing the nearest collider is expensive so cache the result
        # in case it's needed again.

        # TODO: Could also be worth caching dMin as the distance to the
        # nearest collider.

        self.nextCollider = which
        return which
예제 #3
0
    def setOrientation(self, orientation):
        assert util.isAlmostEq(1.0, vec.length(orientation)), 'invalid orientation ' + str(orientation)

        vec.copy(orientation, self.orientation)
예제 #4
0
 def setPosition(self, position):
     vec.copy(position, self.position)
    def setOrientation(self, orientation):
        assert util.isAlmostEq(1.0, vec.length(orientation)), 'invalid orientation ' + str(orientation)

        vec.copy(orientation, self.orientation)
 def setPosition(self, position):
     vec.copy(position, self.position)