electronstudio / raylib-python-cffi

Python CFFI bindings for Raylib
http://electronstudio.github.io/raylib-python-cffi
Eclipse Public License 2.0
142 stars 29 forks source link

[request] include raymath.h #19

Closed chriscamacho closed 2 years ago

chriscamacho commented 3 years ago

I got a fair way into porting raymath.h to python, when I noticed that its all messing with ffi types an awful lot, and probably wasting my time....

with helper functions like

def Vector2New(x:float, y:float, z:float):
    return ffi.new("struct Vector2 *",[ x, y, z])

and a submodule for raymath RAYMATH_STANDALONE ? (or will this just drag in Vector2 again...)

then most of the "scary" ffi.new stuff goes away!

the remaining issue I'm not over worried about.....

only issue is accessing members of the struct

is there anyway to automagically turn this

v3[0].z = 1.5

into

v3.z = 1.5
chriscamacho commented 3 years ago

the i suppose you'd need

v3.toPtr()

and a wrapper that knows when it needs a pointer!

electronstudio commented 3 years ago

There's already helper functions in pyray.py to create 'Vector2','Vector3','Vector4','Camera2D', 'Camera3D', 'Quaternion', 'Color', 'Rectangle' structs. And I just added code so that functions that require pointers automatically create pointers for their arguments.

chriscamacho commented 3 years ago

it would be nice to have the functions!

chriscamacho commented 3 years ago

here's my take on raymath, quaternion functions still to do.

warning ! contains sharp edges! you need to know when you need to dereference ...

I still do wonder if it wouldn't be worth including raymath.h in the wrapper...

https://gist.github.com/chriscamacho/63a9427deca505634f162e882e369172

electronstudio commented 2 years ago

raymath.h is a pain to include because it doesn't have any function declarations.

Compare to physac.h... although it's an h file, inside it you have declaration void InitPhysics(void); and then you have a separate definition with a function body void InitPhysics(void) { ... }

raymath only has the definitions, so we would need to generate the declarations ourselves.

electronstudio commented 2 years ago

raymath added