class ZONE: dims = Vector(0.54 * M, 0.48 * M) outlines = ( # F1, F4, F2, F5, F3, F6 *mirrors(Box(dims, Vector(-3.54 * M, 0.55 * M))), *mirrors(Box(dims, Vector(-2.14 * M, -0.59 * M))), *mirrors(Box(dims, Vector(0, 1.795 * M))) )
def __init__(self, init_x, init_y, init_z, init_roll, init_pitch, init_yaw,\ init_min_x, init_min_y, init_min_z, init_max_x, init_max_y, init_max_z,\ x=0., y=0., z=0., roll=0., pitch=0., yaw=0.,\ min_x=0., min_y=0., min_z=0., max_x=0., max_y=0., max_z=0.): '''The variables whose names start with the prefix 'init_' represent the pose and the bounding box of an object before an action execution; all the others represent the object's pose and bounding box after an execution. ''' self.init_position = Vector(init_x, init_y, init_z) self.init_rotation = Rotator(init_roll, init_pitch, init_yaw) self.init_bounding_box = Box(init_min_x, init_min_y, init_min_z, init_max_x, init_max_y, init_max_z) self.position = Vector(x, y, z) self.rotation = Rotator(roll, pitch, yaw) self.bounding_box = Box(min_x, min_y, min_z, max_x, max_y, max_z)
def __init__(self, sensors=None, human=False): super().__init__() self.update = self.update_no_track #self.move = self.move_cor self.start_time = time.time() self.human = human # physical car parameters self.width = 10 self.length = 30 self.hwbase = self.length / 2 self.htrack = self.width / 2 self.max_speed = 150 self.rot = 0 self.speed = 0 self.max_steering = PI / 4 self.steering = 0 # for collision detection and box drawings self.quad = Quad(box=Box(-self.width/2, self.length/2, self.width, self.length)) self.corner_distance = Line(self.position, self.quad.top_left).length self.corner_angle = Line(self.position, self.quad.top_right).angle _ = self.corners # to set corner attributes # track info self.track = None self.section = None self.section_idx = -1 self.collided = False self.laps = 0 if not sensors: self.sensors = SensorRig(self, (-PI/2, -3 * self.corner_angle, -self.corner_angle, 0, self.corner_angle, 3 * self.corner_angle, PI/2), (30, 50, 100, 175, 100, 50, 30)) elif sensors == 1: self.sensors = SensorRig(self, (0,), (175,)) else: n = sensors // 2 * 2 + 1 angles = tuple(-PI/2 + i*PI/(n-1) for i in range(n)) distances = (100,) * n self.sensors = SensorRig(self, angles, distances) # neural network if cmodule: self.driver = neural.CDriver(1+self.sensors.size) else: self.driver = neural.Driver(1+self.sensors.size) # graphics stuff self.construct() self.section_batch = pyglet.graphics.Batch() self.section_batch_idx = -1
def make_track_new(self): #points = [(0, 100), (20, 150), (50, 250), (100, 280), (150, 300)] points = [(0, 100), (20, 150), (50, 250), (100, 260), (160, 230), (180, 180), (180, 120), (200, 50), (200, 20), (100, -120), (20, -90), (0, -40)] prev_quad = Quad(box=Box(0, 50, self.width, 50)) #prev_quad = Quad(coords=((0,0),(0,self.width),(0,50),(self.width,50))) for point in points: prev_quad, new_quad = self.make_section_quad(point, prev_quad) self.add_section(quad=prev_quad) prev_quad = new_quad self.add_section(quad=prev_quad) quad = Quad(coords=(prev_quad.top_left, prev_quad.top_right, self.sections[0].quad.bottom_left, self.sections[0].quad.bottom_right)) self.add_section(quad) self.circular = True
class ROBOT: outline = Box(Vector(0.6 * M, 0.5 * M)) _armor_length = 0.14 * M armor_lines = [ LineSegment(*y_mirrors(Vector(outline.dims.x / 2, _armor_length / 2))), LineSegment(*x_mirrors(Vector(_armor_length / 2, outline.dims.y / 2))), LineSegment(*x_mirrors(Vector(_armor_length / 2, -outline.dims.y / 2))), LineSegment(*y_mirrors(Vector(-outline.dims.x / 2, _armor_length / 2))) ] armor_damages = [20, 40, 40, 60] _drive_radius = 0.3 * M _factor = 1 / (math.sqrt(2) * _drive_radius) drive_config = MotionConfig(3 * MS, 6 * MS2, 0.1 * MS2) rotation_config = MotionConfig(_factor * drive_config.top_speed, _factor * drive_config.top_accel, _factor * drive_config.friction_decel) gimbal_yaw_config = MotionConfig(300 * DS, 1000 * DS2, 10 * DS2) zero_tolerance = 0.001 rebound_coeff = 0.4 shot_cooldown = 0.1 * S
from smoke_solver import Smoke_Builder, FlowEmitter from smoke_animation import Smoke_Animation from colliders import RigidBodyCollier, Collider from geometry import Box, Ball res = (512, 512) ti.init(arch=ti.gpu, kernel_profiler=True) gui = ti.GUI("smoke animation", res=res) # build smoke solver smoke = \ Smoke_Builder(res) \ .add_flow_emitter([512//2 , 0] , 512//3 , 2000.0) \ .set_decay(0.995) \ .build() # .set_compute_buoyancy_force(tempreture_factor=600)\ ani = Smoke_Animation(smoke, res) ani.reset() # collider smoke.add_collider(RigidBodyCollier(Box([156, 156], [226, 276]))) smoke.add_collider(RigidBodyCollier(Ball([276, 226], 30))) while gui.running: ani.update() ani.display(gui) ti.kernel_profiler_print()
def __init__(self, PLY = None): if PLY == None: print "PLY nao fornecido" exit(0) self.box = Box() self.vertex = PLY.vertex self.faces = PLY.faces self.colors = [ (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()), (random.random(),random.random(),random.random()) ] self.isOpened = False self.isAnimated = False self.useTexture = False self.mapRotate = matrix.identity() self.textureMap = {} self.aux = 0 edges_per_face = [] points_per_face = [] points_per_face_orig = [] polygons = [] for face in self.faces: edges_per_face.append([]) points_per_face.append([]) points_per_face_orig.append([]) for i in xrange(len(face)): points_per_face[-1].append(copy.deepcopy(self.vertex[face[i]])) points_per_face_orig[-1].append(copy.deepcopy(self.vertex[face[i]])) if i != (len(face)-1): edges_per_face[-1].append((face[i],face[i+1])) else: edges_per_face[-1].append((face[i],face[0])) polygons.append(Polygon(points_per_face_orig[-1])) adjacences_list = [] edge_between_faces = {} for i in xrange(len(edges_per_face)): adjacences_list.append([]) for j in xrange(len(edges_per_face[i])): edge = edges_per_face[i][j] for k in xrange(len(edges_per_face)): if k != i: if (((edge[1],edge[0]) in edges_per_face[k])or((edge[0],edge[1]) in edges_per_face[k])) : adjacences_list[i].append(k) edge_between_faces[(i,k)] = edge edge_between_faces[(k,i)] = edge break if len(edges_per_face[i]) != len(adjacences_list[i]): print "Inconsistencia na contrucao do grafico" self.edges_per_face = edges_per_face self.points_per_face = points_per_face self.points_per_face_orig = points_per_face_orig self.adjacences_list = adjacences_list self.polygons = polygons self.edge_between_faces = edge_between_faces self.selected = [0 for elem in edges_per_face] self.face_selected = -1 return