feat: upgrade pyglet
This commit is contained in:
parent
906abc5109
commit
72b3473cbe
@ -456,9 +456,10 @@ class Vec3:
|
|||||||
:returns: A unit vector with the same rotation.
|
:returns: A unit vector with the same rotation.
|
||||||
:rtype: Vec3
|
:rtype: Vec3
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
d = self.__abs__()
|
d = self.__abs__()
|
||||||
if d:
|
|
||||||
return Vec3(self.x / d, self.y / d, self.z / d)
|
return Vec3(self.x / d, self.y / d, self.z / d)
|
||||||
|
except ZeroDivisionError:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def clamp(self, min_val: float, max_val: float) -> Vec3:
|
def clamp(self, min_val: float, max_val: float) -> Vec3:
|
||||||
@ -868,11 +869,16 @@ class Mat4(tuple):
|
|||||||
0.0, 0.0, 0.0, 1.0))
|
0.0, 0.0, 0.0, 1.0))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def look_at(cls, position: Vec3, target: Vec3, up: Vec3) -> Mat4:
|
def look_at(cls: type[Mat4T], position: Vec3, target: Vec3, up: Vec3):
|
||||||
direction = target - position
|
f = (target - position).normalize()
|
||||||
direction_mat4 = cls.look_at_direction(direction, up)
|
u = up.normalize()
|
||||||
position_mat4 = cls.from_translation(-position)
|
s = f.cross(u)
|
||||||
return direction_mat4 @ position_mat4
|
u = s.cross(f)
|
||||||
|
|
||||||
|
return cls([s.x, u.x, -f.x, 0.0,
|
||||||
|
s.y, u.y, -f.y, 0.0,
|
||||||
|
s.z, u.z, -f.z, 0.0,
|
||||||
|
-s.dot(position), -u.dot(position), f.dot(position), 1.0])
|
||||||
|
|
||||||
def row(self, index: int) -> tuple:
|
def row(self, index: int) -> tuple:
|
||||||
"""Get a specific row as a tuple."""
|
"""Get a specific row as a tuple."""
|
||||||
|
@ -185,14 +185,13 @@ class _ShapeGroup(Group):
|
|||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return (other.__class__ is self.__class__ and
|
return (other.__class__ is self.__class__ and
|
||||||
|
self.program == other.program and
|
||||||
self.parent == other.parent and
|
self.parent == other.parent and
|
||||||
self.order == other.order and
|
|
||||||
self.blend_src == other.blend_src and
|
self.blend_src == other.blend_src and
|
||||||
self.blend_dest == other.blend_dest and
|
self.blend_dest == other.blend_dest)
|
||||||
self.program == other.program)
|
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((id(self.parent), self.blend_src, self.blend_dest, self.order, self.program))
|
return hash((self.program, self.parent, self.blend_src, self.blend_dest))
|
||||||
|
|
||||||
|
|
||||||
class ShapeBase(ABC):
|
class ShapeBase(ABC):
|
||||||
|
@ -209,7 +209,7 @@ class SpriteGroup(graphics.Group):
|
|||||||
same parent group, texture and blend parameters.
|
same parent group, texture and blend parameters.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, texture, blend_src, blend_dest, program, order=0, parent=None):
|
def __init__(self, texture, blend_src, blend_dest, program, parent=None):
|
||||||
"""Create a sprite group.
|
"""Create a sprite group.
|
||||||
|
|
||||||
The group is created internally when a :py:class:`~pyglet.sprite.Sprite`
|
The group is created internally when a :py:class:`~pyglet.sprite.Sprite`
|
||||||
@ -231,7 +231,7 @@ class SpriteGroup(graphics.Group):
|
|||||||
`parent` : `~pyglet.graphics.Group`
|
`parent` : `~pyglet.graphics.Group`
|
||||||
Optional parent group.
|
Optional parent group.
|
||||||
"""
|
"""
|
||||||
super().__init__(order, parent)
|
super().__init__(parent=parent)
|
||||||
self.texture = texture
|
self.texture = texture
|
||||||
self.blend_src = blend_src
|
self.blend_src = blend_src
|
||||||
self.blend_dest = blend_dest
|
self.blend_dest = blend_dest
|
||||||
@ -263,7 +263,7 @@ class SpriteGroup(graphics.Group):
|
|||||||
self.blend_dest == other.blend_dest)
|
self.blend_dest == other.blend_dest)
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.parent, id(self.program),
|
return hash((self.program, self.parent,
|
||||||
self.texture.id, self.texture.target,
|
self.texture.id, self.texture.target,
|
||||||
self.blend_src, self.blend_dest))
|
self.blend_src, self.blend_dest))
|
||||||
|
|
||||||
@ -335,7 +335,7 @@ class Sprite(event.EventDispatcher):
|
|||||||
self._texture = img.get_texture()
|
self._texture = img.get_texture()
|
||||||
|
|
||||||
self._batch = batch or graphics.get_default_batch()
|
self._batch = batch or graphics.get_default_batch()
|
||||||
self._group = self.group_class(self._texture, blend_src, blend_dest, self.program, 0, group)
|
self._group = self.group_class(self._texture, blend_src, blend_dest, self.program, group)
|
||||||
self._subpixel = subpixel
|
self._subpixel = subpixel
|
||||||
self._create_vertex_list()
|
self._create_vertex_list()
|
||||||
|
|
||||||
@ -434,7 +434,6 @@ class Sprite(event.EventDispatcher):
|
|||||||
self._group.blend_src,
|
self._group.blend_src,
|
||||||
self._group.blend_dest,
|
self._group.blend_dest,
|
||||||
self._group.program,
|
self._group.program,
|
||||||
0,
|
|
||||||
group)
|
group)
|
||||||
self._batch.migrate(self._vertex_list, GL_TRIANGLES, self._group, self._batch)
|
self._batch.migrate(self._vertex_list, GL_TRIANGLES, self._group, self._batch)
|
||||||
|
|
||||||
@ -472,7 +471,6 @@ class Sprite(event.EventDispatcher):
|
|||||||
self._group.blend_src,
|
self._group.blend_src,
|
||||||
self._group.blend_dest,
|
self._group.blend_dest,
|
||||||
self._group.program,
|
self._group.program,
|
||||||
0,
|
|
||||||
self._group.parent)
|
self._group.parent)
|
||||||
self._vertex_list.delete()
|
self._vertex_list.delete()
|
||||||
self._texture = texture
|
self._texture = texture
|
||||||
@ -871,7 +869,6 @@ class AdvancedSprite(pyglet.sprite.Sprite):
|
|||||||
self._group.blend_src,
|
self._group.blend_src,
|
||||||
self._group.blend_dest,
|
self._group.blend_dest,
|
||||||
program,
|
program,
|
||||||
0,
|
|
||||||
self._group)
|
self._group)
|
||||||
self._batch.migrate(self._vertex_list, GL_TRIANGLES, self._group, self._batch)
|
self._batch.migrate(self._vertex_list, GL_TRIANGLES, self._group, self._batch)
|
||||||
self._program = program
|
self._program = program
|
||||||
|
Loading…
Reference in New Issue
Block a user