Commit Graph

25 Commits

Author SHA1 Message Date
bjorn 342f92940e Add :equals method to vector objects; 2022-03-25 16:05:38 -07:00
bjorn 2da18d419b mv util src; 2022-03-22 00:13:38 -07:00
bjorn bbd502153a Formatting; 2022-03-15 16:33:53 -07:00
bjorn fdfcb5539f Merge branch 'master' into dev 2022-03-14 13:19:59 -07:00
bjorn 1e91eea9b0 Fix Mat4:__mul(Vec3);
The matrix was transforming the input vector, not the new vector.
2022-03-10 07:41:44 -08:00
Josip Miskovic ef41e06fc9 Add Vec2/3/4:angle(other)
Functions to calculate the angle between two vectors. Angle is always
positive. Implementations give the same result as this Lua code:

```lua
local function lua_angle(v1, v2)
  return math.acos(v1:dot(v2) / (v1:length() * v2:length()))
end
```

If either vector is zero-length, the pi/2 value is returned.
2022-03-03 14:12:56 -08:00
bjorn 20e4567bd6 Merge branch 'master' into dev 2021-12-20 17:12:39 +02:00
Josip Miskovic 015a2ed69c Accept number values in Vec2/3/4 operations
Vector methods are extended to receive vectors as individual numbers
for each of x,y,z,w component. The vector objects are still supported
as well.

Previously only single value scalar was supported. This change maintains
backward compatibility.

```
v = vec3():add( 1, 2, 3 )          -- both do the same
v = vec3():add( vec3(1, 2, 3) )    _/

v = vec4():mul( 2 )            -- x component is a default for y, z
v = vec4():mul( 2, 2, 2, 2 )   _/

v = vec2():lerp( 2, 2, 0.5 )        -- in lerp, dot, cross, distance
v = vec2():lerp( vec2(2, 2), 0.5 )  _/   all components are mandatory
```
2021-09-07 14:00:59 -07:00
bjorn fdb8a2423c Merge branch 'master' into dev 2021-07-10 09:44:03 -07:00
bjorn 526e06d445 Fix mat4 corruption when using vectors;
We correct m[15] to 1.f too late, by that time the undefined 4th
component of the vec3 could have corrupted the rotation/scale.
2021-06-16 16:55:19 -06:00
bjorn bf627e1e3e Allow passing vec2 as scale argument;
Useful for planes.
2021-06-01 09:59:38 -06:00
bjorn ca4b7d01bc Allow passing vec2 as scale argument;
Useful for planes.
2021-05-31 15:05:13 -06:00
bjorn 159243190b rm some unnecessary includes; 2021-04-20 20:08:30 -06:00
bjorn 2b94bcb46e Add quat_identity; 2021-04-03 18:38:23 -06:00
bjorn 2d43620d3c rm LOVR_ALIGN;
It isn't very portable, the effects aren't significant.
2021-03-15 18:56:02 -06:00
bjorn e63099ba6a Flatten api.h; 2021-03-15 18:54:27 -06:00
bjorn 72284c2c5b Merge branch 'master' into dev 2021-02-12 08:16:36 -07:00
Josip Miskovic 944a6029f0 Add mat4:targetAt and modify the mat4:lookAt
lookAt() returns view matrix that can be used to transform the camera
perspective. target() returns model matrix that is used to change
model transform. Results are matrix inversions of one another. Now both
functions exist it is possible to use right one and avoid extra matrix
inversion.
2021-01-22 16:01:27 +01:00
bjorn 3bc2c00b79 api doesn't include util; 2020-12-25 12:50:26 -07:00
bjornbytes 80a33c0544 mat4_multiply -> mat4_mul;
quat_mul vs. mat4_multiply is inconsistent.  Going with mul over
multiply is consistent with vec3_sub and Lua's __mul metamethod.
2020-11-21 14:32:59 -07:00
bjorn 8973730d8a openvr_getSkeleton;
Untested
2020-08-22 13:33:06 -06:00
bjorn ec257b179f Support Lua 5.2, 5.3, 5.4; 2020-08-19 13:12:57 -06:00
Josip Miskovic c314824304 Initialize vec3 from mat4
Rotation and scaling is lost, only position is extracted from mat4.
2020-06-28 11:49:43 +03:00
bjorn 8c429e89ac Fix -Wshadow; 2020-01-23 11:18:04 -08:00
bjorn c9b1f257bf api: try new file naming convention; Tupfile: cleanup;
I assume full responsibility for any catastrophes this causes.
2019-12-31 19:31:44 -08:00
Renamed from src/api/l_vectors.c (Browse further)