Shapes API accepts both vec3 and number coords

This commit is contained in:
Josip Miskovic 2020-05-09 12:10:28 +03:00
parent 2d6f7802f1
commit e2d1b33eed
3 changed files with 16 additions and 22 deletions

View File

@ -113,10 +113,9 @@ static int l_lovrShapeGetPosition(lua_State* L) {
static int l_lovrShapeSetPosition(lua_State* L) { static int l_lovrShapeSetPosition(lua_State* L) {
Shape* shape = luax_checkshape(L, 1); Shape* shape = luax_checkshape(L, 1);
float x = luax_checkfloat(L, 2); float position[4];
float y = luax_checkfloat(L, 3); luax_readvec3(L, 2, position, NULL);
float z = luax_checkfloat(L, 4); lovrShapeSetPosition(shape, position[0], position[1], position[2]);
lovrShapeSetPosition(shape, x, y, z);
return 0; return 0;
} }
@ -133,11 +132,9 @@ static int l_lovrShapeGetOrientation(lua_State* L) {
static int l_lovrShapeSetOrientation(lua_State* L) { static int l_lovrShapeSetOrientation(lua_State* L) {
Shape* shape = luax_checkshape(L, 1); Shape* shape = luax_checkshape(L, 1);
float angle = luax_checkfloat(L, 2); float orientation[4];
float x = luax_checkfloat(L, 3); luax_readquat(L, 2, orientation, NULL);
float y = luax_checkfloat(L, 4); lovrShapeSetOrientation(shape, orientation);
float z = luax_checkfloat(L, 5);
lovrShapeSetOrientation(shape, angle, x, y, z);
return 0; return 0;
} }
@ -218,10 +215,9 @@ static int l_lovrBoxShapeGetDimensions(lua_State* L) {
static int l_lovrBoxShapeSetDimensions(lua_State* L) { static int l_lovrBoxShapeSetDimensions(lua_State* L) {
BoxShape* box = luax_checktype(L, 1, BoxShape); BoxShape* box = luax_checktype(L, 1, BoxShape);
float x = luax_checkfloat(L, 2); float size[4];
float y = luax_checkfloat(L, 3); luax_readscale(L, 2, size, 3, NULL);
float z = luax_checkfloat(L, 4); lovrBoxShapeSetDimensions(box, size[0], size[1], size[2]);
lovrBoxShapeSetDimensions(box, x, y, z);
return 0; return 0;
} }

View File

@ -1,5 +1,4 @@
#include "physics.h" #include "physics.h"
#include "core/maf.h"
#include "core/ref.h" #include "core/ref.h"
#include "core/util.h" #include "core/util.h"
#include <stdlib.h> #include <stdlib.h>
@ -525,8 +524,8 @@ void lovrColliderGetOrientation(Collider* collider, float* angle, float* x, floa
quat_getAngleAxis(quaternion, angle, x, y, z); quat_getAngleAxis(quaternion, angle, x, y, z);
} }
void lovrColliderSetOrientation(Collider* collider, float* quaternion) { void lovrColliderSetOrientation(Collider* collider, quat orientation) {
float q[4] = { quaternion[3], quaternion[0], quaternion[1], quaternion[2] }; float q[4] = { orientation[3], orientation[0], orientation[1], orientation[2] };
dBodySetQuaternion(collider->body, q); dBodySetQuaternion(collider->body, q);
} }
@ -728,10 +727,8 @@ void lovrShapeGetOrientation(Shape* shape, float* angle, float* x, float* y, flo
quat_getAngleAxis(quaternion, angle, x, y, z); quat_getAngleAxis(quaternion, angle, x, y, z);
} }
void lovrShapeSetOrientation(Shape* shape, float angle, float x, float y, float z) { void lovrShapeSetOrientation(Shape* shape, quat orientation) {
float quaternion[4]; float q[4] = { orientation[3], orientation[0], orientation[1], orientation[2] };
quat_fromAngleAxis(quaternion, angle, x, y, z);
float q[4] = { quaternion[3], quaternion[0], quaternion[1], quaternion[2] };
dGeomSetOffsetQuaternion(shape->id, q); dGeomSetOffsetQuaternion(shape->id, q);
} }

View File

@ -1,4 +1,5 @@
#include "core/arr.h" #include "core/arr.h"
#include "core/maf.h"
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <ode/ode.h> #include <ode/ode.h>
@ -140,7 +141,7 @@ void lovrColliderSetMassData(Collider* collider, float cx, float cy, float cz, f
void lovrColliderGetPosition(Collider* collider, float* x, float* y, float* z); void lovrColliderGetPosition(Collider* collider, float* x, float* y, float* z);
void lovrColliderSetPosition(Collider* collider, float x, float y, float z); void lovrColliderSetPosition(Collider* collider, float x, float y, float z);
void lovrColliderGetOrientation(Collider* collider, float* angle, float* x, float* y, float* z); void lovrColliderGetOrientation(Collider* collider, float* angle, float* x, float* y, float* z);
void lovrColliderSetOrientation(Collider* collider, float* quaternion); void lovrColliderSetOrientation(Collider* collider, quat orientation);
void lovrColliderGetLinearVelocity(Collider* collider, float* x, float* y, float* z); void lovrColliderGetLinearVelocity(Collider* collider, float* x, float* y, float* z);
void lovrColliderSetLinearVelocity(Collider* collider, float x, float y, float z); void lovrColliderSetLinearVelocity(Collider* collider, float x, float y, float z);
void lovrColliderGetAngularVelocity(Collider* collider, float* x, float* y, float* z); void lovrColliderGetAngularVelocity(Collider* collider, float* x, float* y, float* z);
@ -174,7 +175,7 @@ void lovrShapeSetUserData(Shape* shape, void* data);
void lovrShapeGetPosition(Shape* shape, float* x, float* y, float* z); void lovrShapeGetPosition(Shape* shape, float* x, float* y, float* z);
void lovrShapeSetPosition(Shape* shape, float x, float y, float z); void lovrShapeSetPosition(Shape* shape, float x, float y, float z);
void lovrShapeGetOrientation(Shape* shape, float* angle, float* x, float* y, float* z); void lovrShapeGetOrientation(Shape* shape, float* angle, float* x, float* y, float* z);
void lovrShapeSetOrientation(Shape* shape, float angle, float x, float y, float z); void lovrShapeSetOrientation(Shape* shape, quat orientation);
void lovrShapeGetMass(Shape* shape, float density, float* cx, float* cy, float* cz, float* mass, float inertia[6]); void lovrShapeGetMass(Shape* shape, float density, float* cx, float* cy, float* cz, float* mass, float inertia[6]);
void lovrShapeGetAABB(Shape* shape, float aabb[6]); void lovrShapeGetAABB(Shape* shape, float aabb[6]);