コード例 #1
0
    def drawSelf(self):
        if self.sceneNode.corners is None or self.sceneNode.dimension is None:
            return
        corners = self.sceneNode.corners

        outwardSegments = [
            LineSegment(corners[i], corners[j]) for i, j in self.outwardIndices
        ]
        verticalSegments = [
            LineSegment(corners[i], corners[j])
            for i, j in self.verticalIndices
        ]
        points = []

        for segment in outwardSegments:
            p = segment.atHeight(self.sceneNode.planeHeight)
            if p is not None:
                points.append(p)

        if len(points) < 4:
            # only intersected two outward segments. check the far verticals.
            for segment in verticalSegments[:2]:
                r = Ray.fromPoints(*segment)
                points.append(r.atHeight(self.sceneNode.planeHeight))

        if len(points) < 4:
            # intersected zero outward segments!
            # rarely occurs, the near verticals are 1/10 of a block tall
            for segment in verticalSegments[2:]:
                r = Ray.fromPoints(*segment)
                points.append(r.atHeight(self.sceneNode.planeHeight))

        if len(points) < 4:
            return

        p1, p2, p3, p4 = points[:4]
        points = [p1, p2, p4, p3, p1]

        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT, GL.GL_COLOR_BUFFER_BIT):
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glVertexPointer(3, GL.GL_FLOAT, 0, numpy.array(points).ravel())

            GL.glLineWidth(3.0)

            GL.glColor(1, 1, .1, 0.5)
            GL.glDisable(GL.GL_DEPTH_TEST)
            GL.glDrawArrays(GL.GL_LINE_STRIP, 0, len(points))
コード例 #2
0
ファイル: minimap.py プロジェクト: KevinKelley/mcedit2
    def atHeight(self, y):
        p1 = self.p1
        p2 = self.p2
        if not (p1.y < y < p2.y or p1.y > y > p2.y):
            return None

        r = Ray.fromPoints(p1, p2)
        return r.atHeight(y)
コード例 #3
0
    def atHeight(self, y):
        p1 = self.p1
        p2 = self.p2
        if not (p1.y < y < p2.y or p1.y > y > p2.y):
            return None

        r = Ray.fromPoints(p1, p2)
        return r.atHeight(y)
コード例 #4
0
ファイル: minimap.py プロジェクト: KevinKelley/mcedit2
    def drawSelf(self):
        if self.sceneNode.corners is None or self.sceneNode.dimension is None:
            return
        corners = self.sceneNode.corners

        outwardSegments = [LineSegment(corners[i], corners[j]) for i, j in self.outwardIndices]
        verticalSegments = [LineSegment(corners[i], corners[j]) for i, j in self.verticalIndices]
        points = []

        for segment in outwardSegments:
            p = segment.atHeight(self.sceneNode.planeHeight)
            if p is not None:
                points.append(p)

        if len(points) < 4:
            # only intersected two outward segments. check the far verticals.
            for segment in verticalSegments[:2]:
                r = Ray.fromPoints(*segment)
                points.append(r.atHeight(self.sceneNode.planeHeight))

        if len(points) < 4:
            # intersected zero outward segments!
            # rarely occurs, the near verticals are 1/10 of a block tall
            for segment in verticalSegments[2:]:
                r = Ray.fromPoints(*segment)
                points.append(r.atHeight(self.sceneNode.planeHeight))

        if len(points) < 4:
            return

        p1, p2, p3, p4 = points[:4]
        points = [p1, p2, p4, p3, p1]

        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT, GL.GL_COLOR_BUFFER_BIT):
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glVertexPointer(3, GL.GL_FLOAT, 0, numpy.array(points).ravel())

            GL.glLineWidth(3.0)

            GL.glColor(1, 1, .1, 0.5)
            GL.glDisable(GL.GL_DEPTH_TEST)
            GL.glDrawArrays(GL.GL_LINE_STRIP, 0, len(points))
コード例 #5
0
ファイル: minimap.py プロジェクト: cagatayikim/mcedit2
 def rayCastCorner(near, far):
     ray = Ray.fromPoints(near, far)
     if not any(ray.vector):
         return far
     try:
         #point = rayCastInBounds(ray, dimension, 50)[0]
         #return point or far
         return near + (near - far) / 4
     except raycast.MaxDistanceError:
         return ray.atHeight(0)
コード例 #6
0
ファイル: minimap.py プロジェクト: 101baja202/mcedit2
 def rayCastCorner(near, far):
     ray = Ray.fromPoints(near, far)
     if not any(ray.vector):
         return far
     try:
         #point = rayCastInBounds(ray, dimension, 50)[0]
         #return point or far
         return near + (near - far) / 4
     except raycast.MaxDistanceError:
         return ray.atHeight(0)
コード例 #7
0
ファイル: worldview.py プロジェクト: cagatayikim/mcedit2
    def getViewBounds(self):
        """
        Get the corners of the viewing area, intersected with the world's bounds.
        xxx raycast to intersect with terrain height too

        :return:
        :rtype:
        """
        corners = self.getViewCorners()
        # Convert the 4 corners into rays extending from the near point, then interpolate each ray at the
        # current dimension's height limits
        pairs = []
        for i in range(0, 8, 2):
            pairs.append(corners[i:i+2])

        rays = [Ray.fromPoints(p1, p2) for p1, p2 in pairs]
        bounds = self.dimension.bounds
        pointPairs = [(r.atHeight(bounds.maxy), r.atHeight(bounds.miny)) for r in rays]

        return sum(pointPairs, ())