def setFromDict(self, designObject, myShipDict): """setup this ship according to the design object and ship dictionary info given""" self.myDesign = designObject self.designID = designObject.id self.componentdata = designObject.componentdata self.weapondata = designObject.weapondata self.myShipHull = designObject.myShipHull designAttrDict = designObject.getMyInfoAsDict() self.currentISP = myShipDict['currentISP'] for position, dQuad in myShipDict['quads'].iteritems(): newQuad = quad.Quad(dQuad) newQuad.setMyParent(self) # weapons have to be created first for id, dWeap in dQuad['weapons'].iteritems(): newWeap = weapon.Weapon(dWeap) newWeap.setMyQuad(newQuad) for id, dComp in dQuad['components'].iteritems(): newComp = component.Component(dComp) newComp.setMyQuad(newQuad) newQuad.setMyStatus() self.quads[newQuad.position] = newQuad newQuad.resetDefences() newQuad.reloadAmmo() self.setMyStatus() self.name = designObject.name + '-' + self.id self.randomizeJunkTrail()
def __init__(self): glutInit(len(sys.argv), sys.argv) glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE) glutInitWindowSize(800, 600) glutCreateWindow('Dynamic FBM Warping') #glutFullScreen() glutDisplayFunc(self.draw) glutMotionFunc(self.mouse_drag) glutKeyboardFunc(self.keyboard) glutMouseFunc(self.mouse_press) glutReshapeFunc(self.reshape) glutIdleFunc(self.idle) print glGetString(GL_VERSION) glClearColor(0.0, 0.0, 0.0, 1.0) self.time = time.clock() self.aspect_ratio = 1.0 self.width = 800 self.height = 600 self.fps = 120 self.idle_tick = 1.0 / self.fps self.paused = False self.quad = quad.Quad() self.high_quality = True self.frames_drawn = 0 self.second_timer = 0 self.fullscreen = False self.scr_width = 800 self.scr_height = 600 self.current_shader_index = 3 self.shaders = [] self.offset = [0, 0] self.last_pos = [0, 0] self.mouse_pressed = False self.fragfiles = [ item for item in os.listdir("./shaders") if item.endswith("frag") ] for shaderfile in self.fragfiles: print "Loading shader:", shaderfile self.shaders.append( shader.Shader("./shaders/warping.vert", "./shaders/" + shaderfile))
def setMyDesign(self, designObject): """Copy the Ship Design Attributes, Quads to ship""" self.myDesign = designObject self.designID = designObject.id self.componentdata = designObject.componentdata self.weapondata = designObject.weapondata self.myShipHull = designObject.myShipHull designAttrDict = designObject.getMyInfoAsDict() self.currentISP = self.myShipHull.maxISP self.currentPower = designAttrDict['maxPower'] self.maxBattery = designAttrDict['maxBattery'] self.thrust = designAttrDict['thrust'] self.rotation = designAttrDict['rotation'] self.radar = designAttrDict['radar'] self.jamming = designAttrDict['jamming'] self.repair = designAttrDict['repair'] self.maxAssault = designAttrDict['maxAssault'] self.mass = self.myShipHull.mass for position, dQuad in designObject.quads.iteritems(): newQuad = quad.Quad(dQuad.getMyInfoAsDict()) newQuad.setMyParent(self) # weapons have to be created first for id, weap in dQuad.weapons.iteritems(): newWeap = weapon.Weapon(weap.getMyInfoAsDict()) newWeap.setMyQuad(newQuad) for id, comp in dQuad.components.iteritems(): newComp = component.Component(comp.getMyInfoAsDict()) newComp.setMyQuad(newQuad) newQuad.setMyStatus() self.quads[newQuad.position] = newQuad newQuad.resetDefences() newQuad.reloadAmmo() self.name = designObject.name + '-' + self.id self.setMyStrength() if 'AS' in self.myShipHull.abr: self.isAssault = 1 else: self.isAssault = 0
[8.360311073266353254e-01, 0.000000000000000000e+00], [9.061798459386638527e-01, -7.745966692414832933e-01], [9.061798459386638527e-01, 0.000000000000000000e+00], [9.061798459386638527e-01, 7.745966692414834043e-01], [9.681602395076263079e-01, 0.000000000000000000e+00]]) # initiate uqtk arrays for quad points and weights x = uqtkarray.dblArray2D() w = uqtkarray.dblArray1D() # create instance of quad class and output # points and weights print('Create an instance of Quad class') ndim = 2 level = 3 q = uqtkquad.Quad('LU','sparse',ndim,level,0,1) print('Now set and get the quadrature rule...') q.SetRule() q.GetRule(x,w) # print out x and w print('Displaying the quadrature points and weights:\n') x_np = uqtk2numpy(x) print(x_np) n = len(x) print('Number of quad points is ', n, '\n') # plot the quadrature points print('Plotting the points (get points in column major order as a flattened vector)') print('need to use reshape with fortran ordering') xpnts = zeros((n,ndim))
# loop over our contours for c in cnts: # approximate the contour peri = cv2.arcLength(c, True) area = cv2.contourArea(c) approx = cv2.approxPolyDP(c, 0.01 * peri, True) # found paper if len(approx) == 4 and peri > 1500 and area > 50000: counter += 1 gap_counter = 0 if counter >= counter_thresh: counter = 0 screenCnt = approx bg_thresh = np.zeros(thresh.shape, dtype=np.uint8) ppr_quad = quad.Quad(map(lambda x: x[0], screenCnt)) ref_white = get_white() cv2.fillConvexPoly(bg_thresh, ppr_quad.points, 255) cv2.polylines(bg_thresh, [ppr_quad.points], True, 0, 5) break # allow for brief losses in tracking the paper gap_counter += 1 if gap_counter >= gap_thresh: counter = 0 # if paper is detected if bg_thresh is not None: ppr_img = ppr_quad.transform(img) h, w = ppr_img.shape[:2] ppr_img_copy = ppr_img.copy()
[0., 0., 1.] ]) # Initial state r = np.array([0, 0, 0, 7.0]) # Position r_dot = np.array([0, 0, 0, 1.0]) # Velocity omega = (np.random.random(3) - 0.5) * 0.1 # Angular velocity q = np.array([1.0, 0.0, 0.0, 0.0]) # Attitude quaternion target_altitude = r[3] target_yaw = 0.0 target_q = np.array([1.0, 0.0, 0.0, 0.0]) pitching = 0 yawing = 0 ascending = 0 copter = quad.Quad(r, r_dot, omega, q, c, d, g, m, I) import pyglet from pyglet.gl import * from pyglet.window import key width = 800 height = 800 window = pyglet.window.Window(width, height) glClearColor(1, 1, 1, 1) # A glVertex transformed by the inertial-to-body-frame quaternion def glVertex3fq(x, y, z, q): v = quaternion.rotateVector(np.array([0, x, y, z]), q) glVertex3f(v[1], v[2], v[3])