This commit is contained in:
blueloveTH 2023-07-01 22:41:19 +08:00
parent 3c64f59fd3
commit 320d2e1f3b
2 changed files with 13 additions and 0 deletions

View File

@ -305,6 +305,12 @@ PyObject* py_var(VM*, const PyVec4&);
PyObject* py_var(VM*, const Mat3x3&); PyObject* py_var(VM*, const Mat3x3&);
PyObject* py_var(VM*, const PyMat3x3&); PyObject* py_var(VM*, const PyMat3x3&);
#define BIND_VEC_ADDR(D) \
vm->bind_method<0>(type, "addr", [](VM* vm, ArgsView args){ \
PyVec##D& self = _CAST(PyVec##D&, args[0]); \
return VAR_T(VoidP, &self.x); \
});
#define BIND_VEC_VEC_OP(D, name, op) \ #define BIND_VEC_VEC_OP(D, name, op) \
vm->bind_method<1>(type, #name, [](VM* vm, ArgsView args){ \ vm->bind_method<1>(type, #name, [](VM* vm, ArgsView args){ \
PyVec##D& self = _CAST(PyVec##D&, args[0]); \ PyVec##D& self = _CAST(PyVec##D&, args[0]); \
@ -385,6 +391,7 @@ struct PyVec2: Vec2 {
return VAR(self); return VAR(self);
}); });
BIND_VEC_ADDR(2)
BIND_VEC_VEC_OP(2, __add__, +) BIND_VEC_VEC_OP(2, __add__, +)
BIND_VEC_VEC_OP(2, __sub__, -) BIND_VEC_VEC_OP(2, __sub__, -)
BIND_VEC_FLOAT_OP(2, __mul__, *) BIND_VEC_FLOAT_OP(2, __mul__, *)
@ -433,6 +440,7 @@ struct PyVec3: Vec3 {
return VAR_T(PyVec3, self); return VAR_T(PyVec3, self);
}); });
BIND_VEC_ADDR(3)
BIND_VEC_VEC_OP(3, __add__, +) BIND_VEC_VEC_OP(3, __add__, +)
BIND_VEC_VEC_OP(3, __sub__, -) BIND_VEC_VEC_OP(3, __sub__, -)
BIND_VEC_FLOAT_OP(3, __mul__, *) BIND_VEC_FLOAT_OP(3, __mul__, *)
@ -483,6 +491,7 @@ struct PyVec4: Vec4{
return VAR_T(PyVec4, self); return VAR_T(PyVec4, self);
}); });
BIND_VEC_ADDR(4)
BIND_VEC_VEC_OP(4, __add__, +) BIND_VEC_VEC_OP(4, __add__, +)
BIND_VEC_VEC_OP(4, __sub__, -) BIND_VEC_VEC_OP(4, __sub__, -)
BIND_VEC_FLOAT_OP(4, __mul__, *) BIND_VEC_FLOAT_OP(4, __mul__, *)

View File

@ -1,4 +1,5 @@
from typing import overload from typing import overload
from c import float_p
class vec2: class vec2:
x: float x: float
@ -16,6 +17,7 @@ class vec2:
def length_squared(self) -> float: ... def length_squared(self) -> float: ...
def normalize(self) -> vec2: ... def normalize(self) -> vec2: ...
def rotate(self, radians: float) -> vec2: ... def rotate(self, radians: float) -> vec2: ...
def addr(self) -> float_p: ...
class vec3: class vec3:
x: float x: float
@ -33,6 +35,7 @@ class vec3:
def length(self) -> float: ... def length(self) -> float: ...
def length_squared(self) -> float: ... def length_squared(self) -> float: ...
def normalize(self) -> vec3: ... def normalize(self) -> vec3: ...
def addr(self) -> float_p: ...
class vec4: class vec4:
x: float x: float
@ -50,6 +53,7 @@ class vec4:
def length(self) -> float: ... def length(self) -> float: ...
def length_squared(self) -> float: ... def length_squared(self) -> float: ...
def normalize(self) -> vec4: ... def normalize(self) -> vec4: ...
def addr(self) -> float_p: ...
class mat3x3: class mat3x3:
_11: float _11: float