Example #1
0
 def __init__(self, pos):
     pygame.sprite.Sprite.__init__(self)
     self.depth = 0
     self.prevpos = V.vector(pos)
     self.velocity = V.vector(0, 0)
     self.visible = True
     self.showheading = False
     self.showbox = False
Example #2
0
 def __init__(self, pos):
     pygame.sprite.Sprite.__init__(self)
     self.depth = 0
     self.prevpos = V.vector(pos)
     self.velocity = V.vector(0,0)
     self.visible = True
     self.showheading = False
     self.showbox = False
Example #3
0
    def update(self):

        self.prevpos = V.vector(self.rect.center).copy()

        self.state.execute(self)

        ## Add a tiny force toward the center of the field
        if False:  #self.state != S.Wait():
            center = V.vector(pygame.display.get_surface().get_rect().center)
            towardcenter = center - self.rect.center
            V.normalize_ip(towardcenter)
            self.steering += 0.5 * towardcenter

        self.velocity += FORCE_PER_TICK * self.steering / (self.mass)
        V.truncate(self.velocity, self.maxspeed)

        speed = V.length(self.velocity)
        if speed > 0.001:
            self.heading = V.normalize(self.velocity)
        self.rect.center += self.velocity
        self.depth = -self.rect.centery

        #determine which image direction to use, based on heading and velocity:
        if speed >= 0.001:
            small = 0.382  # sin(22.5 degrees)
            big = 0.923  # cos(22.5 degrees)
            x, y = self.heading
            if y >= big: self.dir = 's'
            elif small <= y:
                if x > 0: self.dir = 'se'
                else: self.dir = 'sw'
            elif -small <= y:
                if x > 0: self.dir = 'e'
                else: self.dir = 'w'
            elif -big <= y:
                if x > 0: self.dir = 'ne'
                else: self.dir = 'nw'
            else: self.dir = 'n'
        else:
            self.velocity[0] = self.velocity[1] = 0.0

    #image action:  stopped or moving?
        if speed < 0.001:
            self.aspeed = 0.5
            action = 'looking'
        else:
            self.aspeed = 0.2 * speed
            action = 'walking'

        self.images = Images.get(self.name)[self.dir][action]
        self.nframes = len(self.images)

        #advance animation frame
        self.frame = self.aspeed + self.frame
        while self.frame >= self.nframes:
            self.frame -= self.nframes
        self.image = self.images[int(self.frame)]
Example #4
0
    def update(self):

        self.prevpos = V.vector(self.rect.center).copy()

        self.state.execute(self)
        
        ## Add a tiny force toward the center of the field
        if False:#self.state != S.Wait():
            center = V.vector(pygame.display.get_surface().get_rect().center)
            towardcenter = center - self.rect.center
            V.normalize_ip(towardcenter)
            self.steering += 0.5*towardcenter      
        
        self.velocity += FORCE_PER_TICK*self.steering/(self.mass)
        V.truncate(self.velocity, self.maxspeed)

        speed = V.length(self.velocity)
        if speed > 0.001:
            self.heading = V.normalize(self.velocity)
        self.rect.center += self.velocity
        self.depth = -self.rect.centery
        
    #determine which image direction to use, based on heading and velocity:
        if speed >= 0.001:
            small = 0.382 # sin(22.5 degrees)
            big = 0.923  # cos(22.5 degrees)
            x,y = self.heading
            if y >= big: self.dir = 's'
            elif small <= y:
                if x > 0: self.dir = 'se'
                else: self.dir = 'sw'
            elif -small <= y:
                if x > 0: self.dir = 'e'
                else: self.dir = 'w'
            elif -big <= y:
                if x > 0: self.dir = 'ne'
                else: self.dir = 'nw'
            else: self.dir = 'n'
        else:
            self.velocity[0] = self.velocity[1] = 0.0
        
    #image action:  stopped or moving?
        if speed < 0.001: 
            self.aspeed = 0.5
            action = 'looking'
        else: 
            self.aspeed = 0.2*speed
            action = 'walking'
            
        self.images = Images.get(self.name)[self.dir][action]
        self.nframes = len(self.images)
        
    #advance animation frame
        self.frame = self.aspeed+self.frame
        while self.frame >= self.nframes: self.frame -= self.nframes
        self.image = self.images[int(self.frame)]
Example #5
0
 def test_get_prediction_vector(self):
     points = [(1,5),(3,0),(5,6)]
     v1 = vector(points[1],points[0])
     v2 = vector(points[1],points[2])
     angle = vectorAngle(v1,v2)
     c= Corner(points,1,imgtime=1)
     c1= Corner(points,1,imgtime=1)
     ans= c.get_prediction_vector(True, c1)
     self.assertAlmostEqual(ans[0],v1[0],6)
     self.assertAlmostEqual(ans[1],v1[1],6)
     ans= c.get_prediction_vector(False, c1)
     self.assertAlmostEqual(ans[0],v2[0],6)
     self.assertAlmostEqual(ans[1],v2[1],6)
Example #6
0
 def test_get_prediction_vector(self):
     points = [(1, 5), (3, 0), (5, 6)]
     v1 = vector(points[1], points[0])
     v2 = vector(points[1], points[2])
     angle = vectorAngle(v1, v2)
     c = Corner(points, 1, imgtime=1)
     c1 = Corner(points, 1, imgtime=1)
     ans = c.get_prediction_vector(True, c1)
     self.assertAlmostEqual(ans[0], v1[0], 6)
     self.assertAlmostEqual(ans[1], v1[1], 6)
     ans = c.get_prediction_vector(False, c1)
     self.assertAlmostEqual(ans[0], v2[0], 6)
     self.assertAlmostEqual(ans[1], v2[1], 6)
def pnt2line(pnt, start, end):
    line_vec = vec.vector(start, end)
    pnt_vec = vec.vector(start, pnt)
    line_len = vec.length(line_vec)
    line_unitvec = vec.unit(line_vec)
    pnt_vec_scaled = vec.scale(pnt_vec, 1.0 / line_len)
    t = vec.dot(line_unitvec, pnt_vec_scaled)
    if t < 0.0:
        t = 0.0
    elif t > 1.0:
        t = 1.0
    nearest = vec.scale(line_vec, t)
    dist = vec.distance(nearest, pnt_vec)
    nearest = vec.add(nearest, start)
    return (dist, nearest)
Example #8
0
def get(win, min_x, min_y, min_z, len,quantity,fname):
    # Ещё раз считываем obj файл, для записи точек(с нормалями), и разбиения на треугольники.
    if (min_x > 0):
        min_x = 0
    if (min_y > 0):
        min_y = 0
    if (min_z > 0):
        min_z = 0
    f = open(fname, 'r')
    new = QColor()
    lines = f.read()
    i = 0
    j = 0
    k = 0
    points = np.empty(shape = (len,), dtype = Point)
    triangl_normals = np.empty(shape = (len,), dtype= for_normals)
    for l in range(len):
        triangl_normals[l] = for_normals()
    world_coords = np.empty(shape = (3,), dtype= Point)
    communication = np.empty(shape = (quantity,), dtype = Point)
    normals = np.empty(shape = (len,), dtype = vector)
    for line in lines.split('\n'):

        try:
            v, x, y, z = re.split('\s+', line)

        except:
            try:
                v, x, y, z = re.split('\s+', line[:-1])
            except:
                continue

        if v == 'v':
            points[i] = Point(float(x) - min_x, float(y) - min_y, float(z) - min_z, None)

            i += 1
        if v == 'f':
            world_coords[0] = points[int(x.split('/')[0]) - 1]
            world_coords[1] = points[int(y.split('/')[0]) - 1]
            world_coords[2] = points[int(z.split('/')[0]) - 1]
            n = (world_coords[2] - world_coords[0]) ** (world_coords[1] - world_coords[0])
            n =  vector(n.x,n.y,n.z)
            q = n.normolize()
            triangl_normals[int(x.split('/')[0]) - 1].for_no.append(q)
            triangl_normals[int(y.split('/')[0]) - 1].for_no.append(q)
            triangl_normals[int(z.split('/')[0]) - 1].for_no.append(q)
            communication[j] = [points[int(i.split('/')[0])-1] for i in (x, y, z)]
            j += 1
    for i in range(len):
        points[i].norma = triangl_normals[i].get_medium()
    normolize_all(points)
    subject = Obj(points, communication)
    objects.add(subject)

    if win.flag == 0:
        show_all_models1(win)
    else:
        show_all_models2(win)
    f.close()
Example #9
0
def sphere_to_2D_plane(ref,w):
	xmult = orthonorm_tox(ref)
	xmult = v3.vector(xmult.x, xmult.y, xmult.z)
	ymult = orthonorm_toy(ref)
	ymult = v3.vector(ymult.x, ymult.y, ymult.z)
	zmult = orthonorm_toz(ref)
	zmmult = v3.vector(zmult.x, zmult.y, zmult.z)
	return v.vector(ymult.dot(w), -zmult.dot(w))
Example #10
0
def sphere_to_2D_plane(ref, w):
    xmult = orthonorm_tox(ref)
    xmult = v3.vector(xmult.x, xmult.y, xmult.z)
    ymult = orthonorm_toy(ref)
    ymult = v3.vector(ymult.x, ymult.y, ymult.z)
    zmult = orthonorm_toz(ref)
    zmmult = v3.vector(zmult.x, zmult.y, zmult.z)
    return v.vector(ymult.dot(w), -zmult.dot(w))
Example #11
0
 def set_new_position(self, points, offset=True,scale=1):
     res = Marker.set_new_position(self, points, offset,scale)
     le = len(points)
     if le<0 or type(points[0])<>tuple: return res
     for i, cor in enumerate(self.corners):
         cor.diag = v.vector(cor.p, points[(i + 2) % le])
         cor.set_colors(self.m_d.img)
     return res
Example #12
0
 def execute(self, obj):
     pos = V.vector(obj.rect.center)
     targpos = obj.target.rect.center
     traveltime = V.length(pos-targpos)/obj.maxspeed
     targvel = obj.target.velocity
     futurepos = targpos + targvel*traveltime
     desired_velocity = obj.maxspeed*V.normalize(futurepos - pos)
     obj.steering = desired_velocity - obj.velocity
     V.truncate(obj.steering, obj.maxforce)
Example #13
0
 def get_medium(self):
     sumx = 0
     sumy = 0
     sumz = 0
     for i in range(len(self.for_no)):
         sumx += self.for_no[i].x
         sumy += self.for_no[i].y
         sumz += self.for_no[i].z
     return vector(sumx/len(self.for_no),sumy/len(self.for_no),sumz/len(self.for_no))
Example #14
0
 def execute(self, obj):
     pos = V.vector(obj.rect.center)
     targpos = obj.target.rect.center
     traveltime = V.length(pos - targpos) / obj.maxspeed
     targvel = obj.target.velocity
     futurepos = targpos + targvel * traveltime
     desired_velocity = obj.maxspeed * V.normalize(pos - futurepos)
     obj.steering = desired_velocity - obj.velocity
     V.truncate(obj.steering, obj.maxforce)
Example #15
0
 def get_border_points(self,rect):
     black=[]
     white=[]
     vec1=v.vector(rect[0], rect[2])
     vec2=v.vector(rect[1], rect[3])
     real_p=[]
     f=2.0/32
     img=self.m_d.gray_img
     def get_points(p1,p2,f1,f2,points):
         a,b=self.get_line(v.add(p1, vec1, f1), v.add(p2,vec2,f2), img)
         points.extend(a)
         real_p.extend(b)
     def get_points_color(f,points):
         get_points(rect[0],rect[1],-f,-f,points)
         get_points(rect[2],rect[1],f,-f,points)
         get_points(rect[0],rect[3],-f,f,points)
         get_points(rect[2],rect[3],f,f,points)
     get_points_color(f,black)
     get_points_color(-f,white)
     return black,white,real_p
Example #16
0
	def get_velocity_vectors(self):
		own_v = []
		intr_v = [[] for x in range(len(self.names)-1)]
		self.velocity = [[] for x in range(len(self.names)-1)]

		if self.spherical_velocity:
			for y in range(len(self.data)):
				test = v.vector(float(self.data[y][self.vx_place]), float(self.data[y][self.vy_place]))

				if self.data[y][0] == self.names[0]:
					own_v.append(test)
				else:
					for x in range(0, len(self.names)):
						if self.data[y][0] == self.names[x]:
							intr_v[x-1].append(test)



		else:
			for y in range (len(self.data)):
				temp_angle = float(self.data[y][self.trk_place])
				temp_gs = float(self.data[y][self.gs_place])

				if self.units_list[0][self.trk_place] == "deg":
					temp_angle = math.radians(temp_angle)

				test = v.vector(math.sin(temp_angle)*temp_gs, math.cos(temp_angle)*temp_gs)
		
				if self.data[y][0] == self.names[0]:
					own_v.append(test)
				else:
					for x in range(0, len(self.names)):
						if self.data[y][0] == self.names[x]:
							intr_v[x-1].append(test)

		for x in range(len(intr_v)):
			for y in range(0, len(intr_v[x])):
				temp = own_v[y] - intr_v[x][y]
				self.velocity[x].append(temp)
Example #17
0
    def __init__(self, name, pos, maxspeed=PLAYER_MAXSPEED, screen=None):
        AutoObject.__init__(self, pos)

        # Image and rect vars
        self.name = name
        self.images = Images.get(self.name)['e']['looking']
        self.imagesize = self.images[0].get_size()
        w, h = self.imagesize
        self.rect = pygame.Rect(0, 0, Player.wfrac * w, Player.hfrac * h)
        self.rect.center = V.vector(pos)

        # Physics vars
        self.obstacles = []
        self.state = S.Wait()

        self.maxspeed = maxspeed
        self.maxforce = maxspeed * 0.1

        self.velocity = V.vector(0, 0)
        self.steering = V.vector(0, 0)
        randang = random.uniform(0, 2 * math.pi)
        x, y = math.cos(randang), math.sin(randang)
        self.heading = V.vector(x, y)
        self.dir = 's'

        # Animation vars
        self.depth = 0
        self.nframes = len(self.images)
        self.frame = random.randint(0, self.nframes - 1)
        self.mass = 1.0

        # Vars that should be in the state (IMHO):
        wanderangle = random.uniform(0, 2 * math.pi)
        self.wanderpoint = V.vector(math.cos(wanderangle),
                                    math.sin(wanderangle))
        V.normalize_ip(self.wanderpoint)

        self.seektarget = None
        self.seektarget2 = None
Example #18
0
    def __init__(self, name, pos, maxspeed=PLAYER_MAXSPEED, screen=None):
        AutoObject.__init__(self, pos)

        # Image and rect vars
        self.name = name
        self.images = Images.get(self.name)['e']['looking']
        self.imagesize = self.images[0].get_size()
        w,h = self.imagesize
        self.rect = pygame.Rect(0, 0, Player.wfrac*w, Player.hfrac*h)
        self.rect.center = V.vector(pos)

        # Physics vars
        self.obstacles = []
        self.state = S.Wait()
        
        self.maxspeed = maxspeed
        self.maxforce = maxspeed*0.1

        self.velocity = V.vector(0,0)
        self.steering = V.vector(0,0)
        randang = random.uniform(0, 2*math.pi)
        x,y = math.cos(randang), math.sin(randang)
        self.heading = V.vector(x,y)
        self.dir = 's'

        # Animation vars
        self.depth = 0
        self.nframes = len(self.images)
        self.frame = random.randint(0,self.nframes-1)
        self.mass = 1.0

        # Vars that should be in the state (IMHO):
        wanderangle = random.uniform(0, 2*math.pi)
        self.wanderpoint = V.vector(math.cos(wanderangle), math.sin(wanderangle))
        V.normalize_ip(self.wanderpoint)

        self.seektarget = None
        self.seektarget2 = None
Example #19
0
	def get_position_vectors(self):
		pso = []
		psi = [[] for x in range(len(self.names)-1)]
		si = [[] for x in range(len(self.names)-1)]
		self.position = [[] for x in range(len(self.names)-1)]
		origin = v.vector(0.0, 0.0)

		for y in range (0, len(self.data)):
			a = float(self.data[y][1])
			b = float(self.data[y][2])
			if not self.spherical:
				test = v.vector(a,b)
			else:
				a = math.radians(a)
				b = math.radians(b)
				test = ENU.spherical2xyz(a,b)
			# the next two loops put the temp vector in the appropriate slot
			if self.data[y][0] == self.names[0]:
				pso.append(test)
			else:
				for x in range(0, len(self.names)):
					if self.data[y][0] == self.names[x]:
						psi[x-1].append(test)
		
		# calculation using sphere_to_2D_plane 
		# if self.spherical:
		for x in range(0, len(psi)):
			for y in range(0, len(psi[x])):
				temp = ENU.sphere_to_2D_plane(pso[y], psi[x][y])
				si[x].append(temp)

		# calculate relative position 
		for x in range(0, len(psi)):
			for y in range(0, len(psi[x])):
				temp = origin - si[x][y]
				self.position[x].append(temp)
Example #20
0
def show_all_models1(win):
    # Отображение объектов с тонировкой
    win.Delete_all()
    qwe = 0
    new = QColor()
    # Инициализация z-буфера.
    zbufer = np.full(width * (height+1),-10000)
    # Инициализация  луча света(возможно заменю на vector )
    light_dir = vector(0, 0, -1)
    for k in objects.objects:
        # перебор всех объектов
        start_time = time.clock()
        for i in k.tri:
            qwe = triangle(i, win, zbufer,qwe,light_dir)
        print("{:g} s".format(time.clock() - start_time))

    win.update()
Example #21
0
	def get_gs(self):
		self.gs = [[] for x in range(len(self.names))]

		if self.spherical_velocity:
			for x in range(len(self.data)):
				temp_vector = v.vector(self.data[x][self.vx_place], self.data[x][self.vy_place])
				temp = temp_vector.norm(temp_vector)

				for y in range(len(self.names)):
					if self.data[x][0] == self.names[y]:
						self.gs[y].append(temp)

		else:
			for x in range(len(self.data)):
				temp = float(self.data[x][self.gs_place])

				for y in range(0, len(self.names)):
					if self.data[x][0] == self.names[y]:
						self.gs[y].append(temp)
Example #22
0
 def get_turn_down(self, win):
     for j in self.points:
             y = j.y
             y = y - 325 / half_scr_y
             matr = np.matrix([[1, 0, 0, 0], \
                               [0, m.cos(-m.pi / 30), m.sin(-m.pi / 30), 0], \
                               [0, -m.sin(-m.pi / 30), m.cos(-m.pi / 30), 0], \
                               [0, 0, 0, 1]])
             matr = np.linalg.inv(matr)
             vector_turn = np.matrix([j.norma.x, j.norma.y, j.norma.z,0])
             vector_turn = vector_turn.dot(matr)
             new_v = vector(vector_turn[0, 0], vector_turn[0, 1], vector_turn[0, 2])
             new = Point(j.x, (y * m.cos(-m.pi / 30) + j.z * m.sin(-m.pi / 30))+325 / half_scr_y,-y * (m.sin(-m.pi / 30)) + j.z * m.cos(-m.pi / 30),new_v)
             j.y = new.y
             j.z = new.z
             j.norma = new.norma
     if win.flag == 0:
         show_all_models1(win)
     else:
         show_all_models2(win)
Example #23
0
    def get_line(self,p1,p2,img):
        a,b = v.vector(p1, p2)
        if a>b:l=a
        else:l=b
        if l==0: return [],[]
        li=cv.InitLineIterator(img, p1, p2,8)
        points=[]
        for i,c in enumerate(li):
            points.append(c)
        l=len(points)
        if len(points)==0:
            return [],[]
        vec=(a/float(l),b/float(l))
        real_p=[]
        for i in range(l):
#            list.append(c)
#        for i in range(l):
            p=v.int_point(v.add(p1,vec,i))
            real_p.append(p)
#            points.append(img[p[1],p[0]]);
        return points,real_p
Example #24
0
    def turn_left_point(self, win):
        # Поворот вокруг оси оy вправо
        for j in self.points:
            x = j.x
            x = x - 325 / half_scr_y

            matr = np.matrix([[m.cos(-m.pi / 30), 0, m.sin(-m.pi / 30),0 ], \
                              [0,1 , 0, 0], \
                              [-m.sin(-m.pi / 30), 0, m.cos(-m.pi / 30),0],\
                              [0,0,0,1]])
            matr = np.linalg.inv(matr)
            vector_turn = np.matrix([j.norma.x,j.norma.y,j.norma.z,0])
            vector_turn = vector_turn.dot(matr)
            new_v = vector(vector_turn[0,0],vector_turn[0,1],vector_turn[0,2])
            new = Point(x*m.cos(-m.pi/30)+j.z*m.sin(-m.pi/30)+ 325 / half_scr_y,j.y,-x*m.sin(-m.pi/30) + j.z*m.cos(-m.pi/30),new_v)
            j.x = new.x
            j.z = new.z
            j.norma = new.norma
        if win.flag == 0:
            show_all_models1(win)
        else:
            show_all_models2(win)
Example #25
0
    def turn_z_left_point(self,win):
        for j in self.points:
            x = j.x
            x = x - 325 / half_scr_y
            y = j.y
            y = y - 325 / half_scr_y

            matr = np.matrix([[m.cos(m.pi / 30), -m.sin(m.pi / 30), 0 , 0], \
                              [m.sin(m.pi / 30), m.cos(m.pi / 30), 0, 0], \
                              [0, 0, 1,0],\
                              [0, 0, 0, 1]])
            matr = np.linalg.inv(matr)
            vector_turn = np.matrix([j.norma.x,j.norma.y,j.norma.z,0])
            vector_turn = vector_turn.dot(matr)
            new_v = vector(vector_turn[0,0],vector_turn[0,1],vector_turn[0,2])
            new = Point(x*m.cos(m.pi/30)-y*m.sin(m.pi/30),x*m.sin(m.pi/30) + y*m.cos(m.pi/30),j.z,new_v)
            j.x = new.x + 325 / half_scr_y
            j.y = new.y +325 / half_scr_y
            j.norma = new.norma
        if win.flag == 0:
            show_all_models1(win)
        else:
            show_all_models2(win)
Example #26
0
import vectors as V

ZERO_VECTOR = V.vector((0,0))
PLAYER_MAXSPEED = 5
FORCE_PER_TICK = 0.125
WANDER_RADIUS = 80
WANDER_OFFSET = 100
Example #27
0
def random_pos():
    return V.vector(random.randint(100,world_size[0]-100),
                    random.randint(100,world_size[1]-100))
Example #28
0
 def execute(self, obj):
     pos = V.vector(obj.rect.center)
     endpos = obj.target.rect.center
     desired_velocity = obj.maxspeed*V.normalize(pos - endpos)
     obj.steering = desired_velocity - obj.velocity
     V.truncate(obj.steering, obj.maxforce)
Example #29
0
 def add_line(a,b,c,d,factor):
     p1=v.add(r[a],v.vector(r[a],r[b]),factor)
     p2=v.add(r[c],v.vector(r[c],r[d]),factor)
     lines.append(((p1,p2),(a,c)))
Example #30
0
def main():
    ip= CamImageProvider(0, "../resources/testdata.avi")
    #ip = MovieImageProvider("../resources/testdata.avi",0,0)
    sq = Square(0)
    img,imgtime = ip.getImage(1)
    m_d = SquareDetector(img, imgtime, 2, 0)
    m_d.add_marker(sq)
    angle_min = math.pi
    angle_max = 0
    angle_diff_min = 100
    angle_diff_max = 0
    prop_min  = 40
    prop_max = 0
    rot_max = 0
    debug.start_at(ip, 0)
    while cv.WaitKey(1)<>27:
        img,imgtime = ip.getImage(1)
        if img is None:
            return
#        tmpimg = cv.CloneImage(draw_img)
#        tmpimg2 = cv.CloneImage(draw_img)
#        gray2 = cv.CloneImage(gray)
#        gray3 = cv.CloneImage(gray)
#        tmp = cv.CloneImage(gray)
#        mask = cv.CloneImage(gray)
#        mask2=cv.CloneImage(gray)
#        cv.Set(mask2,1)
#        cv.CvtColor(draw_img, gray, cv.CV_BGR2GRAY)
#        cv.CvtColor(draw_img, tmpimg, cv.CV_BGR2HSV)
#        cv.SetImageCOI(tmpimg, 1)
#        cv.Copy(tmpimg, gray)
#        print cv.MinMaxLoc(gray)
#        cv.ShowImage("gray", gray)
        if debug.is_time():
            pass
        m_d.find_markers(img,imgtime,True)
        mar = m_d.markers[0]
        points = mar.points
        m_d.draw_markers(m_d.draw_img)
        debug.show([m_d.draw_img],"main",1,1)
        #debug.show_images()
        if len(points)<>4 or cv.WaitKey(50)<>32: 
            continue
        a = length(vector(points[0],points[1]))
        b = length(vector(points[1],points[2]))
        c = length(vector(points[2],points[3]))
        d = length(vector(points[3],points[0]))
        if a>c:
            a,c = c,a
        if b>d:
            b,d = d,b
        if c == 0.0:
            print mar
        else:
            print "sides a/c:", a/c
            if a/c > prop_max: prop_max = a/c
            if a/c < prop_min: prop_min = a/c
        if d==0.0:
            print mar
        else:
            print "sides b/d", b/d
            if b/d > prop_max: prop_max = b/d
            if b/d < prop_min: prop_min = b/d
        for cor in mar.corners:
            if cor.angle < angle_min:angle_min = cor.angle
            if cor.angle > angle_max:angle_max = cor.angle
            if cor.rotation > rot_max: rot_max = cor.rotation
        a,b,c,d = [c.angle for c in mar.corners]
        if a>c:
            a,c=c,a
        if b>d:
            b,d=d,b
        if a/c > angle_diff_max: angle_diff_max=a/c
        if a/c< angle_diff_min: angle_diff_min = a/c
        print "angle diff a/c", a/c
        if b/d > angle_diff_max: angle_diff_max=b/d
        if b/d< angle_diff_min: angle_diff_min = b/d
        print "angle diff b/d", b/d
                
    print "angle_min", angle_min
    print "angle_max", angle_max
    print "prop_min", prop_min
    print "prop_max", prop_max
    print "rot_max",rot_max
    print "angle_diff_min", angle_diff_min
    print "angle_diff_max",angle_diff_max
Example #31
0
def random_pos():
    return V.vector(random.randint(50,screen_size[0]-50),
                    random.randint(50,screen_size[1]-50))
Example #32
0
def random_pos():
    return V.vector(random.randint(50, screen_size[0] - 50),
                    random.randint(50, screen_size[1] - 50))
Example #33
0
def random_pos():
    return V.vector(random.randint(100, world_size[0] - 100),
                    random.randint(100, world_size[1] - 100))
Example #34
0
 def vect2(self):
     return v.vector(self.x, self.y)
Example #35
0
 def execute(self, obj):
     pos = V.vector(obj.rect.center)
     endpos = obj.target.rect.center
     desired_velocity = obj.maxspeed * V.normalize(endpos - pos)
     obj.steering = desired_velocity - obj.velocity
     V.truncate(obj.steering, obj.maxforce)
Example #36
0
import vectors as V

ZERO_VECTOR = V.vector((0, 0))
PLAYER_MAXSPEED = 5
FORCE_PER_TICK = 0.125
WANDER_RADIUS = 80
WANDER_OFFSET = 100
Example #37
0
	def vect2(self):
		return v.vector(self.x, self.y)
Example #38
0
def main():
    ip = CamImageProvider(0, "../resources/testdata.avi")
    #ip = MovieImageProvider("../resources/testdata.avi",0,0)
    sq = Square(0)
    img, imgtime = ip.getImage(1)
    m_d = SquareDetector(img, imgtime, 2, 0)
    m_d.add_marker(sq)
    angle_min = math.pi
    angle_max = 0
    angle_diff_min = 100
    angle_diff_max = 0
    prop_min = 40
    prop_max = 0
    rot_max = 0
    debug.start_at(ip, 0)
    while cv.WaitKey(1) <> 27:
        img, imgtime = ip.getImage(1)
        if img is None:
            return


#        tmpimg = cv.CloneImage(draw_img)
#        tmpimg2 = cv.CloneImage(draw_img)
#        gray2 = cv.CloneImage(gray)
#        gray3 = cv.CloneImage(gray)
#        tmp = cv.CloneImage(gray)
#        mask = cv.CloneImage(gray)
#        mask2=cv.CloneImage(gray)
#        cv.Set(mask2,1)
#        cv.CvtColor(draw_img, gray, cv.CV_BGR2GRAY)
#        cv.CvtColor(draw_img, tmpimg, cv.CV_BGR2HSV)
#        cv.SetImageCOI(tmpimg, 1)
#        cv.Copy(tmpimg, gray)
#        print cv.MinMaxLoc(gray)
#        cv.ShowImage("gray", gray)
        if debug.is_time():
            pass
        m_d.find_markers(img, imgtime, True)
        mar = m_d.markers[0]
        points = mar.points
        m_d.draw_markers(m_d.draw_img)
        debug.show([m_d.draw_img], "main", 1, 1)
        #debug.show_images()
        if len(points) <> 4 or cv.WaitKey(50) <> 32:
            continue
        a = length(vector(points[0], points[1]))
        b = length(vector(points[1], points[2]))
        c = length(vector(points[2], points[3]))
        d = length(vector(points[3], points[0]))
        if a > c:
            a, c = c, a
        if b > d:
            b, d = d, b
        if c == 0.0:
            print mar
        else:
            print "sides a/c:", a / c
            if a / c > prop_max: prop_max = a / c
            if a / c < prop_min: prop_min = a / c
        if d == 0.0:
            print mar
        else:
            print "sides b/d", b / d
            if b / d > prop_max: prop_max = b / d
            if b / d < prop_min: prop_min = b / d
        for cor in mar.corners:
            if cor.angle < angle_min: angle_min = cor.angle
            if cor.angle > angle_max: angle_max = cor.angle
            if cor.rotation > rot_max: rot_max = cor.rotation
        a, b, c, d = [c.angle for c in mar.corners]
        if a > c:
            a, c = c, a
        if b > d:
            b, d = d, b
        if a / c > angle_diff_max: angle_diff_max = a / c
        if a / c < angle_diff_min: angle_diff_min = a / c
        print "angle diff a/c", a / c
        if b / d > angle_diff_max: angle_diff_max = b / d
        if b / d < angle_diff_min: angle_diff_min = b / d
        print "angle diff b/d", b / d

    print "angle_min", angle_min
    print "angle_max", angle_max
    print "prop_min", prop_min
    print "prop_max", prop_max
    print "rot_max", rot_max
    print "angle_diff_min", angle_diff_min
    print "angle_diff_max", angle_diff_max