def drawDirectionArrow(color, tailPoint, arrowBasePoint, tailRadius, scale, tailRadiusLimits = (), flipDirection = False, opacity = 1.0, numberOfSides = 20, glpane = None, scale_to_glpane = False ): """ Draw a directional arrow staring at <tailPoint> with an endpoint decided by the vector between <arrowBasePoint> and <tailPoint> and the glpane scale <scale> @param color : The arrow color @type color: Array @param tailPoint: The point on the arrow tail where the arrow begins. @type tailPoint: V @param arrowBasePoint: A point on the arrow where the arrow head begins(?? @type arrowBasePoint: V @param tailRadius: The radius of the arrow tail (cylinder radius representing the arrow tail) @type tailRaius: float @param opacity: The opacity decides the opacity (or transparent display) of the rendered arrow. By default it is rendered as a solid arrow. It varies between 0.0 to 1.0 ... 1.0 represents the solid arrow renderring style @type opacity: float @param numberOfSides: The total number of sides for the arrow head (a glePolycone) The default value if 20 (20 sided polycone) @type numberOfSides: int @param scale_to_glpane: If True, the arrow size will be determined by the glpane scale. """ #@See DnaSegment_ResizeHandle to see how the tailRadiusLimits #are defined. See also exprs.Arrow. Note that we are not using #argument 'scale' for this purpose because the if scale_to_glpane and glpane is not None: scaled_tailRadius = tailRadius*0.05*glpane.scale if tailRadiusLimits: min_tailRadius = tailRadiusLimits[0] max_tailRadius = tailRadiusLimits[1] if scaled_tailRadius < min_tailRadius: pass #use the provided tailRadius elif scaled_tailRadius > max_tailRadius: tailRadius = max_tailRadius else: tailRadius = scaled_tailRadius else: tailRadius = scaled_tailRadius vec = arrowBasePoint - tailPoint vec = scale*0.07*vec arrowBase = tailRadius*3.0 arrowHeight = arrowBase*1.5 axis = norm(vec) #as of 2008-03-03 scaledBasePoint is not used so commenting out. #(will be removed after more testing) ##scaledBasePoint = tailPoint + vlen(vec)*axis drawcylinder(color, tailPoint, arrowBasePoint, tailRadius, capped = True, opacity = opacity) ##pos = scaledBasePoint pos = arrowBasePoint arrowRadius = arrowBase gleSetNumSides(numberOfSides) drawpolycone(color, # Point array (the two endpoints not drawn.) [[pos[0] - 1 * axis[0], pos[1] - 1 * axis[1], pos[2] - 1 * axis[2]], [pos[0],# - axis[0], pos[1], #- axis[1], pos[2]], #- axis[2], [pos[0] + arrowHeight * axis[0], pos[1] + arrowHeight * axis[1], pos[2] + arrowHeight * axis[2]], [pos[0] + (arrowHeight + 1) * axis[0], pos[1] + (arrowHeight + 1) * axis[1], pos[2] + (arrowHeight + 1) * axis[2]]], [arrowRadius, arrowRadius, 0, 0], # Radius array opacity = opacity ) #reset the gle number of sides to the gle default of '20' gleSetNumSides(20)
def drawOriginAsSmallAxis(scale, origin, dashEnabled=False): """ Draws a small wireframe version of the origin. It is rendered as a 3D point at (0, 0, 0) with 3 small axes extending from it in the positive X, Y, Z directions. @see: drawaxes (related code) """ #Perhaps we should split this method into smaller methods? ninad060920 #Notes: #1. drawing arrowheads implemented on 060918 #2. ninad060921 Show the origin axes as dotted if behind the mode. #3. ninad060922 The arrow heads are drawn as wireframe cones if behind the # object the arrowhead size is slightly smaller (otherwise some portion of # the the wireframe arrow shows up! #4 .Making origin non-zoomable is acheived by replacing hardcoded 'n' with # glpane's scale - ninad060922 #ninad060922 in future , the following could be user preferences. if (dashEnabled): dashShrinkage = 0.9 else: dashShrinkage = 1 x1, y1, z1 = scale * 0.01, scale * 0.01, scale * 0.01 xEnd, yEnd, zEnd = scale * 0.04, scale * 0.09, scale * 0.025 arrowBase = scale * 0.0075 * dashShrinkage arrowHeight = scale * 0.035 * dashShrinkage lineWidth = 1.0 glPushMatrix() glTranslate(origin[0], origin[1], origin[2]) glDisable(GL_LIGHTING) glLineWidth(lineWidth) gleNumSides = gleGetNumSides() #Code to show hidden lines of the origin if some model obscures it # ninad060921 if dashEnabled: glLineStipple(2, 0xAAAA) glEnable(GL_LINE_STIPPLE) glDisable(GL_DEPTH_TEST) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) gleSetNumSides(5) else: gleSetNumSides(10) glBegin(GL_LINES) color = env.prefs[originAxisColor_prefs_key] glColor3fv(color) #start draw a point at origin . #ninad060922 is thinking about using GL_POINTS here glVertex(-x1, 0.0, 0.0) glVertex(x1, 0.0, 0.0) glVertex(0.0, -y1, 0.0) glVertex(0.0, y1, 0.0) glVertex(-x1, y1, z1) glVertex(x1, -y1, -z1) glVertex(x1, y1, z1) glVertex(-x1, -y1, -z1) glVertex(x1, y1, -z1) glVertex(-x1, -y1, z1) glVertex(-x1, y1, -z1) glVertex(x1, -y1, z1) #end draw a point at origin #start draw small origin axes glColor3fv(color) glVertex(xEnd, 0.0, 0.0) glVertex(0.0, 0.0, 0.0) glColor3fv(color) glVertex(0.0, yEnd, 0.0) glVertex(0.0, 0.0, 0.0) glColor3fv(color) glVertex(0.0, 0.0, zEnd) glVertex(0.0, 0.0, 0.0) glEnd() #end draw lines glLineWidth(1.0) # End push matrix for drawing various lines in the origin and axes. glPopMatrix() #start draw solid arrow heads for X , Y and Z axes glPushMatrix() glDisable(GL_CULL_FACE) glColor3fv(color) glTranslatef(xEnd, 0.0, 0.0) glRotatef(90, 0.0, 1.0, 0.0) glePolyCone( [[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight + 1]], None, [arrowBase, arrowBase, 0, 0]) glPopMatrix() glPushMatrix() glColor3fv(color) glTranslatef(0.0, yEnd, 0.0) glRotatef(-90, 1.0, 0.0, 0.0) glePolyCone( [[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight + 1]], None, [arrowBase, arrowBase, 0, 0]) glPopMatrix() glPushMatrix() glColor3fv(color) glTranslatef(0.0, 0.0, zEnd) glePolyCone( [[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight + 1]], None, [arrowBase, arrowBase, 0, 0]) #Disable line stipple and Enable Depth test if dashEnabled: glLineStipple(1, 0xAAAA) glDisable(GL_LINE_STIPPLE) glEnable(GL_DEPTH_TEST) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) gleSetNumSides(gleNumSides) glEnable(GL_CULL_FACE) glEnable(GL_LIGHTING) glPopMatrix() #end draw solid arrow heads for X , Y and Z axes return
def drawOriginAsSmallAxis(scale, origin, dashEnabled = False): """ Draws a small wireframe version of the origin. It is rendered as a 3D point at (0, 0, 0) with 3 small axes extending from it in the positive X, Y, Z directions. @see: drawaxes (related code) """ #Perhaps we should split this method into smaller methods? ninad060920 #Notes: #1. drawing arrowheads implemented on 060918 #2. ninad060921 Show the origin axes as dotted if behind the mode. #3. ninad060922 The arrow heads are drawn as wireframe cones if behind the # object the arrowhead size is slightly smaller (otherwise some portion of # the the wireframe arrow shows up! #4 .Making origin non-zoomable is acheived by replacing hardcoded 'n' with # glpane's scale - ninad060922 #ninad060922 in future , the following could be user preferences. if (dashEnabled): dashShrinkage = 0.9 else: dashShrinkage=1 x1, y1, z1 = scale * 0.01, scale * 0.01, scale * 0.01 xEnd, yEnd, zEnd = scale * 0.04, scale * 0.09, scale * 0.025 arrowBase = scale * 0.0075 * dashShrinkage arrowHeight = scale * 0.035 * dashShrinkage lineWidth = 1.0 glPushMatrix() glTranslate(origin[0], origin[1], origin[2]) glDisable(GL_LIGHTING) glLineWidth(lineWidth) gleNumSides = gleGetNumSides() #Code to show hidden lines of the origin if some model obscures it # ninad060921 if dashEnabled: glLineStipple(2, 0xAAAA) glEnable(GL_LINE_STIPPLE) glDisable(GL_DEPTH_TEST) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) gleSetNumSides(5) else: gleSetNumSides(10) glBegin(GL_LINES) color = env.prefs[originAxisColor_prefs_key] glColor3fv(color) #start draw a point at origin . #ninad060922 is thinking about using GL_POINTS here glVertex(-x1, 0.0, 0.0) glVertex( x1, 0.0, 0.0) glVertex(0.0, -y1, 0.0) glVertex(0.0, y1, 0.0) glVertex(-x1, y1, z1) glVertex( x1, -y1, -z1) glVertex(x1, y1, z1) glVertex(-x1, -y1, -z1) glVertex(x1, y1, -z1) glVertex(-x1, -y1, z1) glVertex(-x1, y1, -z1) glVertex(x1, -y1, z1) #end draw a point at origin #start draw small origin axes glColor3fv(color) glVertex(xEnd, 0.0, 0.0) glVertex( 0.0, 0.0, 0.0) glColor3fv(color) glVertex(0.0, yEnd, 0.0) glVertex(0.0, 0.0, 0.0) glColor3fv(color) glVertex(0.0, 0.0, zEnd) glVertex(0.0, 0.0, 0.0) glEnd() #end draw lines glLineWidth(1.0) # End push matrix for drawing various lines in the origin and axes. glPopMatrix() #start draw solid arrow heads for X , Y and Z axes glPushMatrix() glDisable(GL_CULL_FACE) glColor3fv(color) glTranslatef(xEnd, 0.0, 0.0) glRotatef(90, 0.0, 1.0, 0.0) glePolyCone([[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight+1]], None, [arrowBase, arrowBase, 0, 0]) glPopMatrix() glPushMatrix() glColor3fv(color) glTranslatef(0.0, yEnd, 0.0) glRotatef(-90, 1.0, 0.0, 0.0) glePolyCone([[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight+1]], None, [arrowBase, arrowBase, 0, 0]) glPopMatrix() glPushMatrix() glColor3fv(color) glTranslatef(0.0,0.0,zEnd) glePolyCone([[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight+1]], None, [arrowBase, arrowBase, 0, 0]) #Disable line stipple and Enable Depth test if dashEnabled: glLineStipple(1, 0xAAAA) glDisable(GL_LINE_STIPPLE) glEnable(GL_DEPTH_TEST) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) gleSetNumSides(gleNumSides) glEnable(GL_CULL_FACE) glEnable(GL_LIGHTING) glPopMatrix() #end draw solid arrow heads for X , Y and Z axes return