Пример #1
0
    def attachToTrack(self, playerpos):
        self.track.attachPlayer(playerpos)
        closest_idx = [0, 1]
        pp = playerpos
        vvx = verts.tr
        dsqlow = [(pp - vvx[closest_idx[0]][0]).normSquared(), \
            (pp - vvx[closest_idx[1]][0]).normSquared()]
        for i, point in enumerate(vvx):
            dsqcur = (pp - point[0]).normSquared()
            if dsqcur < dsqlow[0]:
                dsqlow[0] = dsqcur
                closest_idx[0] = i
            elif dsqcur < dsqlow[1]:
                dsqlow[1] = dsqcur
                closest_idx[1] = i

        plane = Plane()
        cm = vvx[closest_idx[0]][1]
        plane.norm.set(cm.m21, cm.m22, cm.m23)
        plane.setOrigin(vvx[closest_idx[0]][0])
        upv = Vector(plane.norm)
        close = ClosestOnPlane(plane, pp)
        drawpos = close + upv*2
        # find closest point from player pos on line segment closi1->2
        # use that value to interpolate upv from 1->2
        #return drawpos, self.computeUp(closest_idx, close)
        #return drawpos, upv
        return drawpos, Vector(0,1,0)
Пример #2
0
    def doShid(self):
        closest_idx = 0
        pp = self.player.movebody.pos
        vvx = verts.tr
        dsqlow = (pp - vvx[closest_idx][0]).normSquared()
        for i, point in enumerate(vvx):
            if i == closest_idx:
                continue
            dsqcur = (pp - point[0]).normSquared()
            if dsqcur < dsqlow:
                dsqlow = dsqcur
                closest_idx = i

        plane = Plane()
        cm = vvx[closest_idx][1]
        plane.norm.set(cm.m21, cm.m22, cm.m23)
        plane.setOrigin(vvx[closest_idx][0])
        upv = Vector(plane.norm)
        close = ClosestOnPlane(plane, pp)
        return close