DirectGeometry.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from PandaObject import *
  2. class LineNodePath(NodePath):
  3. def __init__(self, parent = None, **kw):
  4. # Initialize the superclass
  5. NodePath.__init__(self)
  6. if parent is None:
  7. parent = hidden
  8. # Attach a geomNode to the parent and set self to be
  9. # the resulting node path
  10. self.lineNode = GeomNode()
  11. self.assign(parent.attachNewNode( self.lineNode ))
  12. # Create a lineSegs object to hold the line
  13. ls = self.lineSegs = LineSegs()
  14. # Initialize the lineSegs parameters
  15. ls.setThickness( kw.get('thickness', 1.0) )
  16. ls.setColor( kw.get('colorVec', VBase4(1.0)) )
  17. def moveTo( self, *_args ):
  18. apply( self.lineSegs.moveTo, _args )
  19. def drawTo( self, *_args ):
  20. apply( self.lineSegs.drawTo, _args )
  21. def create( self, frameAccurate = 0 ):
  22. self.lineSegs.create( self.lineNode, frameAccurate )
  23. def reset( self ):
  24. self.lineSegs.reset()
  25. self.lineNode.clear()
  26. def isEmpty( self ):
  27. return self.lineSegs.isEmpty()
  28. def setThickness( self, thickness ):
  29. self.lineSegs.setThickness( thickness )
  30. def setColor( self, *_args ):
  31. apply( self.lineSegs.setColor, _args )
  32. def setVertex( self, *_args):
  33. apply( self.lineSegs.setVertex, _args )
  34. def setVertexColor( self, vertex, *_args ):
  35. apply( self.lineSegs.setVertexColor, (vertex,) + _args )
  36. def getCurrentPosition( self ):
  37. return self.lineSegs.getCurrentPosition()
  38. def getNumVertices( self ):
  39. return self.lineSegs.getNumVertices()
  40. def getVertex( self, index ):
  41. return self.lineSegs.getVertex(index)
  42. def getVertexColor( self ):
  43. return self.lineSegs.getVertexColor()
  44. ##
  45. ## Given a point in space, and a direction, find the point of intersection
  46. ## of that ray with a plane at the specified origin, with the specified normal
  47. def planeIntersect (lineOrigin, lineDir, planeOrigin, normal):
  48. t = 0
  49. offset = planeOrigin - lineOrigin
  50. t = offset.dot(normal) / lineDir.dot(normal)
  51. hitPt = lineDir * t
  52. return hitPt + lineOrigin