Example #1
0
  def __mul__(self,mult) :
    ''' Multiply sign wrapper. '''
    
    if isinstance(mult,Vertex) :
      # The right operator is an vertex.
      
      res_x= mult.wx * self.main_matrix[0] + mult.wy * self.main_matrix[4] + mult.wz * self.main_matrix[8]  + self.main_matrix[12]
      res_y= mult.wx * self.main_matrix[1] + mult.wy * self.main_matrix[5] + mult.wz * self.main_matrix[9]  + self.main_matrix[13]
      res_z= mult.wx * self.main_matrix[2] + mult.wy * self.main_matrix[6] + mult.wz * self.main_matrix[10] + self.main_matrix[14]
      
      return Vertex(res_x,res_y,res_z)   

    elif isinstance(mult,Vector) :
      # The right operator is an vector.
      
      x= mult.x*self.main_matrix[0] + mult.y*self.main_matrix[4] + mult.z*self.main_matrix[8]
      y= mult.x*self.main_matrix[1] + mult.y*self.main_matrix[5] + mult.z*self.main_matrix[9]
      z= mult.x*self.main_matrix[2] + mult.y*self.main_matrix[6] + mult.z*self.main_matrix[10]
      
      return Vector(x,y,z)    
    
    else :
      # The right operator is suppose to be an Localview otherwise.
      try :
        mult.pos=self.mult_vertex(mult.pos)      # Localview position multiplying.
        mult.right=self.mult_vector(mult.right)  # Localview X axe vector multiplying.
        mult.up=self.mult_vector(mult.up)        # Localview Y axe vector multiplying.
        mult.sight=self.mult_vector(mult.sight)  # Localview Z axe vector multiplying.
        return mult
      except :
	return None
Example #2
0
 def mult_vector(self,vector) :
   ''' Multiply the current main matrix with the given vector. 
       And return the result as an Vector.
   '''
   
   if not isinstance(vector,Vector) :
     raise TypeError(Vector)
   
   x= vector.x * self.main_matrix[0] + vector.y * self.main_matrix[4] + vector.z * self.main_matrix[8]
   y= vector.x * self.main_matrix[1] + vector.y * self.main_matrix[5] + vector.z * self.main_matrix[9]
   z= vector.x * self.main_matrix[2] + vector.y * self.main_matrix[6] + vector.z * self.main_matrix[10]
   
   return Vector(x,y,z)
Example #3
0
 def __init__(self,x=0.0,y=0.0,z=0.0) :
   ''' Create an localview object with:
       -) an position represented by an Vertex.
       -) 3 free axes initialise as the X, Y, Z axes.
   '''
   
   self.pos=Vertex(x,y,z)       # Position from the localview. 
   self.right=Vector(1.,0.,0.)  # Axe X representing vector.
   self.up=Vector(0.,1.,0.)     # Axe Y representing vector.
   self.sight=Vector(0.,0.,1.)  # Axe Z representing vector.
Example #4
0
class Localview(object) :
  
  def __init__(self,x=0.0,y=0.0,z=0.0) :
    ''' Create an localview object with:
        -) an position represented by an Vertex.
        -) 3 free axes initialise as the X, Y, Z axes.
    '''
    
    self.pos=Vertex(x,y,z)       # Position from the localview. 
    self.right=Vector(1.,0.,0.)  # Axe X representing vector.
    self.up=Vector(0.,1.,0.)     # Axe Y representing vector.
    self.sight=Vector(0.,0.,1.)  # Axe Z representing vector.
    
  def mult_matrix(self,matrix,localview) :
    ''' Multiply the localview with an matrix, given as argument,
        which settings change the localview.
    '''    
    
    if not isinstance(matrix,Matrix) :
      raise TypeError(Matrix)
    
    if not isinstance(localview,Localview) :
      raise TypeError(Localview)
    
    localview.pos=matrix.mult_vertex(localview.pos)      # Multiply the matrix with the position Vertex.
    localview.up=matrix.mult_vector(localview.up)        # Multiply the matrix with the X axe representing vector.
    localview.right=matrix.mult_vector(localview.right)  # Multiply the matrix with the Y axe representing vector.
    localview.sight=matrix.mult_vector(localview.sight)  # Multiply the matrix with the Z axe representing vector.
    
    return localview
  
  def __mul__(self,matrix) :
    ''' Localview and Localview multiplication sign '*' wrapper. 
        Multiplying the current localview with the right operator Matrix object.
    ''' 
    
    if not isinstance(matrix,Matrix) :
      raise TypeError(Matrix)
    
    self.pos=matrix.mult_vertex(self.pos)      # Multiply the matrix with the position Vertex.
    self.up=matrix.mult_vector(self.up)        # Multiply the matrix with the X axe representing vector.
    self.right=matrix.mult_vector(self.right)  # Multiply the matrix with the Y axe representing vector.
    self.sight=matrix.mult_vector(self.sight)  # Multiply the matrix with the Z axe representing vector.
    
    return self
  
  def display(self,factor) :
    ''' Function to display the localview axes. '''
    
    right_arrow = self.right.add_vertex(self.pos,self.right.mult_vector(factor,self.right))
    up_arrow = self.up.add_vertex(self.pos,self.up.mult_vector(factor,self.up))
    sight_arrow = self.sight.add_vertex(self.pos,self.sight.mult_vector(factor,self.sight))
    
    glLineWidth(4)
    
    glColor(255,0,0)
    glBegin(GL_LINES)
    glVertex(self.pos.get_vertex())
    glVertex(right_arrow.get_vertex())
    glEnd()
    
    glColor(0,255,0)
    glBegin(GL_LINES)
    glVertex(self.pos.get_vertex())
    glVertex(up_arrow.get_vertex())
    glEnd()
    
    glColor(0,0,255)
    glBegin(GL_LINES)
    glVertex(self.pos.get_vertex())
    glVertex(sight_arrow.get_vertex())
    glEnd()
    
  def __doc__(self) :
    ''' print documentation '''
    print '''
    Localview management class implementing an
    <type 'Localview'> datatype.
    
    An localview is an object representing either an 
    -> Camera view.
    -> Local axes (X, Y, Z) of an 3D object.
    
    An locaview is made from:
    -> An localview position vertex, object from <type 'Vertex'>.
	which is the position from:
	-> The camera.
	-> The center from the 3D object.
	referenced as an attribute named: Localview.pos
	
      -> 3 axes, objects from <type 'Vector'>. Representing either:
	-> The camera orientation.
	-> The own axes from the 3D object.
	
    The Localview class implement:
      
    -) multiplication with an matrix methods:
      
    either as the method: 
    -> Localview.mult_matrix(matrix)
	  which take an matrix containing the changing to apply
	  to the localview.
    -> an multiply sign placeholder:
	  The matrix to multiply with must be at the right to
	  the localview:
	  
	    Localview * Matrix 
      
    -) An Locaview display method for debugging purpose.
          Which display the axes in their current orientation
	  from the center to the greater values from the axes.
	  At the current Localview position.
          '''      
              
Example #5
0
class Localview(object) :
  # This class is redefine here because we cannot import it because it cause import crossing errors:
  # The Localview class depends from the Matrix class and
  # The Matrix class depends from the Localview class !!!
  
  def __init__(self,x=0.0,y=0.0,z=0.0) :
    ''' Create an localview object with:
        -) an position represented by an Vertex.
        -) 3 free axes initialise as the X, Y, Z axes.
    '''
    
    self.pos=Vertex(x,y,z)       # Position from the localview. 
    self.right=Vector(1.,0.,0.)  # Axe X representing vector.
    self.up=Vector(0.,1.,0.)     # Axe Y representing vector.
    self.sight=Vector(0.,0.,1.)  # Axe Z representing vector.
    
  def mult_matrix(self,matrix,localview) :
    ''' Multiply the localview with an matrix, given as argument,
        which settings change the localview.
    '''    
    
    if not isinstance(matrix,Matrix) :
      raise TypeError(Matrix)
    
    if not isinstance(localview,Localview) :
      raise TypeError(Localview)
    
    localview.pos=matrix.mult_vertex(localview.pos)      # Multiply the matrix with the position Vertex.
    localview.up=matrix.mult_vector(localview.up)        # Multiply the matrix with the X axe representing vector.
    localview.right=matrix.mult_vector(localview.right)  # Multiply the matrix with the Y axe representing vector.
    localview.sight=matrix.mult_vector(localview.sight)  # Multiply the matrix with the Z axe representing vector.
    
    return localview
  
  def __mul__(self,matrix) :
    ''' Localview and Localview multiplication sign '*' wrapper. 
        Multiplying the current localview with the right operator Matrix object.
    ''' 
    
    if not isinstance(matrix,Matrix) :
      raise TypeError(Matrix)
    
    self.pos=matrix.mult_vertex(self.pos)      # Multiply the matrix with the position Vertex.
    self.up=matrix.mult_vector(self.up)        # Multiply the matrix with the X axe representing vector.
    self.right=matrix.mult_vector(self.right)  # Multiply the matrix with the Y axe representing vector.
    self.sight=matrix.mult_vector(self.sight)  # Multiply the matrix with the Z axe representing vector.
    
    return self
  
  def display(self,factor) :
    ''' Function to display the localview axes. '''
    
    right_arrow = self.right.add_vertex(self.pos,self.right.mult_vector(factor,self.right))
    up_arrow = self.up.add_vertex(self.pos,self.up.mult_vector(factor,self.up))
    sight_arrow = self.sight.add_vertex(self.pos,self.sight.mult_vector(factor,self.sight))
    
    glLineWidth(4)
    
    glColor(255,0,0)
    glBegin(GL_LINES)
    glVertex(self.pos.get_vertex())
    glVertex(right_arrow.get_vertex())
    glEnd()
    
    glColor(0,255,0)
    glBegin(GL_LINES)
    glVertex(self.pos.get_vertex())
    glVertex(up_arrow.get_vertex())
    glEnd()
    
    glColor(0,0,255)
    glBegin(GL_LINES)
    glVertex(self.pos.get_vertex())
    glVertex(sight_arrow.get_vertex())
    glEnd()