Open harrisi opened 4 months ago
That's exactly up the alley of this project--and as a maintainer on Scenic, I'm very aware of how it might help there. :)
If you can put together a list of things (similar to what you already have, maybe add some additional stuff), then I can get that plumbed in.
I also feel like a 3x4 matrix or 2x3 matrix for 2D stuff without shear could be useful. What do you think?
Awesome! I realized after the fact when I was going to ask Scenic people what they'd need from graphmath. Turns out I don't need to! :)
Here's a list of things that I've had to implement to supplement graphmath so far, for various 2D and 3D projects:
@type t :: {Vec2.t(), Vec2.t()}
)
@spec scale(mat :: t(), scalar :: number()) :: t()
@spec add(mat1 :: t(), mat2 :: t()) :: t()
@spec determinant(mat :: t()) :: float()
@spec trace(mat :: t()) :: float()
@spec determinant(mat :: t()) :: float()
@spec minor(mat :: t(), i :: integer(), j :: integer()) :: Mat22.t()
@spec cofactor(mat :: t(), i :: integer(), j :: integer()) :: float()
@spec trace(mat :: t()) :: float()
@spec determinant(mat :: t()) :: float()
@spec minor(mat :: t(), i :: integer(), j :: integer()) :: Mat33.t()
@spec cofactor(mat :: t(), i :: integer(), j :: integer()) :: float()
@spec orient(pos :: Vec3.t(), fwd :: Vec3.t(), up :: Vec3.t()) :: t()
@spec look_at(eye :: Vec3.t(), center :: Vec3.t(), up :: Vec3.t()) :: t()
@spec perspective(fov_y :: float(), aspect :: float(), near :: float(), far :: float()) :: t()
(although these should maybe be number()
s, now that I'm looking at it)@spec ortho(x_min :: float(), x_max :: float(), y_min :: float(), y_max :: float(), z_near :: float(), z_far :: float()) :: t()
(ditto about number()
, maybe)@spec multiply_vec(Mat44.t(), Vec4.t()) :: Vec4.t()
which returns a new Vec4
with the dot product of each row by the vector. I think the same thing can be achieved already with other functions though.I don't have a strong opinion on Mat34
/Mat23
. I haven't had a need for something like that yet. I don't love the non-square nature, since really you'd need Mat43
and Mat32
as well. But I suppose that's not the end of the world.
Let me know if some or all of those seem unnecessary.
Hi, thanks for graphmath! It solves a lot of problems with 3D rendering and physics simulations.
There are a few things that could be added to make this more complete for realtime 3D interactive applications, as well as 2D UIs, such as Scenic.
A few things such as
Vec4
,Mat22
, some added functions such astrace
,determinant
,look_at
,perspective
,ortho
, maybe some others, would be nice for both 3D rendering and some physics-based simulations.The main interest I have is to unify many of these common math functions into a package that something like Scenic could utilize, as well as my own projects with OpenGL rendering. I'm not sure if this is outside the scope of this project, but if it seems it would fit, I'd be happy to open a (or some) PRs.