Exemplo n.º 1
0
    def modifySingleVector(self, v=Vector([0,0,0], [0,0,0]), diff_x=0, diff_y=0, move_x=0, move_y=0, move_z=0, screen_vectors=[], scale = 1):
        #Scale vector if user scrolled mouse
        v.start_point[0] *= scale
        v.start_point[1] *= scale
        v.start_point[2] *= scale

        v.end_point[0] *= scale
        v.end_point[1] *= scale
        v.end_point[2] *= scale

        # Rotate Vector according to the current screen_x/y axis
        if diff_x != 0:
            v.rotateAroundAnotherVector(axis_vector=self.screen_y_vector, angle_of_rotation=diff_x)
        if diff_y != 0:
            v.rotateAroundAnotherVector(axis_vector=self.screen_x_vector, angle_of_rotation=diff_y)

        if v not in screen_vectors:
            #If objects are moving
            if move_x != 0:
                v.start_point += self.screen_x_vector.vector * move_x
                v.end_point += self.screen_x_vector.vector * move_x

            if move_y != 0:
                v.start_point += self.screen_y_vector.vector * move_y
                v.end_point += self.screen_y_vector.vector * move_y

            #Modify the 2d representation of the vector in a 3d space

            #Set start point and end point Vectors
            start_point_vector = Vector(end_point=v.start_point, temp_vector=True)
            end_point_vector = Vector(end_point=v.end_point, temp_vector=True)

            #Get 2d coordinates of the start and the end of the 2d vector on that plane
            v.screen_start_point = start_point_vector.get2dCoordinates(self.screen_x_vector, self.screen_y_vector)
            v.screen_end_point = end_point_vector.get2dCoordinates(self.screen_x_vector, self.screen_y_vector)

            scale_x = self.x_axis_scale
            scale_y = self.y_axis_scale
            root_point_x = self.root_point[0]
            root_point_y = self.root_point[1]
            x1 = -1 * v.screen_start_point [0]
            y1 = v.screen_start_point[1]
            x2 = -1 * v.screen_end_point[0]
            y2 = v.screen_end_point[1]
            self.app_canvas.coords(v.canvas_object,
                    #X1, Y1
                    root_point_x - x1 * scale_x, root_point_y - y1 * scale_y,

                    #X2, Y2
                    root_point_x - x2 * scale_x, root_point_y - y2 * scale_y
            )