def __init__(self, joint, radius=0.05): """Constructor. \param joint (\c Joint) The joint that uses this geom \param radius (\c float) Radius of the wire sphere at the joint position """ GeomObject.__init__(self) self.joint = joint self.radius = radius self.spheregeom = SphereGeom(radius=self.radius, segmentsu=8, segmentsv=4)
class JointGeom(GeomObject): """The geom object class for Joint objects. The geometry draws a wire frame sphere at the joint position and connections to all children joints (visualizing the bones). """ def __init__(self, joint, radius=0.05): """Constructor. \param joint (\c Joint) The joint that uses this geom \param radius (\c float) Radius of the wire sphere at the joint position """ GeomObject.__init__(self) self.joint = joint self.radius = radius self.spheregeom = SphereGeom(radius=self.radius, segmentsu=8, segmentsv=4) def uniformCount(self): return 0 def varyingCount(self): return 0 def vertexCount(self): return 0 def boundingBox(self): r = vec3(self.radius, self.radius, self.radius) return BoundingBox(-r, r) def drawGL(self): # Draw sphere glPushAttrib(GL_LIGHTING_BIT | GL_CURRENT_BIT | GL_POLYGON_BIT) glDisable(GL_LIGHTING) glPushMatrix() # The joint is located at the pivot point p = self.joint.getOffsetTransform()[3] pivot = vec3(p.x, p.y, p.z) glTranslate(pivot.x, pivot.y, pivot.z) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) self.spheregeom.drawGL() # Draw bone glBegin(GL_LINES) for child in self.joint.iterChilds(): if not isinstance(child, Joint): continue p = child.pos-pivot try: b1 = p.ortho().normalize() b2 = p.cross(b1).normalize() except: continue b1 *= 0.75*self.radius b2 *= 0.75*self.radius glVertex3d(b1.x, b1.y, b1.z) glVertex3d(p.x, p.y, p.z) glVertex3d(-b1.x, -b1.y, -b1.z) glVertex3d(p.x, p.y, p.z) glVertex3d(b2.x, b2.y, b2.z) glVertex3d(p.x, p.y, p.z) glVertex3d(-b2.x, -b2.y, -b2.z) glVertex3d(p.x, p.y, p.z) glEnd() # Pivot coordinate system... P = self.joint.getOffsetTransform() r = 1.5*self.radius glBegin(GL_LINES) # X axis b = r*P[0] glColor3f(1,0,0) glVertex3f(0,0,0) glVertex3f(b.x,b.y,b.z) # Y axis b = r*P[1] glColor3f(0,1,0) glVertex3f(0,0,0) glVertex3f(b.x,b.y,b.z) # Z axis b = r*P[2] glColor3f(0,0,1) glVertex3f(0,0,0) glVertex3f(b.x,b.y,b.z) glEnd() glPopMatrix() glPopAttrib()
class JointGeom(GeomObject): """The geom object class for Joint objects. The geometry draws a wire frame sphere at the joint position and connections to all children joints (visualizing the bones). """ def __init__(self, joint, radius=0.05): """Constructor. \param joint (\c Joint) The joint that uses this geom \param radius (\c float) Radius of the wire sphere at the joint position """ GeomObject.__init__(self) self.joint = joint self.radius = radius self.spheregeom = SphereGeom(radius=self.radius, segmentsu=8, segmentsv=4) def uniformCount(self): return 0 def varyingCount(self): return 0 def vertexCount(self): return 0 def boundingBox(self): r = vec3(self.radius, self.radius, self.radius) return BoundingBox(-r, r) def drawGL(self): # Draw sphere glPushAttrib(GL_LIGHTING_BIT | GL_CURRENT_BIT | GL_POLYGON_BIT) glDisable(GL_LIGHTING) glPushMatrix() # The joint is located at the pivot point p = self.joint.getOffsetTransform()[3] pivot = vec3(p.x, p.y, p.z) glTranslate(pivot.x, pivot.y, pivot.z) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) self.spheregeom.drawGL() # Draw bone glBegin(GL_LINES) for child in self.joint.iterChilds(): if not isinstance(child, Joint): continue p = child.pos - pivot try: b1 = p.ortho().normalize() b2 = p.cross(b1).normalize() except: continue b1 *= 0.75 * self.radius b2 *= 0.75 * self.radius glVertex3d(b1.x, b1.y, b1.z) glVertex3d(p.x, p.y, p.z) glVertex3d(-b1.x, -b1.y, -b1.z) glVertex3d(p.x, p.y, p.z) glVertex3d(b2.x, b2.y, b2.z) glVertex3d(p.x, p.y, p.z) glVertex3d(-b2.x, -b2.y, -b2.z) glVertex3d(p.x, p.y, p.z) glEnd() # Pivot coordinate system... P = self.joint.getOffsetTransform() r = 1.5 * self.radius glBegin(GL_LINES) # X axis b = r * P[0] glColor3f(1, 0, 0) glVertex3f(0, 0, 0) glVertex3f(b.x, b.y, b.z) # Y axis b = r * P[1] glColor3f(0, 1, 0) glVertex3f(0, 0, 0) glVertex3f(b.x, b.y, b.z) # Z axis b = r * P[2] glColor3f(0, 0, 1) glVertex3f(0, 0, 0) glVertex3f(b.x, b.y, b.z) glEnd() glPopMatrix() glPopAttrib()