lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]





On Wed, Jun 11, 2014 at 1:52 PM, Lars Ruoff <lars.ruoff@gmail.com> wrote:
Thanks Roland and all,

i have already a solution on the C(++) side. As i said, it's basically
struct VECTOR {
FLOAT x;
FLOAT y;
};
with some methods around it for utility functions.

Would it be better to expose those functions to Lua or use a Lua-side library?
The Lua scripts would need to get some vectors in tables, then do some calculation with it and return a bunch of other vectors.

And concerning my other initial question, would it feel "right" for a Lua coder to handle a 2D vector as a Lua table with elements "x" and "y"?




On Wed, Jun 11, 2014 at 8:18 PM, Roland <roland.yonaba@gmail.com> wrote:
Hi Lars,

I don't know if you are looking for a solution on the C-side, but I remember
I have some implementations of vector classes in pure Lua. They might not be
the best, but just quick modules I have written as part of some personal
projects.
See  vec3.lua
<https://github.com/Yonaba/smallpt-lua/blob/e1e6831394229a6780d5a7c0d428e102e97fcf2f/core/vec3.lua>
(used in Lua port of Smallpt raytracer) and  vector.lua
<https://github.com/Yonaba/character-physics-demo/blob/5689eabec224e572c686a0fc0e72360e11ba9a32/vector.lua>
(2d vectors used in a simulation of steering behaviors).
There is also this quite complete and clean module for 2d vectors, which is
part of a larger set of utilities, named HUMP. See  hump.vector
<https://github.com/vrld/hump/blob/master/vector.lua>  .
And last,  lua-vec <https://code.google.com/p/lua-vec/>  . I haven't tested
this out, though,  but the API looks quite complete.




--
View this message in context: http://lua.2524044.n2.nabble.com/2D-vectors-tp7660586p7660623.html
Sent from the Lua-l mailing list archive at Nabble.com.


As a consumer of this kind of stuff (as opposed to a domain expert):

I'd say it'd feel more natural to have it be { x, y } as opposed to {x = val, y = val}

you can also make a metatable for this so that x and y work, as well but I wouldn't do that. It's fine to represent a tuple as indexed values, as opposed to named pairs.

-Andrew