63 Commits

Author SHA1 Message Date
Colby Klein
c84a8e07c0 add mat4.mul_vec3_perspective, fix doc typo 2022-04-21 12:12:02 -07:00
Colby Klein
f11cea9588 fix whitespace 2022-04-21 11:25:58 -07:00
Colby Klein
9f57a1a939 remove unused a parameter from mat4.look_at 2022-04-21 11:22:55 -07:00
shakesoda
3b90354910
Merge pull request #63 from semyon422/master
Minor fixes
2022-04-21 11:08:52 -07:00
shakesoda
ab0132a6ac
Merge pull request #66 from aki-cat/master
Implement scale to mat4.from_transform method
2022-04-20 15:56:31 -07:00
David Briscoe
c26cc1a508 Include offending type in precondition failure msg
Output the type that was incorrect to make it more obvious what the user
is doing wrong without them adding logging.

To avoid string building during lots of vector math, introduced a
private precond module that only builds the strings when an error
occurs. It uses error() to put the resulting error message at the caller
to cpml.

Before:

  lua: ~/cpml/modules/vec2.lua:52: new: Wrong argument type for x (<number> expected)
  lua: ~/cpml/modules/vec2.lua:424: __add: Wrong argument type for right hand operand. (<cpml.vec2> expected)

  example stack traceback:
  	[C]: in function 'assert'
  	~/cpml/modules/vec2.lua:424: in metamethod '__add'
  	test_cpml.lua:32: in main chunk
  	[C]: in ?

After:

  lua: test_cpml.lua:31: new: Wrong argument type for x: string (<number> expected)
  lua: test_cpml.lua:32: __add: Wrong argument type 'string' for right hand operand. (<cpml.vec2> expected)

  example stack traceback:
  	[C]: in function 'error'
  	~/cpml/modules/_private_precond.lua:13: in function 'modules._private_precond.assert'
  	~/cpml/modules/vec2.lua:425: in metamethod '__add'
  	test_cpml.lua:32: in main chunk
  	[C]: in ?

The tracebacks are longer, but the initial error is at the location of
the mistake and the output includes the input type.
2022-03-27 09:56:15 -07:00
shakesoda
c50d292cb6
Merge pull request #69 from idbrii/mat-cleanup
mat4: minor cleanup of globals and unused variables
2022-03-27 03:48:54 -07:00
David Briscoe
320f895759 mat4: minor cleanup of globals and unused variables
forward, side, new_up are unused but are shadowed in many functions.
Doesn't seem like they're intended to be used.

No reason for variables in CreateNDCScaleAndOffsetFromFov to be global.
Don't try running this change, but I'm just making them local.
2022-03-26 23:35:04 -07:00
David Briscoe
29954aa60e vec: Add nan checking functions
Add:
* vec2.has_nan + test
* vec3.has_nan + test
* quat.has_nan
* mat4.has_nan
* utils.is_nan + test
2022-03-26 23:33:13 -07:00
aki-cat
d7c257387d Implement scale to mat4.from_transform method 2021-12-10 00:31:57 -03:00
semyon422
f22c9e09cc Fix incorrect out of mat4.invert when out = a 2021-08-11 18:12:58 +05:00
semyon422
54d9a578e1 Use local variables 2021-08-11 17:08:30 +05:00
mcclure
1000f1d6e5
Merge pull request #48 from mcclure/mat4-reverse
Consistency: mat4 multiply in wrong order
2020-05-03 13:13:11 -04:00
mcclure
5601094c04
Merge pull request #49 from mcclure/vec4_cols
Column version of to_vec4s (to_vec4s_cols)
2020-05-03 12:37:22 -04:00
mcc
13cc666232 Column version of to_vec4s (to_vec4s_cols) for issue #32 2019-11-29 22:24:47 -05:00
mcc
d51a930e4a Consistency (issue #33): mat4 multiply in wrong order
This is a breaking change.
2019-11-29 22:12:22 -05:00
mcc
a86935a39b Allow ffi.metatype to fail so that "busted" unit tests work
On Github we run unit tests inside "busted". At the start of each test "busted" does some sort of trick (clearing package.loaded)? Which causes "require" to run again for all lua files. This breaks ffi.metatype with error "cannot change a protected metatable" if it is called twice with a single type name, since this is true global state. To work around this this patch wraps ffi.metatype calls in a xpcall() so that failure is silently ignored.
2019-11-29 21:13:30 -05:00
mcc
7fa1785469 Fix failing tests; this involves changing 2 bad tests and 1 bad behavior:
- vec2 to_polar/from_cartesian tests were testing for equality rather than using an epsilon.
- bound2.contains had two tests that were plain wrong.
- While I'm fixing the bounds test, bound2.contains and bound3.contains probably ought to test their own min and max values for inclusion.
- The implementation of mat4.look_at appears to be wrong. The final column was being set to 0,0,0,1 which comparing against other implementations does not seem to be correct. My replacement code is modeled on the method used in mat4x4_look_at() in linmath.h in GLFW, which says it's a reimplementation on the method from gluLookAt(). With this change the test passes as originally written.
2019-11-29 17:16:20 -05:00
bjorn
2ac5321bdf mat4:reflect; 2018-01-05 22:08:11 -08:00
Colby Klein
5f9fa96e10 fix typo 2017-11-17 09:52:58 -08:00
Colby Klein
24bcae96e3 probably fix look_at 2017-11-17 09:48:22 -08:00
Colby Klein
b122e4d726 fix typo 2017-03-29 05:32:16 -07:00
Colby Klein
3a18ed0f8c temporarily revert mat4.lua due to bugs 2016-12-22 11:17:58 -08:00
Colby Klein
736ef2fcf8 fix doc comment for mat4.look_at 2016-12-15 16:44:09 -08:00
karai17
08b23e394b Updated tests, fixed couple bugs 2016-12-15 19:57:31 -04:00
karai17
a7f9247838 Unfactored the rest of cpml. Completely untested (all tests are broken) 2016-12-15 04:34:46 -04:00
Colby Klein
ff7cc186e7 add mat4 * vec3 (implicit w=1) 2016-12-13 15:09:38 -08:00
karai17
799e1607bc Updated to work outside of a sanitized environment. 2016-08-14 03:36:36 -03:00
karai17
dc31605db6 Fixed mat4.look_at 2016-07-24 23:42:44 -03:00
karai17
ebae3a1fce Updated mat4 LDocs 2016-07-24 22:16:04 -03:00
karai17
6daa845533 No unnecessary lines! 2016-07-24 11:48:58 -03:00
karai17
3c3eebd66f Minor tweak 2016-07-24 11:39:36 -03:00
karai17
96a63ce581 Added a few more mat4 tests 2016-07-24 11:35:48 -03:00
karai17
c4fabe7f19 Made the tests less bad 2016-07-24 10:04:29 -03:00
karai17
2cb5d0970d Added to_frustum test 2016-07-24 04:43:06 -03:00
karai17
375f748c1f FFI'd color 2016-07-23 23:16:10 -03:00
karai17
864ac736de Reimplemented mat4 ffi (thanks @EntranceJew!)
Resolves issue #17
2016-07-23 22:46:09 -03:00
karai17
481825cba4 What ARE birds?
We just don't know.
2016-07-23 05:21:03 -03:00
karai17
fbf329264d Blood. Sweat. Tears. Mostly blood. And sweat. And tears. 2016-07-23 03:23:06 -03:00
karai17
d34cca315f Removed ffi from mat4, it caused a lot of problems and didn't work. 2016-07-22 17:13:11 -03:00
karai17
5f7a7f29fa Added quaternion tests
* Fixed an issue with is_quat, is_vec3, is_vec2, and is_mat4 methods
* Fixed a minor issue with local variables being declared too late
2016-07-21 20:04:32 -03:00
karai17
2950352ac8 Updated color module, etc. 2016-07-20 22:17:25 -03:00
karai17
a57673dcaf Added frustum and other intersect functions 2016-07-20 20:49:28 -03:00
karai17
f83b60e1e5 Fixed transforms multiplying in the wrong order 2016-07-20 18:36:04 -03:00
karai17
2aa0e7fcb6 Cleaned up internal code to be less verbose 2016-07-20 18:24:54 -03:00
karai17
d1a2c8c94b fixed mat4.__mul 2016-07-20 00:09:17 -03:00
karai17
bff981aa70 typo 2016-07-20 00:08:34 -03:00
karai17
5bee88b943 Fixed mat4.project and mat4.unproject 2016-07-20 00:07:49 -03:00
karai17
4f9bc17bf4 Refactored mat4
Did some tidying up on quat, vec2, vec3, and utils
2016-07-19 23:55:21 -03:00
karai17
f9d31b20fb Fixed a typo 2016-07-18 06:21:43 -03:00