Пример #1
0
class self:
	camera = pygame.math.Vector3(0, 0, 0)
	vantage = pygame.math.Vector3(1, 0, 0)
	up = pygame.math.Vector3(0, 0, 1)
	# Countdown timer of how long the camera should lag in catching up to the player
	tosnap = 0

	# Current mouse settings of gamma and phi
	mgamma = 40
	mphi = 0
	# Current actual settings
	gamma = 40
	phi = 0
	atilt = Vector3(0, 0, 0)
	Rvantage = 20

	# Currently in rapid mode
	rapid = False

	# Whether we're in "f"-mode (as in fixed), i.e. in the northwest puzzle
	fmode = False
	fcamera = Vector3(0, 0, 0)
	# Whether we're in "b"-mode (as in final boss), semifixed
	bmode = False
	bphi = 0
Пример #2
0
 def __init__(self, image, speed=0, freeze=0):
     self.speed = speed
     self.freeze = freeze
     self.shadow = pygame.image.load("pillshadow.png")
     self.img = pygame.image.load(image)
     self.pos = Vector3(0, 0, 0)
     self.vel = Vector3(0, 0, 0)
Пример #3
0
def project_v3_camera_point(v3_p,
                            v3_cam,
                            v3_screen=None,
                            v3_cam_angle=None,
                            aspect_ratio=1):
    """Correct formula for perspective

       v3_ps: list of position of the points to be projected
       v3_cam: position of the camera
       v3_screen: position of the screen [default: (0;0;1)]
       v3_cam_angle: alpha, beta, gamma of camera [default 0;0;0)]

       I suck at matrices so I took the formulas from wikipedia
    """
    if v3_screen is None:
        v3_screen = Vector3(0, 0, 1)
    if v3_cam_angle is None:
        v3_cam_angle = Vector3(0, 0, 0)

    rotation, screen_mat = prepare_rotation_matrix(v3_cam, v3_screen,
                                                   v3_cam_angle)
    translated_p = numpy.array(list(v3_p - v3_cam))
    transformed_p = numpy.matmul(rotation, translated_p)
    homo_proj = numpy.matmul(screen_mat, transformed_p)
    #if homo_proj[2] < 0.0001:
    #    homo_proj[2] = 0.0001
    proj_2d = Vector2(aspect_ratio * homo_proj[0] / homo_proj[2],
                      homo_proj[1] / homo_proj[2])
    return proj_2d
Пример #4
0
 def __init__(self):
     "Inicializa o boid"
     # todo: take keyword args like Peter
     self.color = random_Vector3(0.5)  # R G B
     self.location = Vector3(0.0, 0.0, 0.0)  # x y z
     self.velocity = random_Vector3(-1.0, 1.0)  # vx vy vz
     self.adjustment = Vector3(0.0, 0.0, 0.0)  # to accumulate corrections
Пример #5
0
def v4_to_v3(o):
    if len(o) == 4:
        return Vector3([float(a) / float(o[3]) for a in o[0:3]])
    elif len(o) == 3:
        return Vector3([float(a) for a in o])
    else:
        raise RuntimeError("v4_to_v3: wrong parameter passed")
Пример #6
0
def camera_generator(start_pos=Vector3(0, 0, 0),
                     increment_vector=Vector3(0, 0, 0),
                     min_x=None,
                     min_y=None,
                     min_z=None,
                     max_x=None,
                     max_y=None,
                     max_z=None):
    initial_x, initial_y, initial_z = start_pos
    while True:
        yield start_pos
        start_pos = start_pos + increment_vector

        if max_x is not None and start_pos[0] > max_x:
            start_pos[0] = initial_x
        if max_y is not None and start_pos[1] > max_y:
            start_pos[1] = initial_y
        if max_z is not None and start_pos[2] > max_z:
            start_pos[2] = initial_z
        if min_x is not None and start_pos[0] < min_x:
            start_pos[0] = initial_x
        if min_y is not None and start_pos[1] < min_y:
            start_pos[1] = initial_y
        if min_z is not None and start_pos[2] < min_z:
            start_pos[2] = initial_z
 def center3d(self):
     if self._center3d is not None:
         return self._center3d
     min_x, max_x, min_y, max_y, min_z, max_z = getminmax_xyz(self._vertices)
     self.base_w, self.base_h, self.base_d = max_x - min_x, max_y - min_y, max_z - min_z
     self._center3d = Vector3(max_x-min_x, max_y-min_y, max_z-min_z) / 2 + Vector3(min_x, min_y, min_z)
     return self._center3d
Пример #8
0
 def __init__(self, position, direction, size, up=(), color=(0, 0, 0)):
     super().__init__(position, direction, color)
     self.size = Vector3(size) / 2
     self.up = Vector3(up)
     self.radius = self.size.length()
     self.m = [self.rot, self.rot.cross(self.up).normalize()]
     self.m.append(self.rot.cross(self.m[1]))
Пример #9
0
def loadpipe(pipe, jpipe, jfrom, kfrom, jto, kto, x0, y0, z0, x1, y1, z1, w):
    sectionid, fromid, toid = gettunnelids("pipe", jpipe, jfrom, kfrom, jto,
                                           kto)
    p0 = Vector3(float(x0), float(y0), float(z0))
    p1 = Vector3(float(x1), float(y1), float(z1))
    w = float(w)
    state.sections_by_id[sectionid] = section.Pipe(p0, p1, width=w)
    tunnelconnect(sectionid, fromid, toid, oneway=True)
Пример #10
0
def loadslope(slope, jtunnel, jsection, jfrom, kfrom, jto, kto, x0, y0, z0, x1,
              y1, z1, w):
    sectionid, fromid, toid = gettunnelids(jtunnel, jsection, jfrom, kfrom,
                                           jto, kto)
    p0 = Vector3(float(x0), float(y0), float(z0))
    p1 = Vector3(float(x1), float(y1), float(z1))
    w = float(w)
    state.sections_by_id[sectionid] = section.SlopeConnector(p0, p1, width=w)
    tunnelconnect(sectionid, fromid, toid)
Пример #11
0
	def hit(self, you):
		d = you.pos - self.pos
		if d.length() == 0:
			d = Vector3(1, 0, 0)
		if not you.invulnerable():
			you.thurt = 1
		you.vwater += 12 * d.normalize() + Vector3(0, 0, 10)
		you.landed = False
		you.pickvector()
Пример #12
0
 def __init__(self, image, pos, state, turn=1, speed=7):
     self.pos = Vector2(pos)
     self.heading = Vector2(0, 0)
     self.velocity = Vector2(self.heading)
     self.imageName = image
     self.speed = speed
     self.accel = Vector2()
     self.baseColor = Vector3(0, 1, 1)
     self.maxColor = Vector3(0.88, 1, 1)
     self.circleColor = (255, 0, 170)
Пример #13
0
    def __init__(self, game, interval):
        self.game = game
        self.apples = []
        self.timer = interval
        self.appleColor = Vector3(200, 30, 25)
        self.shadeColor = Vector3(130, 25, 20)
        self.highlightColor = Vector3(240, 50, 30)
        self.brown = Vector3(50, 25, 5)
        self.leafColor = Vector3(60, 100, 40)

        self.counter = 0
Пример #14
0
def distance_sorter(polygon):
    p = Vec()
    for v in polygon:
        p.x += v[0]
        p.y += v[1]
        p.z += v[2]
    p.x /= 4
    p.y /= 4
    p.z /= 4

    return p.distance_to(Vec(300, 300, -50))
Пример #15
0
    def initialize(self):
        """Reset the attributes of the ball for a restart.

        Called when the ball leaves the screen and a player scores.
        """
        self.direction = Vector3(random.choice([-8, 8]), random.choice([-8,
                                                                        8]),
                                 random.choice([-10, 10]))
        self.position = Vector3(WIN_CENTER.x, WIN_CENTER.y, WIN_CENTER.z)
        self.rect.center = (self.position.x, self.position.y)
        self.speed_up = 1.0
Пример #16
0
def pipedata(jpipe, pipe):
    jp0 = pipe["jp0"]
    jp1 = pipe["jp1"]
    r = 1.5
    R = pools[jp0]["r"] + 2
    p0 = Vector3(*pools[jp0]["pos"]) + Vector3(0, 0, 0.8 * r)
    d = Vector3(*pools[jp1]["pos"]) - p0
    d.z = 0
    d = R * d.normalize()
    p1 = p0 + d
    return totuple("pipe", jpipe, "pool", jp0, "pool", jp1, *p0, *p1, r)
Пример #17
0
def project(pos, pitch, yaw, cam):
    global e
    x = pos[0] - cam.x
    y = pos[1] - cam.y
    z = pos[2] - cam.z
    d = Vec(x, y, z)
    d = d.rotate(-pitch, Vec(1, 0, 0).rotate(yaw, Vec(0, 1, 0)))
    d = d.rotate(-yaw, Vec(0, 1, 0))
    if d.z > 0.1:
        return (e / d.z * d.x + width / 2, e / d.z * d.y + height / 2)
    else:
        return 0
Пример #18
0
 def _health_bar_color(self) -> tuple:
     health_fraction = float(self.status.health) / self.status.max_health
     if health_fraction > 0.5:
         frac = 2 * (1 - health_fraction)
         vec = Vector3(settings.GREEN) * frac
         vec += Vector3(settings.YELLOW) * (1 - frac)
         col = tuple(vec)
     else:
         frac = 2 * health_fraction
         vec = Vector3(settings.YELLOW) * frac
         vec += Vector3(settings.RED) * (1 - frac)
         col = tuple(vec)
     return col
Пример #19
0
def transformation_rotation3d(object, points):
    out = []
    for point in points:
        if len(point) != 3:
            logger.error(
                "Tried to perform a 3D transformation on a 2D point: %s (for %s)",
                point, object)
        cv = Vector3(*object.center3d)
        o = Vector3(point) - cv
        o = o.rotate_x(object.alpha_angle)
        o = o.rotate_y(object.beta_angle)
        o = o.rotate_z(object.gamma_angle)
        out.append(o + cv)
    return out
Пример #20
0
def rotate3D_point_with_center(point, center, alpha, beta, gamma):
    """
        rotate a set of points around three angles

    """
    if len(point) == 2:
        point = Vector3(point[0], point[1], 0)
    cv = Vector3(*center)
    # translate coordinates to center, rotate, and re-translate
    o = point - cv
    # rotate around the three angles
    o = o.rotate_x(alpha)
    o = o.rotate_y(beta)
    o = o.rotate_z(gamma)
    return o + cv
Пример #21
0
    def __init__(self, image, face):
        self.face = pygame.image.load(face + ".png")
        self.blink = pygame.image.load(face + "blink.png")
        self.shadow = pygame.image.load("blobshadow.png")
        self.frozenbody = pygame.image.load("frozenbody.png")

        self.img = pygame.image.load(image)

        self.pos = Vector3(0, 0, 0)
        self.vel = Vector3(0, 0, 0)
        self.score = 0
        self.speed = 0.4
        self.freeze = 0
        self.eating = 0
        self.blinking = 0
Пример #22
0
 def __init__(self):
     self.taille = 6
     self.direction = Vector2(0, 0)
     self.position = Vector2(0, 0)
     self.couleur = Vector3(random.randint(0, 255), random.randint(0, 255),
                            random.randint(0, 255))
     self.start = False
Пример #23
0
def run():
    pygame.init()
    screen = pygame.display.set_mode(SCREENSIZE, 0)

    font = pygame.font.SysFont(pygame.font.get_default_font(), 24)

    ball = pygame.image.load("ball.png").convert_alpha()

    points = []
    fov = 90
    vd = get_vd(fov, SCREENSIZE[1])

    for x in range(0, CUBESIZE + 1, 30):
        ex = x == 0 or x == CUBESIZE
        for y in range(0, CUBESIZE + 1, 30):
            ey = y == 0 or y == CUBESIZE
            for z in range(0, CUBESIZE + 1, 30):
                ez = z == 0 or z == CUBESIZE
                if sum(int(ex), int(ey), int(ez)) != 2:
                    continue
                    points.append[Vector3(x, y, z)]

    def getz(point):
        return point.z

    points.sort(key=getz, reverse=True)

    cx, cy = SCREENSIZE
    cx /= 2
    cy /= 2

    bw, bh = ball.get_size()
    bcx = bw / 2
    bcy = bh / 2
Пример #24
0
 def __init__(self):
     self.taille = 35
     self.vitesse = 1000
     self.forme = "rond"
     self.position = Vector2(200, 200)
     self.direction = Vector2()
     self.couleur = Vector3(255, 255, 0)
Пример #25
0
    def __init__(self):
        self.size = 10
        self.shape = "rond"

        self.couleur = Vector3(255, 0, 0)
        self.direction = Vector2(0, 0)
        self.position = Vector2(0, 0)
Пример #26
0
def enforce_v3(object, points):
    out = []
    for point in points:
        if len(point) == 2:
            point = Vector3(point[0], point[1], 0)
        out.append(point)
    return out
Пример #27
0
 def atilt(self, you):
     r = you.pos - self.center
     if r.length() < 6:
         r.scale_to_length(6)
     v = self.vflow(you.pos)
     u = r.cross(Vector3(0, 0, 1)).normalize()
     a = -abs(v.cross(r).z * (v.length() / r.length_squared()))
     return u * 25 * math.tanh(a * 0.1)
Пример #28
0
    def __init__(self, x, y):
        self.val = random.choice([0, 0, 3, 8, 12, 18])

        if 1 <= self.val < 5:
            color = Vector3(0, 255, 0)
        elif 5 <= self.val < 10:
            color = Vector3(255, 255, 0)
        elif 10 <= self.val < 15:
            color = Vector3(255, 125, 0)
        elif 15 <= self.val <= 20:
            color = Vector3(255, 0, 0)
        else:
            color = Vector3(0, 0, 0)

        self.couleur = color

        self.position = Vector2(x, y)
Пример #29
0
    def afficher(self, core):

        if 1 <= self.val < 5:
            color = Vector3(0, 255, 0)
        elif 5 <= self.val < 10:
            color = Vector3(255, 255, 0)
        elif 10 <= self.val < 15:
            color = Vector3(255, 125, 0)
        elif 15 <= self.val <= 20:
            color = Vector3(255, 0, 0)
        else:
            color = Vector3(0, 0, 0)

        self.couleur = color

        if self.val != 0:
            pygame.draw.rect(core.screen, self.couleur, (self.position.x, self.position.y, 35, 35))
Пример #30
0
def loadpool(pool, jpool, cx, cy, cz, r, pressure0, drainable):
    sectionid = parseid(pool, jpool)
    center = Vector3(float(cx), float(cy), float(cz))
    r = float(r)
    pressure0 = int(pressure0)
    drainable = drainable == "True"
    state.sections_by_id[sectionid] = section.Pool(center, r, pressure0,
                                                   drainable)