Esempio n. 1
0
    def _list_to_vec(self, value):
        if isinstance(value, (int, float, complex)):
            return Vec3(value, value, value)

        if len(value) % 2 == 0:
            new_value = Vec2()
            for i in range(0, len(value), 2):
                new_value.add_x(value[i])
                new_value.add_y(value[i + 1])

        if len(value) % 3 == 0:
            new_value = Vec3()
            for i in range(0, len(value), 3):
                new_value.add_x(value[i])
                new_value.add_y(value[i + 1])
                new_value.add_z(value[i + 2])

        return new_value
Esempio n. 2
0
    def __init__(self):
        super().__init__()
        loadPrcFileData('', 'window-title ursina')
        loadPrcFileData('', 'notify-level-util error')
        loadPrcFileData('', 'textures-auto-power-2 #t')
        loadPrcFileData('', 'load-file-type p3assimp')
        # loadPrcFileData('', 'allow-portal-cull #t')
        # loadPrcFileData("", "framebuffer-multisample 1")
        # loadPrcFileData('', 'multisamples 2')
        # loadPrcFileData('', 'textures-power-2 none')
        # loadPrcFileData('', 'threading-model Cull/Draw')
        loadPrcFileData('', 'coordinate-system y-up-left')

        # fallback to one of these if opengl is not supported
        loadPrcFileData('', 'aux-display pandadx9')
        loadPrcFileData('', 'aux-display pandadx8')
        loadPrcFileData('', 'aux-display tinydisplay')

        self.vsync = True  # can't be set during play
        self.show_ursina_splash = False

        self.title = application.asset_folder.name
        self.borderless = True
        # self.icon = 'textures/ursina.ico'
        os_name = platform.system()

        try:
            if os_name == 'Windows':  # windows
                import ctypes
                user32 = ctypes.windll.user32
                user32.SetProcessDPIAware()
                self.screen_resolution = (user32.GetSystemMetrics(0),
                                          user32.GetSystemMetrics(1))

            elif os_name == 'Linux':
                import Xlib
                import Xlib.display
                resolution = Xlib.display.Display().screen().root.get_geometry(
                )
                self.screen_resolution = Vec2(resolution.width,
                                              resolution.height)

            elif os_name == 'Darwin':  # mac
                from AppKit import NSScreen
                size = NSScreen.mainScreen().frame().size
                self.screen_resolution = [size.width, size.height]
        except:
            from screeninfo import get_monitors
            self.screen_resolution = [
                get_monitors()[0].width,
                get_monitors()[0].height
            ]

        self.fullscreen_size = Vec2(*self.screen_resolution)
        self.windowed_size = self.fullscreen_size / 1.25
        self.windowed_position = None  # gets set when entering fullscreen so position will be correct when going back to windowed mode
        self.forced_aspect_ratio = None  # example: window.forced_aspect_ratio = 16/9
        self.size = self.windowed_size
        self.always_on_top = False

        self.top = Vec2(0, .5)
        self.bottom = Vec2(0, -.5)
        self.center = Vec2(0, 0)
Esempio n. 3
0
 def center_on_screen(self):
     self.position = Vec2(
         int((self.screen_resolution[0] - self.size[0]) / 2),
         int((self.screen_resolution[1] - self.size[1]) / 2))
Esempio n. 4
0
 def bottom_right(self):
     return Vec2(self.aspect_ratio / 2, -.5)
Esempio n. 5
0
 def bottom_left(self):
     return Vec2(-self.aspect_ratio / 2, -.5)
Esempio n. 6
0
 def top_right(self):
     return Vec2(self.aspect_ratio / 2, .5)
Esempio n. 7
0
def sum(l):
    try:
        return internal_sum(l)
    except:
        pass

    total = l[0].__class__()
    for e in l:
        total += e

    return total


if __name__ == '__main__':
    from ursina import *
    app = Ursina()
    e1 = Entity(position = (0,0,0))
    e2 = Entity(position = (0,1,1))
    distance(e1, e2)
    distance_xz(e1, e2.position)

    between_color = lerp(color.lime, color.magenta, .5)
    print(between_color)
    print(lerp((0,0), (0,1), .5))
    print(lerp(Vec2(0,0), Vec2(0,1), .5))
    print(lerp([0,0], [0,1], .5))

    print(round(Vec3(.38, .1351, 353.26), 2))

    app.run()
Esempio n. 8
0
 def right(self):
     return Vec2(self.aspect_ratio / 2, 0)
Esempio n. 9
0
 def xy(self):
     return Vec2(self.x, self.y)
Esempio n. 10
0
 def tile_coordinate(self, value):
     self._tile_coordinate = value
     self.texture_offset = Vec2(value[0] / self.tileset_size[0],
                                value[1] / self.tileset_size[1])
Esempio n. 11
0
 def tileset_size(self, value):
     self._tileset_size = value
     self.texture_scale = Vec2(1 / value[0], 1 / value[1])
Esempio n. 12
0
 def texture_offset(self):
     if not hasattr(self, '_texture_offset'):
         return Vec2(0, 0)
     return self._texture_offset
Esempio n. 13
0
 def texture_scale(self):
     if not hasattr(self, '_texture_scale'):
         return Vec2(1, 1)
     return self._texture_scale
Esempio n. 14
0
 def size(self):
     if not self.borderless:
         return Vec2(*base.win.getSize())
     return self._size
Esempio n. 15
0
 def xz(self):
     return Vec2(self.x, self.z)
Esempio n. 16
0
 def left(self):
     return Vec2(-self.aspect_ratio / 2, 0)
Esempio n. 17
0
 def yz(self):
     return Vec2(self.y, self.z)
Esempio n. 18
0
 def top_left(self):
     return Vec2(-self.aspect_ratio / 2, .5)
Esempio n. 19
0
 def size(self):
     return Vec2(self.width, self.height)