本文整理匯總了Python中pandac.PandaModules.LineSegs.reset方法的典型用法代碼示例。如果您正苦於以下問題:Python LineSegs.reset方法的具體用法?Python LineSegs.reset怎麽用?Python LineSegs.reset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pandac.PandaModules.LineSegs
的用法示例。
在下文中一共展示了LineSegs.reset方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: drawLine
# 需要導入模塊: from pandac.PandaModules import LineSegs [as 別名]
# 或者: from pandac.PandaModules.LineSegs import reset [as 別名]
def drawLine(self, parent, source, target):
line = LineSegs()
line.setThickness(LINETHICKNESS)
line.reset()
line.setColor(*GRIDCOLOR)
line.moveTo(source)
line.drawTo(target)
node = line.create()
lineSegNP = NodePath(node).reparentTo(parent)
示例2: DirectionExperiment
# 需要導入模塊: from pandac.PandaModules import LineSegs [as 別名]
# 或者: from pandac.PandaModules.LineSegs import reset [as 別名]
#.........這裏部分代碼省略.........
self.camera_rot.setH(H)
self.cam_spin -= 1
if self.cam_spin == 0:
self.toggle_task("show_question")
return task.done
else:
return task.cont
def show_question(self, task):
self.toggle_task("draw_direction")
self.accept("mouse1", self.record_response)
def record_response(self):
self.ignore("mouse1")
self.taskMgr.remove("draw_direction")
self.toggle_task("physics")
def physics(self, task):
""" Task: simulate physics."""
# Elapsed time.
dt = self._get_elapsed() - self.old_elapsed
# Update amount of time simulated so far.
self.old_elapsed += dt
# Step the physics dt time.
size_sub = self.bbase.sim_par["size_sub"]
n_subs = int(dt / size_sub)
self.bbase.step(dt, n_subs, size_sub)
if self.old_elapsed >= self.feedback_time:
self.toggle_task("show_trial")
return task.done
else:
return task.cont
def draw_direction(self, task):
if self.mouseWatcherNode.hasMouse():
cv = self._get_collision(self.floor)
cv = cv / np.linalg.norm(cv)
self.angle = np.arctan2(cv[1], cv[0])
sx, sy, sz = self.floor.getScale() / 2.0
gx, gy, gz = self.floor.getPos()
gz += sz + 0.01
if self.line_node is not None:
self.line_node.removeNode()
self.line_node = None
self.line.reset()
self.line.setColor(1, 1, 1, 1)
self.line.setThickness(5)
self.line.moveTo(gx, gy, gz)
self.line.drawTo(cv[0] * sx, cv[1] * sy, gz)
self.line_node = self.render.attachNewNode(self.line.create())
self.line_node.setLight(self.line_light)
return task.cont
def _get_collision(self, node, debug=False):
mx = self.mouseWatcherNode.getMouseX()
my = self.mouseWatcherNode.getMouseY()
if debug:
print "mouse:", (mx, my)
# get the origin and direction of the ray extending from the
# camera to the mouse pointer
cm = np.array(self.cam.getNetTransform().getMat())
cr = CollisionRay()
cr.setFromLens(self.cam.node(), (mx, my))
cp = np.hstack([cr.getOrigin(), 1])
cd = np.hstack([cr.getDirection(), 0])
cp = np.dot(cm.T, cp)[:3]
cd = np.dot(cm.T, cd)[:3]
if cd[2] > -1:
cd[2] = -1
if debug:
print "direction:", cd
print "origin:", cp
# point on the plane, z-axis
pz = node.getPos(self.render)[2]
sz = node.getScale(self.render)[2] / 2.0
p0 = np.array([0, 0, pz + sz])
if debug:
print "p0:", p0
# this is the intersection equation that we want to solve,
# where s is the point on the line that intersects
# e_z(cp + s*cd - p0) = 0
s = (p0[2] - cp[2]) / cd[2]
if debug:
print "s:", s
# transform the collision point from line coordinates to world
# coordinates
cv = cp + s * cd
if debug:
print "collision:", cv
return cv
示例3: __init__
# 需要導入模塊: from pandac.PandaModules import LineSegs [as 別名]
# 或者: from pandac.PandaModules.LineSegs import reset [as 別名]
class RepairSawingLine:
def __init__(self, parent, thickness, color, lineSpawnDist = 0.01):
self.points = []
self.parent = parent
self.thickness = thickness
self.color = color
self.lineNode = None
self.lineDrawer = LineSegs()
self.lineDrawer.setThickness(thickness)
self.lineSpawnDist = lineSpawnDist
self.currentPoint = None
self.startPoint = None
self.redraw()
def redraw(self):
self.clearLine()
self.lineDrawer.reset()
self.lineDrawer.setThickness(self.thickness)
self.lineDrawer.setColor(self.color)
if len(self.points) > 0:
self.lineDrawer.moveTo(self.points[0])
for i in range(1, len(self.points)):
p = self.points[i]
self.lineDrawer.drawTo(p)
self.currentPoint = p
self.lineNode = NodePath(self.lineDrawer.create())
self.lineNode.reparentTo(self.parent)
self.lineNode.setBin('fixed', 37)
self.lineNode.setTransparency(True)
def update(self, point):
if self.currentPoint == None or (point - self.currentPoint).length() >= self.lineSpawnDist:
self.addPoint(point)
self.redraw()
def addPoint(self, p):
if len(self.points) == 0:
self.startPoint = p
self.points.append(p)
def clearLine(self):
if self.lineNode != None:
self.lineNode.removeNode()
def reset(self):
self.clearLine()
self.points = []
self.redraw()
self.currentPoint = None
self.startPoint = None
def show(self):
self.lineNode.unstash()
def hide(self):
self.lineNode.stash()