當前位置: 首頁>>代碼示例>>Python>>正文


Python LineSegs.setVertex方法代碼示例

本文整理匯總了Python中pandac.PandaModules.LineSegs.setVertex方法的典型用法代碼示例。如果您正苦於以下問題:Python LineSegs.setVertex方法的具體用法?Python LineSegs.setVertex怎麽用?Python LineSegs.setVertex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandac.PandaModules.LineSegs的用法示例。


在下文中一共展示了LineSegs.setVertex方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: MoveCursor

# 需要導入模塊: from pandac.PandaModules import LineSegs [as 別名]
# 或者: from pandac.PandaModules.LineSegs import setVertex [as 別名]
class MoveCursor(object):
    _EDGES      = 40
    _zPos       = 0
    _movingUp   = False
    _movingDown = False
    _color      = Vec4(0.3, 0.3, 0.8, 1)
    _currentPos = Vec3(0, 0, 0)
    
    def __init__(self, parent, entity, foot=1):
        # We keep a reference to the entity
        self.entity = entity
        
        # Setup the components of the cursor
        self._moveRadCircleNP  = NodePath("Movement Radius Node")
        self._moveLine         = LineSegs()
        self._moveLineNP       = NodePath("Movement Direction Line Node")
        self._moveZLine        = LineSegs()
        self._moveZLineNP      = NodePath("Movement Z Line Node")
        self._moveZFootNP      = NodePath("Movement Z Foot Node")
        self._moveFootCircle   = LineSegs()
        self._moveFootCircleNP = NodePath("Movement Foot Circle Node")
        self._np = NodePath("Movement Node")
        
        self.aaLevel = 16
        self.parent = parent
        self.start  = Vec3(0, 0, 0)
        self.moveRad = entity.moveRadius
        self.footRad = foot
        self.plane = Plane(Vec3(0, 0, 1), Point3(0, 0, 0))
        
        if self.aaLevel > 0:
            self._np.setAntialias(AntialiasAttrib.MLine, self.aaLevel)
        
        x = 0
        y = 0
        z = 0
        # Draw movement radius
        moveRadLine = LineSegs()
        moveRadLine.setThickness(1)
        moveRadLine.setColor(self._color)
        moveRadLine.moveTo(self.moveRad, 0, 0)
        for i in range(self._EDGES + 1):
            newX = (self.moveRad * math.cos((2*math.pi/self._EDGES)*i))
            newY = (self.moveRad * math.sin((2*math.pi/self._EDGES)*i))
            moveRadLine.drawTo(newX, newY, 0)
        moveRadGeom = moveRadLine.create()
        self._moveRadCircleNP = NodePath(moveRadGeom)
        self._moveRadCircleNP.reparentTo(self._np)
        
        # Draw movement foot circle
        self._moveFootCircle.setThickness(1)
        self._moveFootCircle.setColor(self._color)
        self._moveFootCircle.moveTo(self.footRad, 0, 0)
        for i in range(self._EDGES):
            newX = (self.footRad * math.cos((2*math.pi/self._EDGES)*i))
            newY = (self.footRad * math.sin((2*math.pi/self._EDGES)*i))
            self._moveFootCircle.drawTo(newX, newY, 0)
        self._moveFootCircle.drawTo(self.footRad, 0, 0)
        moveFootCircleGeom = self._moveFootCircle.create()
        self._moveFootCircleNP = NodePath(moveFootCircleGeom)
        self._moveFootCircleNP.reparentTo(self._np)
        
        # Draw movement direction line
        self._moveLine.setThickness(1)
        self._moveLine.setColor(self._color)
        self._moveLine.moveTo(0, 0, 0)
        self._moveLine.drawTo(x, y, z) 
        self.moveLineGO = self._moveLine.create(True)
        self._moveLineNP = NodePath(self.moveLineGO)
        self._moveLineNP.reparentTo(self._np)
        
    def updateMovePos(self, Task):
        # endPos must be transformed in the the coord sys of the model
        m_pos = self.getMouseXY()
        if m_pos is not None:
            # Transform current mouse pos
            endPos = self.parent.getRelativePoint(render, m_pos)
            
            # Adjust Z coord if needed
            if self._movingUp:
                self._zPos += 0.1
            elif self._movingDown:
                self._zPos -= 0.1
            endPos.setZ(self._zPos)
            
            # Check if we're trying to move too far, if not update pos
            dist = math.sqrt(endPos.getX()**2 + endPos.getY()**2 + 2*(endPos.getZ()**2))
            if dist <= self.moveRad:
                self._moveLine.setVertex(1, endPos)
                self._moveFootCircleNP.setPos(endPos)
                #self._currentPos = self.parent.getRelativePoint(self.parent, endPos)
                #print("endPos=%s"%endPos)
                #print("myRelPos=%s"%self._currentPos)
                self._currentPos = endPos
                
        return Task.cont
        
    def getMouseXY(self):
        # NOTE - this returns the mouse pos in the ships coord sys
        if base.mouseWatcherNode.hasMouse():
#.........這裏部分代碼省略.........
開發者ID:crempp,項目名稱:Fire-Water,代碼行數:103,代碼來源:GeomObjects.py

示例2: MoveCursor

# 需要導入模塊: from pandac.PandaModules import LineSegs [as 別名]
# 或者: from pandac.PandaModules.LineSegs import setVertex [as 別名]

#.........這裏部分代碼省略.........
		moveZLine = self._moveZLine.create()
		self._moveZLineNP = NodePath(moveZLine)
		self._moveZLineNP.reparentTo(self._np)
		
		# Draw Attack Radius
		self._attackRadCircle.setThickness(1)
		self._attackRadCircle.setColor(0.8, 0.0, 0.0, 1)
		self._attackRadCircle.moveTo(self.attackRad, 0, 0)
		for i in range(self._EDGES + 1):
			newX = (self.attackRad * math.cos((2*math.pi/self._EDGES)*i))
			newY = (self.attackRad * math.sin((2*math.pi/self._EDGES)*i))
			self._attackRadCircle.drawTo(newX, newY, 0)
		attackRadCircleGeom = self._attackRadCircle.create()
		self._attackRadCircleNP = NodePath(attackRadCircleGeom)
		self._attackRadCircleNP.reparentTo(self._np)
		
	def updateMovePos(self, Task):
		# endPos must be transformed in the the coord sys of the model
		m_pos = self.getMouseXY()
		if m_pos is not None:
			# Transform current mouse pos
			endPos = self.parent.getRelativePoint(render, m_pos)
			
			# Adjust Z coord if needed
			if self._movingUp:
				self._zPos += 0.1
			elif self._movingDown:
				self._zPos -= 0.1
			endPos.setZ(self._zPos)
			
			# Check if we're trying to move too far, if not update pos
			dist = math.sqrt(endPos.getX()**2 + endPos.getY()**2 + 2*(endPos.getZ()**2))
			if dist <= self.moveRad:
				self._moveLine.setVertex(1, endPos)
				self._moveFootCircleNP.setPos(endPos)
				self._moveZLine.setVertex(0, Point3(endPos.getX(), endPos.getY(), 0))
				self._moveZLine.setVertex(1, endPos)
				self._attackRadCircleNP.setPos(endPos)
				self._currentPos = render.getRelativePoint(self._np, endPos)
				
				# Check for attackable ships in range of current pos
				attackables = Entity.EntityManager().getEntitiesWithin(self._currentPos, self.attackRad)
				# Unhighlight ships no longer in range
				for e in self.attackables:
					if e not in attackables and isinstance(e, Entity.EntityShip):
						e.representation.unsetAttackable()
				# Highlight ships in range
				for e in attackables:
					if isinstance(e, Entity.EntityShip) and e != self.entity and e.owner != self.entity.owner:
						e.representation.setAttackable()
				self.attackables = attackables
		return Task.cont
		
	def onZChange(self, event):
		if event.type == 'E_Key_ZUp':
			self._movingDown = False
			self._movingUp = True
		if event.type == 'E_Key_ZDown':
			self._movingUp = False
			self._movingDown = True
		if event.type == 'E_Key_ZUp-up':
			self._movingUp = False
			self._movingDown = False
		if event.type == 'E_Key_ZDown-up':	
			self._movingUp = False
			self._movingDown = False
開發者ID:crempp,項目名稱:psg,代碼行數:70,代碼來源:GeomObjects.py


注:本文中的pandac.PandaModules.LineSegs.setVertex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。