ncca-ngl 0.2.3__py3-none-any.whl → 0.2.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ncca/ngl/__init__.py CHANGED
@@ -41,7 +41,7 @@ from .simple_vao import SimpleVAO
41
41
  from .text import Text
42
42
  from .texture import Texture
43
43
  from .transform import Transform, TransformRotationOrder
44
- from .util import calc_normal, clamp, frustum, lerp, look_at, ortho, perspective
44
+ from .util import PerspMode, calc_normal, clamp, frustum, lerp, look_at, ortho, perspective
45
45
  from .vao_factory import VAOFactory, VAOType
46
46
  from .vec2 import Vec2
47
47
  from .vec2_array import Vec2Array
@@ -110,4 +110,5 @@ all = [
110
110
  PrimData,
111
111
  FirstPersonCamera,
112
112
  PySideEventHandlingMixin,
113
+ PerspMode,
113
114
  ]
ncca/ngl/abstract_vao.py CHANGED
@@ -52,14 +52,10 @@ class AbstractVAO(abc.ABC):
52
52
  def remove_vao(self):
53
53
  raise NotImplementedError
54
54
 
55
- def set_vertex_attribute_pointer(
56
- self, id, size, type, stride, offset, normalize=False
57
- ):
55
+ def set_vertex_attribute_pointer(self, id, size, type, stride, offset, normalize=False):
58
56
  if not self.bound:
59
57
  logger.error("VAO not bound in set_vertex_attribute_pointer")
60
- gl.glVertexAttribPointer(
61
- id, size, type, normalize, stride, ctypes.c_void_p(offset)
62
- )
58
+ gl.glVertexAttribPointer(id, size, type, normalize, stride, ctypes.c_void_p(offset))
63
59
  gl.glEnableVertexAttribArray(id)
64
60
 
65
61
  def set_num_indices(self, count):
ncca/ngl/prim_data.py CHANGED
@@ -10,7 +10,7 @@ from .vec3 import Vec3
10
10
  class Prims(enum.Enum):
11
11
  """Enum for the default primitives that can be loaded."""
12
12
 
13
- BUDDAH = "buddah"
13
+ BUDDHA = "buddah"
14
14
  BUNNY = "bunny"
15
15
  CUBE = "cube"
16
16
  DODECAHEDRON = "dodecahedron"
ncca/ngl/quaternion.py CHANGED
@@ -10,6 +10,7 @@ Attributes:
10
10
  import math
11
11
 
12
12
  from .mat4 import Mat4
13
+ from .vec3 import Vec3
13
14
 
14
15
 
15
16
  class Quaternion:
@@ -75,9 +76,7 @@ class Quaternion:
75
76
  return Quaternion(s, x, y, z)
76
77
 
77
78
  def __add__(self, rhs):
78
- return Quaternion(
79
- self.s + rhs.s, self.x + rhs.x, self.y + rhs.y, self.z + rhs.z
80
- )
79
+ return Quaternion(self.s + rhs.s, self.x + rhs.x, self.y + rhs.y, self.z + rhs.z)
81
80
 
82
81
  def __iadd__(self, rhs):
83
82
  self.s += rhs.s
@@ -87,20 +86,57 @@ class Quaternion:
87
86
  return self
88
87
 
89
88
  def __sub__(self, rhs):
90
- return Quaternion(
91
- self.s - rhs.s, self.x - rhs.x, self.y - rhs.y, self.z - rhs.z
92
- )
89
+ return Quaternion(self.s - rhs.s, self.x - rhs.x, self.y - rhs.y, self.z - rhs.z)
93
90
 
94
91
  def __isub__(self, rhs):
95
92
  return self.__sub__(rhs)
96
93
 
94
+ # def __mul__(self, rhs):
95
+ # return Quaternion(
96
+ # self.s * rhs.s - self.x * rhs.x - self.y * rhs.y - self.z * rhs.z,
97
+ # self.s * rhs.x + self.x * rhs.s + self.y * rhs.z - self.z * rhs.y,
98
+ # self.s * rhs.y - self.x * rhs.z + self.y * rhs.s + self.z * rhs.x,
99
+ # self.s * rhs.z + self.x * rhs.y - self.y * rhs.x + self.z * rhs.s,
100
+ # )
101
+
97
102
  def __mul__(self, rhs):
98
- return Quaternion(
99
- self.s * rhs.s - self.x * rhs.x - self.y * rhs.y - self.z * rhs.z,
100
- self.s * rhs.x + self.x * rhs.s + self.y * rhs.z - self.z * rhs.y,
101
- self.s * rhs.y - self.x * rhs.z + self.y * rhs.s + self.z * rhs.x,
102
- self.s * rhs.z + self.x * rhs.y - self.y * rhs.x + self.z * rhs.s,
103
- )
103
+ if isinstance(rhs, Quaternion):
104
+ return Quaternion(
105
+ self.s * rhs.s - self.x * rhs.x - self.y * rhs.y - self.z * rhs.z,
106
+ self.s * rhs.x + self.x * rhs.s + self.y * rhs.z - self.z * rhs.y,
107
+ self.s * rhs.y - self.x * rhs.z + self.y * rhs.s + self.z * rhs.x,
108
+ self.s * rhs.z + self.x * rhs.y - self.y * rhs.x + self.z * rhs.s,
109
+ )
110
+ elif isinstance(rhs, Vec3):
111
+ qw = self.s
112
+ qx = self.x
113
+ qy = self.y
114
+ qz = self.z
115
+
116
+ vx = rhs.x
117
+ vy = rhs.y
118
+ vz = rhs.z
119
+
120
+ # pq
121
+ pw = -qx * vx - qy * vy - qz * vz
122
+ px = qw * vx + qy * vz - qz * vy
123
+ py = qw * vy - qx * vz + qz * vx
124
+ pz = qw * vz + qx * vy - qy * vx
125
+
126
+ # pqp*
127
+ return Vec3(
128
+ -pw * qx + px * qw - py * qz + pz * qy,
129
+ -pw * qy + px * qz + py * qw - pz * qx,
130
+ -pw * qz - px * qy + py * qx + pz * qw,
131
+ )
132
+
133
+ def normalize(self):
134
+ length = math.sqrt(self.s * self.s + self.x * self.x + self.y * self.y + self.z * self.z)
135
+ if length > 0:
136
+ self.s /= length
137
+ self.x /= length
138
+ self.y /= length
139
+ self.z /= length
104
140
 
105
141
  def __str__(self) -> str:
106
142
  """
ncca/ngl/vec2.py CHANGED
@@ -5,6 +5,8 @@ Simple float only Vec2 class for 3D graphics, very similar to the pyngl ones
5
5
  import ctypes
6
6
  import math
7
7
 
8
+ import numpy as np
9
+
8
10
  from .util import clamp
9
11
 
10
12
 
@@ -74,7 +76,7 @@ class Vec2:
74
76
  Raises:
75
77
  ValueError: If v is not a float or int.
76
78
  """
77
- if not isinstance(v, (int, float)):
79
+ if not isinstance(v, (int, float, np.float32)):
78
80
  raise ValueError("need float or int")
79
81
  else:
80
82
  setattr(self, name, v)
ncca/ngl/vec3.py CHANGED
@@ -73,7 +73,7 @@ class Vec3:
73
73
  Raises:
74
74
  ValueError: If v is not a float or int.
75
75
  """
76
- if not isinstance(v, (int, float)):
76
+ if not isinstance(v, (int, float, np.float32)):
77
77
  raise ValueError("need float or int")
78
78
  else:
79
79
  setattr(self, name, v)
ncca/ngl/vec4.py CHANGED
@@ -33,7 +33,7 @@ class Vec4:
33
33
  Raises:
34
34
  ValueError: If v is not a float or int.
35
35
  """
36
- if not isinstance(v, (int, float)):
36
+ if not isinstance(v, (int, float, np.float32)):
37
37
  raise ValueError("need float or int")
38
38
  else:
39
39
  setattr(self, name, v)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ncca-ngl
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: A Python version of the NGL graphics library.
5
5
  Author: Jon Macey
6
6
  Author-email: Jon Macey <jmacey@bournemouth.ac.uk>
@@ -15,8 +15,8 @@ ncca/ngl/PrimData/pack_arrays.py,sha256=aWShJX8QPHXKTj66C8yu1DskmD3VEzFXyaADcxw6
15
15
  ncca/ngl/PrimData/teapot.npy,sha256=fiOfYtB5SkegO7uTSitpjl_HmnS_iIy0sXAGfxCXXjY,1350560
16
16
  ncca/ngl/PrimData/tetrahedron.npy,sha256=_KCSpflFXhYB4gGVxFmF5Cv6pQyPHuUlCj9xfL2oyEM,512
17
17
  ncca/ngl/PrimData/troll.npy,sha256=ohgGgxLCJrmsFdNrlfRY2Rg9eJgcmvArf6IAspO2BKA,3505280
18
- ncca/ngl/__init__.py,sha256=q_DDdcYjGy26vMOeK8xT4oiOE5QKS678y1XsbxfwMgc,2614
19
- ncca/ngl/abstract_vao.py,sha256=VLKp3pmPYK_dQgEImMOAQ0DufAswK_0H4DR4r8flp2U,2104
18
+ ncca/ngl/__init__.py,sha256=2zCMEMQLSZNeWUTY1i7GnRZqhmerPy1F220NoFPfJB0,2640
19
+ ncca/ngl/abstract_vao.py,sha256=fi7-BIfw1jefcXe09Qj2gGmnqqA9kzJK-hAwfG14Hrc,2068
20
20
  ncca/ngl/base_mesh.py,sha256=2JmVT5_bvgLHra1VnwRld-mh-20IqqekgEu1dbGU1a4,5736
21
21
  ncca/ngl/base_mesh.pyi,sha256=kobLuNnCSZlRRobIgVopQaS7Bjg0tJ3m4M64WXt5I-M,173
22
22
  ncca/ngl/bbox.py,sha256=PylB6ju_bkdDUqQkzO1n2E-jsmxiviNkyBLY-sN59n8,6578
@@ -30,10 +30,10 @@ ncca/ngl/mat4.py,sha256=i6ZKnMpwJdh8ULTjcnWKPo9UK39ulU4WeUdoet4yZAE,17574
30
30
  ncca/ngl/multi_buffer_vao.py,sha256=cuNE6gSrqkNcYvfIOYOZp4MVnpCvChUgnzsf7b60pWg,1752
31
31
  ncca/ngl/obj.py,sha256=AGldNouHrkrDs2UhATClGkgo4dzr6lzArR4YeCxQKmo,13667
32
32
  ncca/ngl/plane.py,sha256=96WuGzexYKhoeRVevGP2pZcustt9fzyyAjuwJHT25tk,1299
33
- ncca/ngl/prim_data.py,sha256=sBynXeAfVtYXK7dkdLYELo0VIbN1lK1KZ8KMmCWzjBA,19047
33
+ ncca/ngl/prim_data.py,sha256=SmHoN1wpQlu3HSfZuLBqsR8jEnVGAqdXcwSq62Lepgg,19047
34
34
  ncca/ngl/primitives.py,sha256=pThdSWLv7jJa9weBVOXhRgTfVVH54AWCbsDFCEI1YLg,4841
35
35
  ncca/ngl/pyside_event_handling_mixin.py,sha256=L8obXeTp-g2Va2eXyd1hnmSp-sY7p4GX6EcFYRnH1F4,10588
36
- ncca/ngl/quaternion.py,sha256=agmbW8i125FyLOV2Z9SpTY5yQwmnnm0rxQawwHqq1YI,3858
36
+ ncca/ngl/quaternion.py,sha256=hvMoaV7uxx60boPg4cTqLJDyTpFZrEpUhikNqmNVTrU,5188
37
37
  ncca/ngl/random.py,sha256=wX1R2rMpb76TP4rk44NUp5XoVuMisH9d-eBG5kFBZsM,5579
38
38
  ncca/ngl/shader.py,sha256=fEz8R_itsQssIxQp1E8-PhY3aOaTdm7sXpyFYoARSic,7696
39
39
  ncca/ngl/shader_lib.py,sha256=YmF3EJM9roTEt5OI5sHonAVN_ydIseyiOUBFZTX4KdA,18627
@@ -54,12 +54,12 @@ ncca/ngl/texture.py,sha256=OgBBEItgUDohCsVWgmjEWcQWBJaXl9w070PTOOywPx4,2303
54
54
  ncca/ngl/transform.py,sha256=_PibgtFoU_exfvQUWucmts0WF5OreSTNbftvSa3zT8g,2938
55
55
  ncca/ngl/util.py,sha256=8jp5vTVuGfVHMSktFEubtoaQ8SvLIQtM2UNbUeMTOFk,4372
56
56
  ncca/ngl/vao_factory.py,sha256=v87VfrUMaoqcsE-CS9kM7h5Fyk_e0LGl_iA6xqaomPg,930
57
- ncca/ngl/vec2.py,sha256=XLDBdSS2uqJbDG4gl1bL2YR79fl77bQeu98OEMQMVCQ,10204
57
+ ncca/ngl/vec2.py,sha256=ggrBtJK77c9d_JnN6eik50kZAa1zjudWhll6_5afkFo,10236
58
58
  ncca/ngl/vec2_array.py,sha256=7QRgXh75fORsmNnSnNxNQWk6_rnDgfmRX3tmJZ4ES9E,3420
59
- ncca/ngl/vec3.py,sha256=NAiwdosG5ONcdGBBQGCfnskMdj7MH3eGagavjaU1SyI,12263
59
+ ncca/ngl/vec3.py,sha256=N_-LvP0nB0CQrZWG7TJntUl6QDHzIVLP-J1w8wPZTM0,12275
60
60
  ncca/ngl/vec3_array.py,sha256=fLRC8k0TwcaU7CnR2GmJ0prud4dcvvUX0JTbQH_2W3Y,3535
61
- ncca/ngl/vec4.py,sha256=rkowZkxacU9l0piLnsEYdgMn94gdkYUzipcn4i8lES0,6739
61
+ ncca/ngl/vec4.py,sha256=mLl23D-3yAxh7GsP44ilRto-PMqIDxJjcZpNl2MyqGQ,6751
62
62
  ncca/ngl/vec4_array.py,sha256=PSJXfG0g2AT4oQCLHiVAP6EC5n7vMXRQy0N1rGvv1iw,3426
63
- ncca_ngl-0.2.3.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
64
- ncca_ngl-0.2.3.dist-info/METADATA,sha256=NDXrssowGaXxZNo2-cZlO0yl-mtiYlz_BQfGZe12OBg,1596
65
- ncca_ngl-0.2.3.dist-info/RECORD,,
63
+ ncca_ngl-0.2.5.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
64
+ ncca_ngl-0.2.5.dist-info/METADATA,sha256=-oJBR9uyewb9MnPn6ifLU6eqp3TBukVUP1zWfeGRo50,1596
65
+ ncca_ngl-0.2.5.dist-info/RECORD,,