本文整理汇总了Python中panda3d.core.LineSegs类的典型用法代码示例。如果您正苦于以下问题:Python LineSegs类的具体用法?Python LineSegs怎么用?Python LineSegs使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LineSegs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_xy
def plot_xy(self):
joy_in = self.js.getEvents()
if joy_in:
#print type(joy_in)
for event_name in joy_in:
#print event_name
event = joy_in[event_name]
#print event
#print type(event)
#print inspect.getmembers(event, predicate=inspect.ismethod)
event_mag = event.getMagnitude()
if event_name == 'moveForward':
self.y_mag = event_mag
print('forward', self.y_mag)
elif event_name == 'moveBackward':
self.y_mag = -event_mag
print('backward', self.y_mag)
elif event_name == 'turnRight':
self.x_mag = event_mag
print('right', self.x_mag)
elif event_name == 'turnLeft':
self.x_mag = -event_mag
print('left', self.x_mag)
plot_xy = LineSegs()
plot_xy.setThickness(2.0)
plot_xy.setColor(Vec4(1, 1, 0, 1))
plot_xy.moveTo(self.old_x, 0, self.old_y)
plot_xy.drawTo(self.x_mag, 0, self.y_mag)
base.render2d.attach_new_node(plot_xy.create(True))
self.old_x = self.x_mag
self.old_y = self.y_mag
示例2: move_map_avatar
def move_map_avatar(self, move, stop):
# print move
# avatar is mapped assuming c_range of 0.5. What do I need to
# change to use a different c_range? c_range of one is twice
# the
if move:
avt = LineSegs()
avt.setThickness(1)
avt.setColor(1, 1, 1)
# print 'last', self.last_avt
avt.move_to(self.last_avt[0], -5, self.last_avt[1])
# print 'move', move
new_move = [i + (j * self.avt_factor) for i, j in zip(self.last_avt, move)]
# new_move = [i + j for i, j in zip(self.last_avt, move)]
# would it be better to have a local stop condition?
if stop[0]:
new_move[0] = self.last_avt[0]
# print 'stop x', self.last_avt[0]
if stop[1]:
new_move[1] = self.last_avt[1]
# print 'stop y', self.last_avt[1]
# print 'new', new_move
self.last_avt = [new_move[0], new_move[1]]
avt.draw_to(new_move[0], -5, new_move[1])
self.map_avt_node.append(self.render2d.attach_new_node(avt.create()))
# print self.map_avt_node[-1]
# can't let too many nodes pile up
if len(self.map_avt_node) > 299:
# removing the node does not remove the object from the list
for i, j in enumerate(self.map_avt_node):
j.removeNode()
if i > 49:
break
del self.map_avt_node[0:50]
示例3: create
def create(self, s):
segs = LineSegs( )
segs.setThickness( 2.0 )
segs.setColor( Vec4(1,0,0,1) )
segs.moveTo( s.points[0] )
for p in s.points[1:]:
segs.drawTo( p )
return segs.create( )
示例4: draw_line
def draw_line(self,p,col):
line = LineSegs()
line.setColor(col[0],col[1],col[2], 1)
line.setThickness(2)
line.moveTo(p[0],p[1],0)
line.drawTo(p[2],p[3],0)
line_node = line.create()
node_path = NodePath(line_node)
node_path.reparentTo(render)
示例5: draw_edge
def draw_edge(self,e,e_color):
line_drawer = LineSegs('line_drawer')
line_drawer.setColor(e_color)
line_drawer.setThickness(1.5)
line_drawer.moveTo(e.v1.pos)
line_drawer.drawTo(e.v2.pos)
edge_node = line_drawer.create()
rendered_edge = self.render_root.attachNewNode(edge_node)
self.render_nodes['edge_'+str(e.ID)] = rendered_edge
示例6: drawLineSeg
def drawLineSeg(self, loader, parent, start, end):
lines = LineSegs()
lines.setThickness(5.0)
lines.setColor(VBase4(1, 0.5, 0.5, 1.0))
lines.moveTo(start)
lines.drawTo(end)
np = parent.attachNewNode(lines.create())
np.setDepthWrite(True)
np.setDepthTest(True)
示例7: create_lines
def create_lines(joints, color, thickness=5.0):
for node, parent in joints:
if parent is not None:
lines = LineSegs()
lines.setThickness(thickness)
lines.setColor(color)
lines.moveTo(0, 0, 0)
lines.drawTo(node.getPos(parent))
np = parent.attachNewNode(lines.create())
np.setDepthWrite(True)
np.setDepthTest(True)
示例8: draw
def draw(self, subdiv = 1000):
""" Draws a quick and cheesy visualization of the Mopath using
LineSegs. Returns the NodePath representing the drawing. """
ls = LineSegs('mopath')
p = Point3()
for ti in range(subdiv):
t = float(ti) / float(subdiv) * self.maxT
tp = self.calcTime(t)
self.xyzNurbsCurve.getPoint(tp, p)
ls.drawTo(p)
return NodePath(ls.create())
示例9: update_LFP
def update_LFP(self, dt, last_lfp, lfp_trace, offset, gen_lfp):
# lfp data is taken at 1000Hz, and dt is the number of seconds since
# the last frame was flipped, so plot number of points = dt * 1000
lfp = LineSegs()
lfp.setThickness(1.0)
#print('points to plot', int(dt * 1000))
#self.lfp_test += int(dt * 1000)
#print('points so far', self.lfp_test)
for i in range(int(dt * 1000)):
try:
last_lfp.append((next(gen_lfp) * self.lfp_gain) + offset)
#last_lfp_x += 0.05
# only plotting 200 data points at a time
while len(last_lfp) > 3500:
last_lfp.pop(0)
except StopIteration:
#print('done with lfp')
break
if lfp_trace:
lfp_trace[0].removeNode()
lfp_trace.pop(0)
lfp.moveTo(self.start_x_trace, 55, last_lfp[0])
x = self.start_x_trace
for i in last_lfp:
x += .1
lfp.drawTo(x, 55, i)
node = self.base.pixel2d.attachNewNode(lfp.create())
lfp_trace.append(node)
示例10: line_small_lakes
def line_small_lakes(self):
for l in range(len(small_lake_lines)):
line = LineSegs()
line.setColor(0,0,0, 1)
line.setThickness(2)
for n in range(len(small_lake_lines[l])):
x = (small_lake_nodes[small_lake_lines[l][n]]["x"]-map_center[0])*amplification
y = (small_lake_nodes[small_lake_lines[l][n]]["y"]-map_center[1])*amplification
if n == 0:
line.moveTo(x,y,0)
else:
line.drawTo(x,y,0)
line_node = line.create()
node_path = NodePath(line_node)
node_path.reparentTo(render)
示例11: __make_border__
def __make_border__(cls, parent, thickness, color, l, r , b, t):
moveto_drawto = (
((l,0,t), (l,0,b)),
((r,0,t), (r,0,b)),
((l,0,b), (r,0,b)),
((l,0,t), (r,0,t)),
)
for moveto, drawto in moveto_drawto:
Border = LineSegs()
Border.setThickness(thickness)
Border.setColor(*color)
Border.moveTo(*moveto)
Border.drawTo(*drawto)
b = parent.attachNewNode(Border.create())
b.setBin(*cls.DRAW_ORDER['border'])
示例12: createSelectionBox
def createSelectionBox(self, corner1, corner2):
"""
Create a selection "box" given the coordinates of two opposite corners.
The corners are given in world coordinates (well, 3d graphics
coordinates).
"""
assert self.selectionBox is None
p1, p2, p3, p4 = self.convert3dBoxToScreen(corner1, corner2)
x1, y1 = p1
x2, y2 = p2
x3, y3 = p3
x4, y4 = p4
# TODO[#3]: Magic numbers bad.
self.selectionBox = LineSegs("SelectionBox")
self.selectionBox.setThickness(3.0)
self.selectionBox.setColor(0.0, 1.0, 0.25, 1.0)
self.selectionBox.move_to(x1, 0, y1)
self.selectionBox.draw_to(x2, 0, y2)
self.selectionBox.draw_to(x3, 0, y3)
self.selectionBox.draw_to(x4, 0, y4)
self.selectionBox.draw_to(x1, 0, y1)
self.selectionBoxNode = self.render2d.attachNewNode(
self.selectionBox.create())
示例13: fire_laser
def fire_laser(self, panda3dworld, entity_id):
now = globalClock.getRealTime()
if now - self.last_time_laser_fired < self.laser_reload_time:
if defines.ENTITIES[entity_id]["CATEGORY"] == "ship":
panda3dworld.keys["fire"] = 0
elif defines.ENTITIES[entity_id]["CATEGORY"] == "ship2":
panda3dworld.keys["p2fire"] = 0
else:
self.last_time_laser_fired = now
pos = defines.ENTITIES[entity_id]["NODE"].getPos()
angle = 360 - defines.ENTITIES[entity_id]["NODE"].getR()
# print angle
start_pos_x = pos.x + 0.5 * cos(angle * pi / 180)
start_pos_y = pos.z + 0.5 * sin(angle * pi / 180)
pos_x = pos.x + 10 * cos(angle * pi / 180)
pos_y = pos.z + 10 * sin(angle * pi / 180)
callback = test_laser_collision(start_pos_x, start_pos_y, pos_x, pos_y)
if callback.hit:
pos_x = callback.point.x
pos_y = callback.point.y
for contact_id, entity in defines.ENTITIES.items():
if entity["BODY"].fixtures[0] == callback.fixture:
if (
entity["CATEGORY"] == "ship"
or entity["CATEGORY"] == "ship2"
or entity["CATEGORY"] == "asteroid"
):
entity["SHIELD"] -= 10
elif entity["CATEGORY"] == "bullet":
defines.ENTITIES[contact_id]["NODE"].removeNode()
defines.ENTITIES[contact_id]["PHYSIC_NODE"].removeNode()
defines.world.DestroyBody(defines.ENTITIES[contact_id]["BODY"])
del defines.ENTITIES[contact_id]
ls = LineSegs("lines")
ls.setColor(1, 1, 1, 1)
ls.drawTo(start_pos_x, 55, start_pos_y)
ls.drawTo(pos_x, 55, pos_y)
laser = ls.create(False)
laserPath = render.attachNewNode(laser)
laserPath.setBin("unsorted", 0)
laserPath.setDepthTest(False)
sound = base.loader.loadSfx("sounds/laser.ogg")
sound.setVolume(0.2)
sound.play()
taskMgr.doMethodLater(0.05, remove_laser_task, "remove laser", extraArgs=[laserPath], appendTask=True)
defines.ENTITIES[entity_id]["ENERGY"] -= 5
if defines.ENTITIES[entity_id]["CATEGORY"] == "ship":
panda3dworld.keys["fire"] = 0
elif defines.ENTITIES[entity_id]["CATEGORY"] == "ship2":
panda3dworld.keys["p2fire"] = 0
示例14: walkJointHierarchy
def walkJointHierarchy(self, actor, part, parentNode = None, indent = ""):
if isinstance(part, CharacterJoint):
np = actor.exposeJoint(None, 'modelRoot', part.getName())
if parentNode and parentNode.getName() != "root":
lines = LineSegs()
lines.setThickness(3.0)
lines.setColor(random.random(), random.random(), random.random())
lines.moveTo(0, 0, 0)
lines.drawTo(np.getPos(parentNode))
lnp = parentNode.attachNewNode(lines.create())
lnp.setBin("fixed", 40)
lnp.setDepthWrite(False)
lnp.setDepthTest(False)
parentNode = np
for child in part.getChildren():
self.walkJointHierarchy(actor, child, parentNode, indent + " ")
示例15: draw_path
def draw_path(self, current_position, path):
from panda3d.core import LineSegs, Vec4, Vec3
path = [Vec3(*v) for v in path]
segments = LineSegs()
segments.set_thickness(2.0)
segments.set_color((1, 1, 0, 1))
segments.move_to(current_position)
for point in path:
segments.draw_to(point)
if self._path_node:
self._path_node.remove_node()
node = segments.create()
self._path_node = render.attach_new_node(node)
self._replan_timer = Timer(1.5)
self._replan_timer.on_target = self._replan