def place(self, shape, start, direction, inv_modelview): """ Place a new node. Consume: shape the shape to add start, direction describes the Ray to move to inv_modelview is the inverse modelview matrix for the scene """ new_node = None if shape == 'sphere': new_node = Sphere() elif shape == 'cube': new_node = Cube() elif shape == 'cylinder': new_node = Cylinder() elif shape == 'figure': new_node = SnowFigure() self.add_node(new_node) if new_node.call_list != 5: #print(dir(new_node),new_node.call_list) # place the node at the cursor in camera-space translation = (start + direction * self.PLACE_DEPTH) # convert the translation to world-space pre_tran = numpy.array( [translation[0], translation[1], translation[2], 1]) translation = inv_modelview.dot(pre_tran) new_node.translate(translation[0], translation[1], translation[2]) if new_node.call_list == 5 and len(self.selected_node_list) > 2: #print(dir(new_node),new_node.call_list) # place the node at the cursor in camera-space translation = (start + direction * self.PLACE_DEPTH) # convert the translation to world-space pre_tran = numpy.array( [translation[0], translation[1], translation[2], 1]) translation = inv_modelview.dot(pre_tran) #print(self.selected_node_list[-1].translate) #print(self.selected_node_list[-2].translation_matrix) center_x = ( self.selected_node_list[-2].translation_matrix[0, 3] + self.selected_node_list[-1].translation_matrix[0, 3]) / 2 center_y = ( self.selected_node_list[-2].translation_matrix[1, 3] + self.selected_node_list[-1].translation_matrix[1, 3]) / 2 center_z = ( self.selected_node_list[-2].translation_matrix[2, 3] + self.selected_node_list[-1].translation_matrix[2, 3]) / 2 new_node.translate(center_x, center_y, center_z) direction_x = ( self.selected_node_list[-2].translation_matrix[0, 3] - self.selected_node_list[-1].translation_matrix[0, 3]) direction_y = ( self.selected_node_list[-2].translation_matrix[1, 3] - self.selected_node_list[-1].translation_matrix[1, 3]) direction_z = ( self.selected_node_list[-2].translation_matrix[2, 3] - self.selected_node_list[-1].translation_matrix[2, 3]) if math.fabs(direction_z) > 2: new_node.rotate( math.atan(direction_z / direction_y) + math.pi / 2, math.atan(direction_x / direction_z), 0, False) elif math.fabs(direction_y) > 2: new_node.rotate(90, 0, 0) new_node.rotate( math.atan(direction_y / direction_z) + math.pi / 2, math.atan(direction_x / direction_y), 0, False) elif math.fabs(direction_x) > 2: new_node.rotate(0, 90, 0) new_node.rotate( math.atan(direction_x / direction_z) + math.pi / 2, math.atan(direction_y / direction_x), 0, False) print( math.atan(direction_z / direction_y) * 180 / math.pi, math.atan(direction_x / direction_z) * 180 / math.pi) #print("1",math.atan(direction_z/direction_y)*(180/math.pi),math.atan(direction_x/direction_z)*(180/math.pi)) print("2", direction_z / direction_y, direction_x / direction_z) print("3", direction_z, direction_y, direction_x, direction_z)