Skip to content

add a function to apply affine transforms to vectors #140

@jimy-byerley

Description

@jimy-byerley

Hello !
here is the issue for one of the specific suggesions from #139

Half the operations I do with mat4 is transforming a vec3, I suppose that's the same for many users.
But as mat4 and vec3 are not dimensionally compatible for matrix product, there is always the need to convert them. Could it be possible to have a function doing this multiplication ?

motivation

# this is the current way to apply an affine transformation
>>> vec3(matrix * vec4(v,1))    # many conversions and parenthesis for just one vector

# this could be a nicer way, at least more efficient
>>> hmul(matrix, v)   # all conversions made in C code, so much more efficient

(I thought to name it hmul as in Homogeneous Multiplication because affineMul in the spirit of affineInverse seemed too cumbersome)

I suspect having such a function dedicated to mat4 * vec3 operation would be more efficient than the current way because there is currently 2 conversions (vec3->vec4 before and then after operation again vec4->vec3) thus 2 object allocation; where a c++ function would optimize all this in jsut the product.

feature

The following could be the overloaded functions corresponding to the need I describe here:

hmul(mat4, vec3) -> vec3   # shorthand for  vec3(mat * vec4(vec,1))
hmul(mat3, vec2) -> vec2   # shorthand for vec2(mat * vec3(vec,1))
hmul(mat2, vec1) -> vec1   # etc

Do you think it could play well with the philosophy of pyglm ?

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions