示例#1
0
    def _checkRayIntersect(self, ray):
        """Check if ray intersects object
        @see: objects.ObjectDepth._checkRayIntersect
        """
        res = ogre.Math.intersects(ray, self.sceneNode._getWorldAABB())
        rvalue, pos = objects.ObjectDepth._checkRayIntersect(self, ray)

        if not rvalue:
            return False, -1

        # works just for a isometric mode
        m = ogre.Matrix4()
        self.getSceneNode().getWorldTransforms(m)
        p = ogre.Matrix4.getTrans(m)

        pl = ogre.Plane(ray.getDirection(), p)
        pr = ray.intersects(pl)
        if not pr.first:
            return False, -1

        d = ray.getPoint(pr.second)

        rvalue = False
        for idx in range(len(self.points)):
            p2 = self.points[idx] + p
            p1 = self.points[idx - 1] + p
            if (((p2.y <= d.y and d.y < p1.y) or (p1.y <= d.y and d.y < p2.y)) and \
                (d.x > (p1.x - p2.x) * (d.y - p2.y) / (p1.y - p2.y) + p2.x)):
                rvalue = not rvalue

        return rvalue, 0
示例#2
0
    def _checkRayIntersect(self, ray):
        """Check if ray intersects union object.
        Just check if it intersects any of object included to union.
        
        @param ray:    ray for intersection checking
        @type ray:    ogre.Ray
        """
        res, pos = suit.core.objects.ObjectDepth._checkRayIntersect(self, ray)
        if not res:
            return False, -1

        # works just for a isometric mode
        m = ogre.Matrix4()
        self.getSceneNode().getWorldTransforms(m)
        p = ogre.Matrix4.getTrans(m)

        pl = ogre.Plane(ray.getDirection(), p)
        pr = ray.intersects(pl)
        if not pr.first:
            return False, -1

        d = ray.getPoint(pr.second)

        dist = self.center_point.getPosition().distance(d)
        if math.fabs(dist - self.radius) <= self.width / 2.0:
            return True, 0

        return False, -1
示例#3
0
    def distance(self, ray):
        m = ogre.Matrix4()
        self.getSceneNode().getWorldTransforms(m)
        p = ogre.Matrix4.getTrans(m)

        pl = ogre.Plane(ray.getDirection(), p)
        pr = ray.intersects(pl)
        if pr.first:
            d = ray.getPoint(pr.second)
            return (d - p).length()

        return None