Mercurial > games > semicongine
changeset 1473:2cc8103a7418
fix: make vector component assignment work
author | sam <sam@basx.dev> |
---|---|
date | Sun, 06 Apr 2025 21:55:22 +0700 |
parents | cfec585882ce |
children | bb7bbe2fee78 |
files | semicongine/core/vector.nim |
diffstat | 1 files changed, 48 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/semicongine/core/vector.nim Wed Apr 02 22:41:48 2025 +0700 +++ b/semicongine/core/vector.nim Sun Apr 06 21:55:22 2025 +0700 @@ -782,13 +782,60 @@ setterCode, ) +template x*[T: TVec](v: T): untyped = + v[0] + +template y*[T: TVec](v: T): untyped = + v[1] + +template z*[T: TVec](v: T): untyped = + v[2] + +template w*[T: TVec](v: T): untyped = + v[3] + +template r*[T: TVec](v: T): untyped = + v[0] + +template g*[T: TVec](v: T): untyped = + v[1] + +template b*[T: TVec](v: T): untyped = + v[2] + +template a*[T: TVec](v: T): untyped = + v[3] + +template `x=`*[T: TVec, S](v: T, a: S): untyped = + v[0] = a + +template `y=`*[T: TVec, S](v: T, a: S): untyped = + v[1] = a + +template `z=`*[T: TVec, S](v: T, a: S): untyped = + v[2] = a + +template `w=`*[T: TVec, S](v: T, a: S): untyped = + v[3] = a + +template `r=`*[T: TVec, S](v: T, a: S): untyped = + v[0] = a + +template `g=`*[T: TVec, S](v: T, a: S): untyped = + v[1] = a + +template `b=`*[T: TVec, S](v: T, a: S): untyped = + v[2] = a + +template `a=`*[T: TVec, S](v: T, a: S): untyped = + v[3] = a + macro createVectorAttribAccessorFuncs() = const COORD_ATTRS = ["x", "y", "z", "w"] const COLOR_ATTRS = ["r", "g", "b", "a"] result = nnkStmtList.newTree() for attlist in [COORD_ATTRS, COLOR_ATTRS]: for i in attlist: - result.add(vectorAttributeAccessor(i)) for j in attlist: result.add(vectorAttributeAccessor(i & j)) for k in attlist: