示例#1
0
	def __init__(self, bidMapper, mid, first, count_inner_rings, count_spokes, bid, flip_face_def=False ):
		self.color				= bidMapper.getColor(bid)
		self.mid 				= mid
		self.first 				= first
		self.count_inner_rings 	= count_inner_rings
		self.count_spokes 		= count_spokes
		self.boundaryId 		= bid
		self.alpha				= math.radians( 360. / (self.count_spokes ) )
		self.alpha_half			= self.alpha / 2.0

		self.simplices				= []	
		self.outer_vertices_idx 	= []
		self.inner_vertices_idx 	= []
		self.vertices 				= PLCPointList( 3 )
		self.spokes					= []
		self.mid_idx 				= self.vertices.appendVert( self.mid, self.color )
		
		rot_mat = Matrix4.new_rotatez( self.alpha )
		
		L = Vector3(self.first.x, self.first.y, self.first.z)
		z_offset = Vector3(0, 0, self.first.z)
		for i in range( 0, self.count_spokes  ):
			if i != 0:
				L -= z_offset
				L = rot_mat * L
				L += z_offset
			L_idx = self.vertices.appendVert( L, self.color )
			self.outer_vertices_idx.append( L_idx )
			spoke_direction = self.mid - L 
			assert self.mid.z == L.z
			spoke_vertex_idx = []
			spoke_vertex_idx.append( L_idx )
			spoke_add  = spoke_direction / float( self.count_inner_rings )
			for i in range( 1, self.count_inner_rings ):
				p = L + ( i * spoke_add )
				spoke_vertex_idx.append( self.vertices.appendVert( p, self.color ) )
			self.inner_vertices_idx.append( spoke_vertex_idx[-1] )
			self.spokes.append( spoke_vertex_idx )

		for i in range( 0, self.count_spokes ):
			current_spoke = self.spokes[i-1]
			left_spoke = self.spokes[i-2]
			right_spoke = self.spokes[i]
			for j in range( 0, self.count_inner_rings - 1 ):
				#print 'current spoke j,j+1, left spoke j: %f - %f - %f '%(current_spoke[j], current_spoke[j+1], left_spoke[j])
				if flip_face_def:
					self.simplices.append( Simplex( current_spoke[j], current_spoke[j+1], left_spoke[j]  ) )
					self.simplices.append( Simplex( right_spoke[j+1], current_spoke[j+1], current_spoke[j] ) )
				else:
					self.simplices.append( Simplex( left_spoke[j], current_spoke[j+1], current_spoke[j] ) )
					self.simplices.append( Simplex( current_spoke[j], current_spoke[j+1], right_spoke[j+1] ) )

		for i in range( 0, len(self.inner_vertices_idx)  ):
			if flip_face_def:
				self.simplices.append( Simplex( self.inner_vertices_idx[i-1], self.inner_vertices_idx[i], self.mid_idx ) )
			else:
				self.simplices.append( Simplex( self.mid_idx, self.inner_vertices_idx[i],self.inner_vertices_idx[i-1] ) )

		#this is exposed to FullGrid
		self.vertex_idx = self.outer_vertices_idx
示例#2
0
def matToList(m):
	m = m.transposed()
	return [m.a,m.b,m.c,m.d, m.e,m.f,m.g,m.h,
		m.i,m.j,m.k,m.l, m.m,m.n,m.o,m.p]

translation = Vector3()

zstamp = time.time()

invrots = [Matrix4.new_identity(),
                  Matrix4.new_rotatex(pi/2),
                  Matrix4.new_rotatex(-pi/2),
                  Matrix4.new_rotatey(pi/2),
                  Matrix4.new_rotatey(-pi/2),
                  Matrix4.new_rotatez(pi/2),
                  Matrix4.new_rotatex(pi)]

def add_flat_tri(p, vertices, normals, indices):
        n = (p[1]-p[0]).cross(p[2]-p[0]).normalize()
        for i in range(3):
                vertices += array('f',[p[i].x, p[i].y, p[i].z])
                normals += array('f',[n.x, n.y, n.z])
        next = len(indices)
        indices += array('H',[next, next+1, next+2])

def create_invader_element():
        vVertices = array('f')
        vNormals = array('f')
        vIndices = array('H')
        r_xy = inv_z - inv_inset