示例#1
0
    def signedDistance(self, point):
        xyVec = bdgmath.Vector2(point.x(), point.y())
        left = bdgmath.Vector2(xyVec.mag(), abs(point.z()))
        d = left.subVec2(self.hrVec)

        inDist = min(max(d.x(), d.y()), 0.0)
        
        outVec = bdgmath.Vector2(max(d.x(), 0.0), max(d.y(), 0.0))
        return outVec.mag() + inDist
示例#2
0
    def drawString(self, dwg, s, pos, scale):
        while s:
            c = s[0]
            s = s[1:]

            charNum = self.charToCharNum(c)
            if ((charNum >= 0) and (charNum < len(self.lines))):

                xMin, yMin, xMax, yMax = self.getCharBounds(charNum)
                charAdv = m.Vector2(-xMin * scale, 0)
                self.drawChar(dwg, charNum, pos.addVec2(charAdv), scale)
                advanceValue = xMax - xMin + self.extraCharSpacing
            else:
                advanceValue = 10 + self.extraCharSpacing
            pos = pos.addVec2(m.Vector2(advanceValue, 0).mulScalar(scale))
示例#3
0
def drawHersheyChar(dwg, s, pos, scale):
    p = draw.Path(stroke_width=2, stroke='black', fill='none')

    numVerts = int(s[5:8])

    leftPos = decodeCoord(s[8])
    rightPos = decodeCoord(s[9])

    remainder = s[10:]

    minX = 0
    maxX = 0
    minY = 0
    maxY = 0

    yFlip = True

    moveFlag = True
    for vi in range(0, numVerts - 1):
        cx = s[10 + 2 * vi]
        cy = s[11 + 2 * vi]

        if cx + cy == " R":
            moveFlag = True
            continue

        xVal = decodeCoord(cx)
        yVal = decodeCoord(cy)

        if yFlip:
            yVal = -yVal

        if vi == 0:
            minX = xVal
            maxX = xVal
            minY = yVal
            maxY = yVal
        else:
            minX = min(minX, xVal)
            maxX = max(maxX, xVal)
            minY = min(minY, yVal)
            maxY = max(maxY, yVal)

        pt = pos.addVec2(m.Vector2(xVal, yVal).mulScalar(scale))
        if moveFlag:
            p.M(*pt.components)
        else:
            p.L(*pt.components)
        moveFlag = False
    dwg.append(p)

    return (minX * scale, minY * scale, maxX * scale, maxY * scale)
示例#4
0
scene = scene.Scene()

scene.addLight(light.DirectionalLight(bdgmath.Vector3(-1, 0.5, -4), 0.8))
scene.addLight(light.AmbientLight(0.2))

floor = plane.ZPlane(0)
floor.squareSize = 2
scene.addObject(floor)

disk = roundedge.RoundEdge(0.1, cylinder.CappedCylinder(0.8, 3.8))

translatedDisk = transform.Translate3d(bdgmath.Vector3(0, 0, 1.5), disk)
#scene.addObject(translatedDisk)

negCyl1 = cylinder.ZCylinder(bdgmath.Vector2(1.5, 1.5), 1.1)
negCyl2 = cylinder.ZCylinder(bdgmath.Vector2(1.5, -1.5), 1.1)
negCyl3 = cylinder.ZCylinder(bdgmath.Vector2(-1.5, -1.5), 1.1)
negCyl4 = cylinder.ZCylinder(bdgmath.Vector2(-1.5, 1.5), 1.1)

w = translatedDisk
for c in [negCyl1, negCyl2, negCyl3, negCyl4]:
    w = csg.Difference(w, c)

scene.addObject(w)

#cam.renderScene(scene, 640, 320, "raytest.png", 5)
#cam.renderScene(scene, 300, 240, "raytest.png", 5)
cam.renderScene(scene, 100, 80, "raytest.png", 5)

示例#5
0
 def __init__(self, height, radius):
     self.height = height
     self.radius = radius
     self.color = (1, 0.5, 0)
     self.material = None
     self.hrVec = bdgmath.Vector2(self.radius, self.height)
示例#6
0
 def signedDistance(self, point):
     vecToAxis2d = bdgmath.Vector2(point.x() - self.base.x(),
                                   point.y() - self.base.y())
     distToAxis = vecToAxis2d.mag()
     return distToAxis - self.radius
示例#7
0
 def drawWrappedString(self, dwg, s, left, right, first, scale,
                       lineAdvance):
     pos = m.Vector2(left, first)
     for line in self.genLines(s, scale, right - left):
         self.drawString(dwg, line, pos, scale)
         pos = pos.addVec2(m.Vector2(0, -lineAdvance))