def draw_axis(self, root, origin): PX = origin[0] PY = origin[1] PZ = origin[2] lengthX = PX + 1.5 lengthY = PY + 1.5 lengthZ = PZ + 1.5 q1 = PX + .5 q2 = -q1 arrowLENGHT = PX + .2 arrowXx1 = PY + .08 arrowXx2 = PY - .08 arrowXz2 = PX + 1.3 arrowYx1 = PX + .08 arrowYx2 = PX - .08 arrowYz2 = PY + 1.3 arrowZx1 = PX + .08 arrowZx2 = PX - .08 arrowZz2 = PZ + 1.3 PIVarX = LineNodePath(root, 'pivotX', 3, Vec4(1, 0, 0, 1)) PIVarY = LineNodePath(root, 'pivotY', 3, Vec4(0, 1, 1, 1)) PIVarZ = LineNodePath(root, 'pivotZ', 3, Vec4(1, 1, 0, 1)) PIVOThandler = LineNodePath(root, 'handler', 2, Vec4(1, 0, 1, 1)) PIVarX.reparentTo(PIVOThandler) PIVarY.reparentTo(PIVOThandler) PIVarZ.reparentTo(PIVOThandler) arrowX1 = (lengthX, PY, PZ) arrowX2 = (arrowXz2, arrowXx1, PZ) arrowX3 = (arrowXz2, arrowXx2, PZ) arrowY1 = (PX, lengthY, PZ) arrowY2 = (arrowYx1, arrowYz2, PZ) arrowY3 = (arrowYx2, arrowYz2, PZ) arrowZ1 = (PX, PY, lengthZ) arrowZ2 = (arrowZx1, PY, arrowZz2) arrowZ3 = (arrowZx2, PY, arrowZz2) PIVarX.drawLines([[(PX, PY, PZ), (lengthX, PY, PZ)], [arrowX1, arrowX2], [arrowX1, arrowX3]]) PIVarY.drawLines([[(PX, PY, PZ), (PX, lengthY, PZ)], [arrowY1, arrowY2], [arrowY1, arrowY3]]) PIVarZ.drawLines([[(PX, PY, PZ), (PX, PY, lengthZ)], [arrowZ1, arrowZ2], [arrowZ1, arrowZ3]]) PIVOThandler.drawLines([[(PX, PY, PZ), (PX + 0.5, PY, PZ)], [(PX + .5, PY, PZ), (PX, PY + .5, PZ)], [(PX, PY + .5, PZ), (PX, PY, PZ)]]) PIVarX.create() PIVarY.create() PIVarZ.create() PIVOThandler.create() return PIVOThandler
def grid(self): raws1unit = 20 rawsfithunit = 10 d = 0 X1 = 10 X2 = -10 Y1 = 10 Y2 = -10 linesX = LineNodePath(render, 'quad', 2, Vec4(.3, .3, .3, .3)) linesXX = LineNodePath(render, 'quad', 1, Vec4(.3, .3, .3, .3)) axis = LineNodePath(render, 'axis', 4, Vec4(.2, .2, .2, .2)) quad = LineNodePath(render, 'quad', 4, Vec4(.2, .2, .2, .2)) x1 = (0, Y2, 0) x2 = (0, Y1, 0) x3 = (X2, 0, 0) x4 = (X1, 0, 0) axis.drawLines([[x1, x2], [x3, x4]]) axis.create() q1 = (X1, Y1, 0) q2 = (X1, Y2, 0) q3 = (q2) q4 = (X2, Y2, 0) q5 = (q4) q6 = (X2, Y1, 0) q7 = (q6) q8 = (X1, Y1, 0) quad.drawLines([[q1, q2], [q3, q4], [q5, q6], [q7, q8]]) quad.create() for l in range(raws1unit - 1): d += 1 l1 = (X2 + d, Y1, 0) l2 = (X2 + d, Y2, 0) l3 = (X2, Y1 - d, 0) l4 = (X1, Y1 - d, 0) linesX.drawLines([[l1, l2], [l3, l4]]) linesX.create() for l in range(rawsfithunit): d -= .2 lx1 = (X2 + 1 + d, Y1, 0) lx2 = (X2 + 1 + d, Y2, 0) lx3 = (X2, Y1 - 1 - d, 0) lx4 = (X1, Y1 - 1 - d, 0) linesXX.drawLines([[lx1, lx2], [lx3, lx4]]) linesXX.create()
def draw_grid(self): raws1unit = 20 rawsHALFunit = 100 X1 = 10 X2 = -10 Y1 = 10 Y2 = -10 linesX = LineNodePath(self.render, 'lines1', 2, Vec4(.3, .3, .3, 0)) linesXXX = LineNodePath(self.render, 'lines1', .4, Vec4(.35, .35, .35, 0)) axis = LineNodePath(self.render, 'axis', 4, Vec4(.2, .2, .2, 0)) quad = LineNodePath(self.render, 'quad', 4, Vec4(.2, .2, .2, 0)) x1 = (0, Y2, 0) x2 = (0, Y1, 0) x3 = (X2, 0, 0) x4 = (X1, 0, 0) axis.drawLines([[x1, x2], [x3, x4]]) axis.create() q1 = (X1, Y1, 0) q2 = (X1, Y2, 0) q3 = (q2) q4 = (X2, Y2, 0) q5 = (q4) q6 = (X2, Y1, 0) q7 = (q6) q8 = (X1, Y1, 0) quad.drawLines([[q1, q2], [q3, q4], [q5, q6], [q7, q8]]) quad.create() gfOutput = [1] d = 0 for l in range(raws1unit - 1): lO = len(gfOutput) lO1 = lO - 1 global field field1 = gfOutput[lO1] field = float(field1) print(field) d += field l1 = (X2 + d, Y1, 0) l2 = (X2 + d, Y2, 0) l3 = (X2, Y1 - d, 0) l4 = (X1, Y1 - d, 0) linesX.drawLines([[l1, l2], [l3, l4]]) linesX.create()
def __init__(self, parent, gridSize=100.0, gridSpacing=5.0, planeColor=(0.5, 0.5, 0.5, 0.5)): # Initialize superclass NodePath.__init__(self) self.assign(hidden.attachNewNode('DirectGrid')) # Don't wireframe or light #useDirectRenderStyle(self) self.setLightOff(0) self.setRenderModeFilled() self.parent = parent # Load up grid parts to initialize grid object # Polygon used to mark grid plane self.gridBack = loader.loadModel('models/misc/gridBack.egg.pz') self.gridBack.reparentTo(self) self.gridBack.setColor(*planeColor) # Grid Lines self.lines = self.attachNewNode('gridLines') self.minorLines = LineNodePath(self.lines) self.minorLines.lineNode.setName('minorLines') self.minorLines.setColor(VBase4(0.3, 0.55, 1, 1)) self.minorLines.setThickness(1) self.majorLines = LineNodePath(self.lines) self.majorLines.lineNode.setName('majorLines') self.majorLines.setColor(VBase4(0.3, 0.55, 1, 1)) self.majorLines.setThickness(5) self.centerLines = LineNodePath(self.lines) self.centerLines.lineNode.setName('centerLines') self.centerLines.setColor(VBase4(1, 0, 0, 0)) self.centerLines.setThickness(3) # Small marker to hilight snap-to-grid point self.snapMarker = loader.loadModel('models/misc/sphere.egg.pz') self.snapMarker.node().setName('gridSnapMarker') self.snapMarker.reparentTo(self) self.snapMarker.setColor(1, 0, 0, 1) self.snapMarker.setScale(0.3) self.snapPos = Point3(0) # Initialize Grid characteristics self.fXyzSnap = 1 self.fHprSnap = 1 self.gridSize = gridSize self.gridSpacing = gridSpacing self.snapAngle = 15.0 self.enable()
def __init__( self, world, space, name=NAME_DEFAULT, modelEgg=MODEL_EGG_DEFAULT, pos=POS_DEFAULT, scale=SCALE_DEFAULT, hpr=HPR_DEFAULT, ): self.limitedYMovement = False self.limitedYCoords = [-1, -1] self.limitedZMovement = False self.limitedZCoords = [-1, -1] self.name = name self.pos = pos self.hpr = hpr self.scale = scale self.world = world self.space = space self.jumping = False self.jumpStarted = 0.0 self.jumpLastUpdate = 0.0 self.lastCollisionTime = 0.0 self.lastCollisionIsGround = True self.lastGroundCollisionBodyPos = None self.jumpSound = loader.loadSfx(self.JUMP_SOUND_DEFAULT) self.bounceSound = loader.loadSfx(self.BOUNCE_SOUND_DEFAULT) if Ball.MOVEMENT_DEBUG: self.lastDrawTime = 0.0 self.lastDrawTime2 = 0.0 self.lines = LineNodePath(parent=render, thickness=3.0, colorVec=Vec4(1, 0, 0, 1)) self.lines2 = LineNodePath(parent=render, thickness=3.0, colorVec=Vec4(0, 0, 1, 1)) self.lines3 = LineNodePath(parent=render, thickness=3.0, colorVec=Vec4(0, 1, 0, 1)) if Ball.JUMP_DEBUG: self.lastTakeoffTime = 0.0 self.moveLeft = False self.moveRight = False self.modelNode = self.createModelNode(self.pos, self.hpr, self.scale, modelEgg) self.ballBody = self.createBallBody(self.modelNode, self.world) self.ballGeom = self.createBallGeom(self.modelNode, self.ballBody, self.space) self.modelNode.reparentTo(render)
def P3DCreateAxes(length=0.5, arrowAngle=25, arrowLength=0.05): nodePath = LineNodePath() nodePath.reparentTo(render2d) #~ nodePath.drawArrow2d(Vec3(0, 0, 0), Vec3(0.5, 0, 0.5), 30, 0.1) nodePath.drawArrow2d(Vec3(0, 0, 0), Vec3(0., 0, length), arrowAngle, arrowLength) nodePath.create() return nodePath
def __init__(self, flock=None, *a, **k): super(BoidEntityBase, self).__init__(*a, **k) self.flock = weakref.proxy(flock) self.flock.add_boid(self) self._debug_line = LineNodePath(self.entities.render, 'caca', 2, Vec4(1, 0, 0, 0))
def line_model(self, r, g, b): line = LineNodePath(self.render2d, 'box', 2) line.reparentTo(self.render) line.setColor(r, g, b, 1.) line.setTransparency(TransparencyAttrib.MAlpha) line.setAlphaScale(0.5) return line
def __init__(self, socketA, socketB): self.connectorID = uuid4() self.socketA = socketA self.socketB = socketB self.line = LineNodePath(ShowBaseGlobal.aspect2d, thickness=2, colorVec=(0.8, 0.8, 0.8, 1)) self.draw()
def startLineDrawing(self, startPos): """Start a task that will draw a line from the given start position to the cursor""" self.line = LineNodePath(render2d, thickness=2, colorVec=(0.8, 0.8, 0.8, 1)) self.line.moveTo(startPos) t = self.taskMgr.add(self.drawLineTask, "drawLineTask") t.startPos = startPos
def draw_box(self, box): line_collection = LineNodePath(parent=render, thickness=1.0, colorVec=Vec4(1, 0, 0, 1)) pos = box.get_position() lengths = box.get_lengths() x = pos[0] y = pos[1] z = pos[2] half_width = lengths[0] / 2 half_length = lengths[1] / 2 half_height = lengths[2] / 2 lines = [ # Bottom Face ((x - half_width, y - half_length, z - half_height), (x + half_width, y - half_length, z - half_height)), ((x + half_width, y - half_length, z - half_height), (x + half_width, y + half_length, z - half_height)), ((x + half_width, y + half_length, z - half_height), (x - half_width, y + half_length, z - half_height)), ((x - half_width, y + half_length, z - half_height), (x - half_width, y - half_length, z - half_height)), # Top Face ((x - half_width, y - half_length, z + half_height), (x + half_width, y - half_length, z + half_height)), ((x + half_width, y - half_length, z + half_height), (x + half_width, y + half_length, z + half_height)), ((x + half_width, y + half_length, z + half_height), (x - half_width, y + half_length, z + half_height)), ((x - half_width, y + half_length, z + half_height), (x - half_width, y - half_length, z + half_height)), # Vertical Lines ((x - half_width, y - half_length, z - half_height), (x - half_width, y - half_length, z + half_height)), ((x + half_width, y - half_length, z - half_height), (x + half_width, y - half_length, z + half_height)), ((x + half_width, y + half_length, z - half_height), (x + half_width, y + half_length, z + half_height)), ((x - half_width, y + half_length, z - half_height), (x - half_width, y + half_length, z + half_height)), ] line_collection.drawLines(lines) line_collection.create()
def _build_cursor(self, shape="sphere"): if shape == "sphere": cursor = self._load("sphere.bam") elif shape == "cross": cursor = LineNodePath() lines = [[Point3(-0.5, 0, 0), Point3(0.5, 0, 0)], [Point3(0, 0, -0.5), Point3(0, 0, 0.5)]] cursor.drawLines(lines) cursor.setThickness(1) cursor.create() # cursor = NodePath("cross") # S = {"cylinderX.bam": ((0., 0., 0.), (1., 0.1, 0.1)), # "cylinderY.bam": ((0., 0., 0.), (0.1, 1., 0.1)), # "cylinderZ.bam": ((0., 0., 0.), (0.1, 0.1, 1.))} # for k, v in S.iteritems(): # m = self._load(k) # m.setName(k) # m.setPos(*v[0]) # m.setScale(*v[1]) # m.reparentTo(cursor) #BP() return cursor
def setup(self): self.targetAlt = r.randrange(100,300) self.Valves = np.array([0.15,0.2,0.15]) self.EngObs = self.vulcain.predict_data_point(np.array(self.Valves).reshape(1,-1)) if self.VISUALIZE is True: self.worldNP = self.render.attachNewNode('World') else: self.root = NodePath(PandaNode("world root")) self.worldNP = self.root.attachNewNode('World') self.world = BulletWorld() self.world.setGravity(Vec3(0, 0, -9.80665)) # World self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug')) self.debugNP.node().showWireframe(True) self.debugNP.node().showConstraints(True) self.debugNP.node().showBoundingBoxes(False) self.debugNP.node().showNormals(True) self.debugNP.show() self.world.setDebugNode(self.debugNP.node()) # self.debugNP.showTightBounds() # self.debugNP.showBounds() # Ground (static) shape = BulletPlaneShape(Vec3(0, 0, 1), 1) self.groundNP = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground')) self.groundNP.node().addShape(shape) self.groundNP.setPos(0, 0, 0) self.groundNP.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.groundNP.node()) # Rocket shape = BulletCylinderShape(self.radius, self.length, ZUp) self.rocketNP = self.worldNP.attachNewNode(BulletRigidBodyNode('Cylinder')) self.rocketNP.node().setMass(27200 * self.scale) self.rocketNP.node().addShape(shape) #self.rocketNP.setPos(20,20,250) self.rocketNP.setPos(20, 20, r.randrange(100, 300)+200) #self.rocketNP.setPos(r.randrange(-self.lateralError, self.lateralError, 1), r.randrange(-self.lateralError, self.lateralError, 1), self.height) # self.rocketNP.setPos(0, 0, self.length*10) self.rocketNP.setCollideMask(BitMask32.allOn()) # self.rocketNP.node().setCollisionResponse(0) self.rocketNP.node().notifyCollisions(True) self.world.attachRigidBody(self.rocketNP.node()) for i in range(4): leg = BulletCylinderShape(0.1 * self.radius, 0.5 * self.length, XUp) self.rocketNP.node().addShape(leg, TransformState.makePosHpr( Vec3(6 * self.radius * math.cos(i * math.pi / 2), 6 * self.radius * math.sin(i * math.pi / 2), -0.6 * self.length), Vec3(i * 90, 0, 30))) shape = BulletConeShape(0.75 * self.radius, 0.5 * self.radius, ZUp) self.rocketNP.node().addShape(shape, TransformState.makePosHpr(Vec3(0, 0, -1 / 2 * self.length), Vec3(0, 0, 0))) # Fuel self.fuelRadius = 0.9 * self.radius shape = BulletCylinderShape(self.fuelRadius, 0.01 * self.length, ZUp) self.fuelNP = self.worldNP.attachNewNode(BulletRigidBodyNode('Cone')) self.fuelNP.node().setMass(self.fuelMass_full * self.fuelMass_init) self.fuelNP.node().addShape(shape) self.fuelNP.setPos(0, 0, self.rocketNP.getPos().getZ() - self.length * 0.5 * (1 - self.fuelMass_init)) self.fuelNP.setCollideMask(BitMask32.allOn()) self.fuelNP.node().setCollisionResponse(0) self.world.attachRigidBody(self.fuelNP.node()) frameA = TransformState.makePosHpr(Point3(0, 0, 0), Vec3(0, 0, 90)) frameB = TransformState.makePosHpr(Point3(0, 0, 0), Vec3(0, 0, 90)) self.fuelSlider = BulletSliderConstraint(self.rocketNP.node(), self.fuelNP.node(), frameA, frameB, 1) self.fuelSlider.setTargetLinearMotorVelocity(0) self.fuelSlider.setDebugDrawSize(2.0) self.fuelSlider.set_lower_linear_limit(0) self.fuelSlider.set_upper_linear_limit(0) self.world.attachConstraint(self.fuelSlider) self.npThrustForce = LineNodePath(self.rocketNP, 'Thrust', thickness=4, colorVec=Vec4(1, 0.5, 0, 1)) self.npDragForce = LineNodePath(self.rocketNP, 'Drag', thickness=4, colorVec=Vec4(1, 0, 0, 1)) self.npLiftForce = LineNodePath(self.rocketNP, 'Lift', thickness=4, colorVec=Vec4(0, 0, 1, 1)) self.npFuelState = LineNodePath(self.fuelNP, 'Fuel', thickness=20, colorVec=Vec4(0, 1, 0, 1)) self.rocketCSLon = self.radius ** 2 * math.pi self.rocketCSLat = self.length * 2 * self.radius if self.VISUALIZE is True: self.terrain = loader.loadModel("LZGrid2.egg") self.terrain.setScale(10) self.terrain.reparentTo(self.render) self.terrain.setColor(Vec4(0.1, 0.2, 0.1, 1)) self.toggleTexture() #self.fuelNP.setPos(0, 0, self.rocketNP.getPos().getZ() - self.length * 0.4 * (1 - self.fuelMass_init)) for i in range(5): self.world.doPhysics(self.dt, 5, 1.0 / 180.0) self.fuelSlider.set_lower_linear_limit(-self.length * 0.5 * (1 - self.fuelMass_init)) self.fuelSlider.set_upper_linear_limit(self.length * 0.5 * (1 - self.fuelMass_init)) for i in range(100): self.world.doPhysics(self.dt, 5, 1.0 / 180.0) self.rocketNP.node().applyForce(Vec3(0,0,300000), Vec3(0, 0, 0))
def __init__(self): ShowBase.__init__(self) wp = core.WindowProperties() wp.setTitle("Dorfdelf") self.win.requestProperties(wp) self.render.setAntialias(core.AntialiasAttrib.MAuto) self.setBackgroundColor(0.5, 0.5, 0.5) self.disableMouse() self.enableParticles() font = self.loader.loadFont('media/calibri.ttf') font.setPixelsPerUnit(120) font.setPageSize(512, 1024) loading = OnscreenText(text='Loading...', scale=0.2, pos=(0.0, 0.0), fg=(1, 1, 1, 1), shadow=(0.3, 0.3, 0.3, 1.0), align=core.TextNode.ACenter, mayChange=True, font=font, parent=self.aspect2d) self.graphicsEngine.renderFrame() self.graphicsEngine.renderFrame() loading.setText('Generating world') self.graphicsEngine.renderFrame() self.graphicsEngine.renderFrame() self.world = world.World(128, 128, 100) self.world.generate() loading.setText('Creating world geometry') self.graphicsEngine.renderFrame() self.graphicsEngine.renderFrame() self.world_geometry = geometry.WorldGeometry(self.world) self.camLens.setFocalLength(1) self.camera.setPos(0, 0, 100) self.camera.lookAt(self.world.midpoint.x, self.world.midpoint.y, 100) self.cam.setPos(0, 0, 0) self.cam.setHpr(0, -45, 0) self.cc = camera.CameraController(self.world.size, self.mouseWatcherNode, self.camera, self.cam) self.gui = gui.GUI(self.pixel2d, font) self.world_geometry.node.setPos(0, 0, 0) self.world_geometry.node.reparentTo(self.render) self.explore_mode = True self.current_slice = int(self.world.midpoint.z) self.accept_keyboard() self.accept('mouse1', self.toggle_block) self.accept('console-command', self.console_command) self.designation = designation.Designation() self.dorfs = [] self.tool = lambda w, x, y, z: None self.toolargs = () self.tools = { 'bomb': tools.bomb, 'block': tools.block, 'd': self.designation.add } self.console = console.Console(self) self.picker = block_picker.BlockPicker(self.world, self) self.zmap = zmap.ZMap(self.world, self) self.change_slice(0) arrow = LineNodePath() arrow.reparentTo(self.render) arrow.drawArrow2d(Vec3(-5, -5, self.world.midpoint.z), Vec3(15, -5, self.world.midpoint.z), 30, 3) arrow.create() loading.hide()
def __init__(self, id, toNpcId=20001, fAutonomous=1): # Default NPC ID is Flippy Toon.Toon.__init__(self) self.id = id self.fAutonomous = fAutonomous npcInfo = NPCToons.NPCToonDict[toNpcId] dnaList = npcInfo[2] gender = npcInfo[3] dna = ToonDNA.ToonDNA() dna.newToonFromProperties(*dnaList) self.setDNA(dna) self.reparentTo(render) self.angleNP = self.find('**/actorGeom') # Create pole self.pole = Actor.Actor() self.pole.loadModel('phase_4/models/props/fishing-pole-mod') self.pole.loadAnims({'cast': 'phase_4/models/props/fishing-pole-chan'}) # Get the top of the pole. self.ptop = self.pole.find('**/joint_attachBill') self.pole.pose('cast', 0) # Prepare Pole self.poleNode = [] self.holdPole() self.createCastTrack() self.castIval = None # Prepare actor self.setupNeutralBlend() self.targetInterval = None # Start automatic casting or create cast button if self.fAutonomous: self.castButton = None self.targetButton = None self.startCasting() else: # Starts casting mode when mouse enters button region self.castButton = DirectButton(text='CAST', relief=None, scale=0.1, pos=(0, 0, -0.2)) self.castButton.bind(DGG.ENTER, self.showCancelFrame) # A big screen encompassing frame to catch the button releases self.cancelFrame = DirectFrame(parent=self.castButton, frameSize=(-1, 1, -1, 1), relief=None, state='normal') # Make sure this is on top of all the other widgets self.cancelFrame.setBin('gui-popup', 0) self.cancelFrame.bind(DGG.B1PRESS, self.startAdjustingCastTask) self.cancelFrame.bind(DGG.B1RELEASE, self.finishCast) self.cancelFrame.hide() # Create bob self.bob = loader.loadModel('phase_4/models/props/fishing_bob') self.bobSpot = Point3(0) # Parameters to control bob motion self.vZeroMax = 30.0 self.angleMax = 30.0 # Ripple effect self.ripples = Ripples.Ripples(self.angleNP) self.ripples.hide() # Target self.buttonFrame = DirectFrame() self.target = base.distributedFishingTarget.fishingTargetNode self.fishPivot = self.attachNewNode('fishPivot') self.fish = loader.loadModel('models/misc/smiley') self.fish.reparentTo(self.fishPivot) self.fish.setScale(0.3, 1, 0.3) self.wiggleIval = None self.circleIval = None self.initFish() self.targetButton = DirectButton(parent=self.buttonFrame, text='MOVE', relief=DGG.RAISED, scale=0.1, pos=(0, 0, -0.9), command=self.moveTarget) self.targetTypeButton = DirectCheckButton(parent=self.buttonFrame, text='MOVING', relief=DGG.RAISED, scale=0.085, pos=(0.4, 0, -0.895), command=self.setfMove) self.fMovingTarget = 0 self.targetModeButton = DirectCheckButton( parent=self.buttonFrame, text='dTASK', relief=DGG.RAISED, scale=0.085, pos=(0.8, 0, -0.895), command=self.setfTargetMode) self.fTargetMode = 0 # Vector line self.line = LineNodePath(render2d) self.line.setColor(VBase4(1, 0, 0, 1)) self.line.moveTo(0, 0, 0) self.line.drawTo(1, 0, 0) self.line.create() self.moveTarget()
def __init__(self, world, render, position, direction, side, torso, limits): radius = 0.15 bicep_length = 0.75 forearm_length = 0.75 in_limit, out_limit, forward_limit, backward_limit, twist_limit = limits torso_pos = torso.getPos() x, y, z = position bicep_y = y + direction * bicep_length / 2 forearm_y = y + direction * bicep_length + forearm_length / 2 bicep_node = BulletRigidBodyNode('Bicep') bicep_node.addShape(BulletCapsuleShape(radius, bicep_length, 1)) bicep_node.setMass(0.25) bicep_pointer = render.attachNewNode(bicep_node) bicep_pointer.setPos(x, bicep_y, z) world.attachRigidBody(bicep_node) forearm_node = BulletRigidBodyNode('Forearm') forearm_node.addShape(BulletCapsuleShape(radius, forearm_length, 1)) forearm_node.setMass(0.25) forearm_pointer = render.attachNewNode(forearm_node) forearm_pointer.setPos(x, forearm_y, z) world.attachRigidBody(forearm_node) rotation = LMatrix3((-direction, 0, 0), (0, 0, -side), (0, -side * direction, 0)) bicep_to_shoulder = Vec3(0, -direction * bicep_length / 2, 0) torso_to_shoulder = Vec3(0, y + torso_pos[1], z - torso_pos[2]) bicep_shoulder_frame = make_rigid_transform(rotation, bicep_to_shoulder) torso_shoulder_frame = make_rigid_transform(rotation, torso_to_shoulder) shoulder = BulletGenericConstraint(torso.node(), bicep_node, torso_shoulder_frame, bicep_shoulder_frame, True) shoulder.setDebugDrawSize(0.3) world.attachConstraint(shoulder, True) elbow_axis = Vec3(0, 0, side) forearm_to_elbow = Point3(0, -direction * forearm_length / 2, 0) bicep_to_elbow = Point3(0, direction * bicep_length / 2, 0) elbow = BulletHingeConstraint(bicep_node, forearm_node, bicep_to_elbow, forearm_to_elbow, elbow_axis, elbow_axis, True) elbow.setDebugDrawSize(0.3) world.attachConstraint(elbow, True) for axis in range(3): shoulder.getRotationalLimitMotor(axis).setMaxMotorForce(200) elbow.setMaxMotorImpulse(200) shoulder.setAngularLimit(0, -in_limit, out_limit) shoulder.setAngularLimit(1, -twist_limit, twist_limit) shoulder.setAngularLimit(2, -backward_limit, forward_limit) elbow.setLimit(0, 180) self.render = render self.position = position self.bicep = bicep_pointer self.forearm = forearm_pointer self.shoulder = shoulder self.elbow = elbow self.transform = LMatrix3(-side * direction, 0, 0, 0, -direction, 0, 0, 0, 1) self.side = side self.lines = LineNodePath(name='debug', parent=self.render, colorVec=VBase4(0.2, 0.2, 0.5, 1)) axes = LineNodePath(name='axes', parent=self.render) paths = [ dict(color=VBase4(1, 0, 0, 1)), dict(color=VBase4(0, 1, 0, 1)), dict(color=VBase4(0, 0, 1, 1)) ] for i in range(3): axis = shoulder.getAxis(i) * 0.25 paths[i]['points'] = [axis] draw_lines(axes, *paths, origin=position)
def refresh(self): # sanity check so we don't get here to early if not hasattr(self, "bounds"): return self.frameInitialiseFunc() textLeftSizeArea = self['numberAreaWidth'] # get the left and right edge of our frame left = DGH.getRealLeft(self) right = DGH.getRealRight(self) diagramLeft = left + textLeftSizeArea xStep = (DGH.getRealWidth(self) - textLeftSizeArea) / (len(self['data']) - 1) posYRes = DGH.getRealTop(self) / (self['numPosSteps'] if self['numPosSteps'] > 0 else max( self['data'])) negYRes = DGH.getRealBottom(self) / (-self['numNegSteps'] if self['numNegSteps'] > 0 else min(self['data'])) # remove old content if self.lines is not None: self.lines.removeNode() if self.measureLines is not None: self.measureLines.removeNode() if self.centerLine is not None: self.centerLine.removeNode() for text in self.xDescriptions: text.removeNode() self.xDescriptions = [] for text in self.points: text.removeNode() self.points = [] # prepare the line drawings self.lines = LineNodePath(parent=self, thickness=3.0, colorVec=(1, 0, 0, 1)) self.measureLines = LineNodePath(parent=self, thickness=1.0, colorVec=(0, 0, 0, 1)) self.centerLine = LineNodePath(parent=self, thickness=2.0, colorVec=(0, 0, 0, 1)) # draw the center line self.centerLine.reset() self.centerLine.drawLines([((diagramLeft, 0, 0), (right, 0, 0))]) self.centerLine.create() self.xDescriptions.append( self.createcomponent('value0', (), None, DirectLabel, (self, ), text="0", text_scale=self['numtextScale'], text_align=TextNode.ARight, pos=(diagramLeft, 0, -0.01), relief=None, state='normal')) # calculate the positive measure lines and add the numbers measureLineData = [] numSteps = (self['numPosSteps'] if self['numPosSteps'] > 0 else math.floor(max(self['data']))) + 1 for i in range(1, numSteps, self['numPosStepsStep']): measureLineData.append( ((diagramLeft, 0, i * posYRes), (right, 0, i * posYRes))) calcBase = 1 / DGH.getRealTop(self) maxData = self['numPosSteps'] if self['numPosSteps'] > 0 else max( self['data']) value = self['stepFormat'](round(i * posYRes * calcBase * maxData, self['stepAccuracy'])) y = i * posYRes self.xDescriptions.append( self.createcomponent('value{}'.format(value), (), None, DirectLabel, (self, ), text=str(value), text_scale=self['numtextScale'], text_align=TextNode.ARight, pos=(diagramLeft, 0, y - 0.025), relief=None, state='normal')) # calculate the negative measure lines and add the numbers numSteps = (self['numNegSteps'] if self['numNegSteps'] > 0 else math.floor(abs(min(self['data'])))) + 1 for i in range(1, numSteps, self['numNegStepsStep']): measureLineData.append( ((diagramLeft, 0, -i * negYRes), (right, 0, -i * negYRes))) calcBase = 1 / DGH.getRealBottom(self) maxData = self['numPosSteps'] if self['numPosSteps'] > 0 else max( self['data']) value = self['stepFormat'](round(i * negYRes * calcBase * maxData, self['stepAccuracy'])) y = -i * negYRes self.xDescriptions.append( self.createcomponent('value{}'.format(value), (), None, DirectLabel, (self, ), text=str(value), text_scale=self['numtextScale'], text_align=TextNode.ARight, pos=(diagramLeft, 0, y + 0.01), relief=None, state='normal')) # Draw the lines self.measureLines.reset() self.measureLines.drawLines(measureLineData) self.measureLines.create() lineData = [] for i in range(1, len(self['data'])): yResA = posYRes if self['data'][i - 1] >= 0 else negYRes yResB = posYRes if self['data'][i] >= 0 else negYRes lineData.append(( # Point A (diagramLeft + (i - 1) * xStep, 0, self['data'][i - 1] * yResA ), # Point B (diagramLeft + i * xStep, 0, self['data'][i] * yResB))) if (self['showDataNumbers']): value = round(self['data'][i - 1], self['stepAccuracy']) self.points.append( self.createcomponent('value{}'.format(value), (), None, DirectLabel, (self, ), text=str(value), text_scale=self['dataNumtextScale'], text_align=TextNode.ARight, pos=(diagramLeft + (i - 1) * xStep, 0, self['data'][i - 1] * yResA), relief=None, state='normal')) # Draw the lines self.lines.reset() self.lines.drawLines(lineData) self.lines.create()
from direct.gui.DirectGui import * from pandac.PandaModules import * from direct.directtools.DirectGeometry import LineNodePath from direct.gui.OnscreenText import OnscreenText import buttonsGRID global output output = [1] textObject = OnscreenText(text="gridUNITS", pos=(-1.23, .94), scale=0.04, fg=(0, 0, 0, .8)) textObject.setTransparency(TransparencyAttrib.MAlpha) line = LineNodePath(render2d, 'line', 2, Vec4(.3, .3, .3, 0)) line.drawLines([[(-.76, 0, 1), (-.76, 0, -1)]]) line.create() def react(input): output.append(input) print output def clear(): gU.enterText('') gU = DirectEntry(text="",
from pandac.PandaModules import * from direct.directtools.DirectGeometry import LineNodePath import direct.directbase.DirectStart from pandac.PandaModules import Point3, Vec3, Vec4 raws1unit = 20 rawsfithunit = 100 d = 0 X1 = 10 X2 = -10 Y1 = 10 Y2 = -10 linesX = LineNodePath(render, 'quad', 2, Vec4(.3, .3, .3, .3)) linesXX = LineNodePath(render, 'quad', 1, Vec4(.3, .3, .3, .3)) axis = LineNodePath(render, 'axis', 4, Vec4(.2, .2, .2, .2)) quad = LineNodePath(render, 'quad', 4, Vec4(.2, .2, .2, .2)) x1 = (0, Y2, 0) x2 = (0, Y1, 0) x3 = (X2, 0, 0) x4 = (X1, 0, 0) axis.drawLines([[x1, x2], [x3, x4]]) axis.create() q1 = (X1, Y1, 0) q2 = (X1, Y2, 0) q3 = (q2)
def __init__(self, width=6.78, length=5.82, simulation=True, video=True): ShowBase.__init__(self) width *= 100 length *= 100 self.room_dimentions = [width, length] self.simulation = simulation self.wall1 = self.wall_model(0, 0, 0, width, 0) self.wall2 = self.wall_model(0, 0, 0, length, 90) self.wall3 = self.wall_model(width, length, 0, width, 180) self.wall4 = self.wall_model(width, length, 0, length, -90) self.root_3d = self.marker_model(position=[0., 0., 0.], orientation=[90, 90, 0]) self.drone = self.drone_model() self.drone_instance = Drone(simulation=simulation, video=video) self.lx_drone = LineNodePath(self.render2d, 'box', 2) self.lx_drone.reparentTo(self.drone) self.lx_drone.setColor(1., 0., 0., 1.) self.lx_drone.setTransparency(TransparencyAttrib.MAlpha) self.lx_drone.setAlphaScale(0.5) self.lx_drone.drawLines([[(0., 0., 0.), (4., 0., 0.)]]) self.lx_drone.create() self.ly_drone = LineNodePath(self.render2d, 'box', 2) self.ly_drone.reparentTo(self.drone) self.ly_drone.setColor(0., 1., 0., 1.) self.ly_drone.setTransparency(TransparencyAttrib.MAlpha) self.ly_drone.setAlphaScale(0.5) self.ly_drone.drawLines([[(0., 0., 0.), (0., 0., 4.)]]) self.ly_drone.create() self.lz_drone = LineNodePath(self.render2d, 'box', 2) self.lz_drone.reparentTo(self.drone) self.lz_drone.setColor(0., 0., 1., 1.) self.lz_drone.setTransparency(TransparencyAttrib.MAlpha) self.lz_drone.setAlphaScale(0.5) self.lz_drone.drawLines([[(0., 0., 0.), (0., 4., 0.)]]) self.lz_drone.create() try: self.joy = xbox.Joystick() joy_ready = False if not self.joy.A(): joy_ready = True if not joy_ready: raise Exception("Joy not ready!") else: print("ready") except: pass # Add the spinCameraTask procedure to the task manager. self.tick_loop = self.taskMgr.add(self.tick, "tick_loop") self.accept("space", self.control_drone, [" "]) self.accept("c", self.control_drone, ["c"]) self.accept("x", self.control_drone, ["x"]) self.accept("w", self.control_drone, ["w"]) self.accept("a", self.control_drone, ["a"]) self.accept("s", self.control_drone, ["s"]) self.accept("d", self.control_drone, ["d"]) self.accept("q", self.control_drone, ["q"]) self.accept("e", self.control_drone, ["e"]) self.accept("m", self.control_drone, ["m"]) self.accept("r", self.control_drone, ["r"]) self.accept("f", self.control_drone, ["f"]) self.keypress_repeat("4", self.move_camera, ["x", -1]) self.keypress_repeat("6", self.move_camera, ["x", 1]) self.keypress_repeat("8", self.move_camera, ["y", 1]) self.keypress_repeat("5", self.move_camera, ["y", -1]) self.keypress_repeat("1", self.move_camera, ["z", 1]) self.keypress_repeat("3", self.move_camera, ["z", -1]) self.keypress_repeat("7", self.move_camera, ["h", -1]) self.keypress_repeat("9", self.move_camera, ["h", 1]) self.keypress_repeat("arrow_up", self.move_camera, ["p", 1]) self.keypress_repeat("arrow_down", self.move_camera, ["p", -1])
def setup(self): self.worldNP = render.attachNewNode('World') # World self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug')) self.debugNP.show() self.debugNP.node().showWireframe(True) self.debugNP.node().showConstraints(True) self.debugNP.node().showBoundingBoxes(False) self.debugNP.node().showNormals(True) #self.debugNP.showTightBounds() #self.debugNP.showBounds() self.world = BulletWorld() self.world.setGravity(Vec3(0, 0, -9.81)) self.world.setDebugNode(self.debugNP.node()) # Ground (static) shape = BulletPlaneShape(Vec3(0, 0, 1), 1) self.groundNP = self.worldNP.attachNewNode( BulletRigidBodyNode('Ground')) self.groundNP.node().addShape(shape) self.groundNP.setPos(0, 0, -2) self.groundNP.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.groundNP.node()) #Rocket shape = BulletCylinderShape(0.2 * self.scale, 2 * self.scale, ZUp) self.rocketNP = self.worldNP.attachNewNode( BulletRigidBodyNode('Cylinder')) self.rocketNP.node().setMass(3.0) self.rocketNP.node().addShape(shape) self.rocketNP.setPos(0, 0, 2 * self.scale) self.rocketNP.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.rocketNP.node()) for i in range(4): leg = BulletCylinderShape(0.02 * self.scale, 1 * self.scale, XUp) self.rocketNP.node().addShape( leg, TransformState.makePosHpr( Vec3(0.6 * self.scale * math.cos(i * math.pi / 2), 0.6 * self.scale * math.sin(i * math.pi / 2), -1.2 * self.scale), Vec3(i * 90, 0, 30))) shape = BulletConeShape(0.15 * self.scale, 0.3 * self.scale, ZUp) self.rocketNozzle = self.worldNP.attachNewNode( BulletRigidBodyNode('Cone')) self.rocketNozzle.node().setMass(1) self.rocketNozzle.node().addShape(shape) self.rocketNozzle.setPos(0, 0, 0.8 * self.scale) self.rocketNozzle.setCollideMask(BitMask32.allOn()) self.rocketNozzle.node().setCollisionResponse(0) self.world.attachRigidBody(self.rocketNozzle.node()) frameA = TransformState.makePosHpr(Point3(0, 0, -1 * self.scale), Vec3(0, 0, 90)) frameB = TransformState.makePosHpr(Point3(0, 0, 0.2 * self.scale), Vec3(0, 0, 90)) self.cone = BulletConeTwistConstraint(self.rocketNP.node(), self.rocketNozzle.node(), frameA, frameB) self.cone.enableMotor(1) #self.cone.setMaxMotorImpulse(2) #self.cone.setDamping(1000) self.cone.setDebugDrawSize(2.0) self.cone.setLimit(20, 20, 0, softness=1.0, bias=1.0, relaxation=10.0) self.world.attachConstraint(self.cone) self.npThrustForce = LineNodePath(self.render, 'Thrust', thickness=4, colorVec=VBase4(1, 0.5, 0, 1))
arrowLENGHT = PX + .2 arrowXx1 = PY + .08 arrowXx2 = PY - .08 arrowXz2 = PX + 1.3 arrowYx1 = PX + .08 arrowYx2 = PX - .08 arrowYz2 = PY + 1.3 arrowZx1 = PX + .08 arrowZx2 = PX - .08 arrowZz2 = PZ + 1.3 PIVarX = LineNodePath(render, 'pivotX', 3, Vec4(1, 0, 0, 1)) PIVarY = LineNodePath(render, 'pivotY', 3, Vec4(0, 1, 1, 1)) PIVarZ = LineNodePath(render, 'pivotZ', 3, Vec4(1, 1, 0, 1)) PIVOThandler = LineNodePath(render, 'handler', 2, Vec4(1, 0, 1, 1)) arrowX1 = (lengthX, PY, PZ) arrowX2 = (arrowXz2, arrowXx1, PZ) arrowX3 = (arrowXz2, arrowXx2, PZ) arrowY1 = (PX, lengthY, PZ) arrowY2 = (arrowYx1, arrowYz2, PZ) arrowY3 = (arrowYx2, arrowYz2, PZ) arrowZ1 = (PX, PY, lengthZ) arrowZ2 = (arrowZx1, PY, arrowZz2)
# Create the joints smileyJoint = OdeBallJoint(world) smileyJoint.attach(smileyBody, None) # Attach it to the environment smileyJoint.setAnchor(0, 0, 0) frowneyJoint = OdeBallJoint(world) frowneyJoint.attach(smileyBody, frowneyBody) frowneyJoint.setAnchor(-5, 0, -5) # Set the camera position base.disableMouse() base.camera.setPos(0, 50, -7.5) base.camera.lookAt(0, 0, -7.5) # We are going to be drawing some lines between the anchor points and the joints lines = LineNodePath(parent=render, thickness=3.0, colorVec=Vec4(1, 0, 0, 1)) def drawLines(): # Draws lines between the smiley and frowney. lines.reset() lines.drawLines([((frowney.getX(), frowney.getY(), frowney.getZ()), (smiley.getX(), smiley.getY(), smiley.getZ())), ((smiley.getX(), smiley.getY(), smiley.getZ()), (0, 0, 0)) ]) lines.create() # The task for our simulation def simulationTask(task): # Step the simulation and set the new positions
def setup(self): #self.targetAlt = r.randrange(100,300) self.Valves = np.array([0.15, 0.2, 0.15]) self.EngObs = self.vulcain.predict_data_point( np.array(self.Valves).reshape(1, -1)) if self.VISUALIZE is True: self.worldNP = self.render.attachNewNode('World') else: self.root = NodePath(PandaNode("world root")) self.worldNP = self.root.attachNewNode('World') self.world = BulletWorld() self.world.setGravity(Vec3(0, 0, -9.80665)) # World self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug')) self.debugNP.node().showWireframe(True) self.debugNP.node().showConstraints(True) self.debugNP.node().showBoundingBoxes(False) self.debugNP.node().showNormals(True) self.debugNP.show() self.world.setDebugNode(self.debugNP.node()) # self.debugNP.showTightBounds() # self.debugNP.showBounds() # Ground (static) shape = BulletPlaneShape(Vec3(0, 0, 1), 1) self.groundNP = self.worldNP.attachNewNode( BulletRigidBodyNode('Ground')) self.groundNP.node().addShape(shape) self.groundNP.setPos(0, 0, 0) self.groundNP.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.groundNP.node()) # Rocket shape = BulletCylinderShape(self.radius, self.length, ZUp) self.rocketNP = self.worldNP.attachNewNode( BulletRigidBodyNode('Cylinder')) self.rocketNP.node().setMass(self.drymass + self.fuelAmount_LH2 + self.fuelAmount_LOX) self.rocketNP.node().addShape(shape) #self.rocketNP.setPos(20,20,250) self.rocketNP.setPos(r.randrange(-200, 200), 20, 350) #r.randrange(300, 500)) #self.rocketNP.setPos(r.randrange(-self.lateralError, self.lateralError, 1), r.randrange(-self.lateralError, self.lateralError, 1), self.height) # self.rocketNP.setPos(0, 0, self.length*10) self.rocketNP.setCollideMask(BitMask32.allOn()) # self.rocketNP.node().setCollisionResponse(0) self.rocketNP.node().notifyCollisions(True) self.world.attachRigidBody(self.rocketNP.node()) for i in range(4): leg = BulletCylinderShape(0.1 * self.radius, 0.5 * self.length, XUp) self.rocketNP.node().addShape( leg, TransformState.makePosHpr( Vec3(6 * self.radius * math.cos(i * math.pi / 2), 6 * self.radius * math.sin(i * math.pi / 2), -0.6 * self.length), Vec3(i * 90, 0, 30))) shape = BulletConeShape(0.75 * self.radius, 0.5 * self.radius, ZUp) self.rocketNP.node().addShape( shape, TransformState.makePosHpr(Vec3(0, 0, -1 / 2 * self.length), Vec3(0, 0, 0))) self.npThrustForce = LineNodePath(self.rocketNP, 'Thrust', thickness=4, colorVec=Vec4(1, 0.5, 0, 1)) self.npDragForce = LineNodePath(self.rocketNP, 'Drag', thickness=4, colorVec=Vec4(1, 0, 0, 1)) self.npLiftForce = LineNodePath(self.rocketNP, 'Lift', thickness=4, colorVec=Vec4(0, 0, 1, 1)) self.rocketCSLon = self.radius**2 * math.pi self.rocketCSLat = self.length * 2 * self.radius if self.VISUALIZE is True: self.terrain = loader.loadModel("../LZGrid2.egg") self.terrain.setScale(10) self.terrain.reparentTo(self.render) self.terrain.setColor(Vec4(0.1, 0.2, 0.1, 1)) self.toggleTexture()