mirror of https://github.com/bjornbytes/lovr.git
Body:getOrientation; Body:setOrientation;
This commit is contained in:
parent
eca490adfd
commit
798b09eb0d
|
@ -20,8 +20,31 @@ int l_lovrBodySetPosition(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrBodyGetOrientation(lua_State* L) {
|
||||
Body* body = luax_checktype(L, 1, Body);
|
||||
float angle, x, y, z;
|
||||
lovrBodyGetOrientation(body, &angle, &x, &y, &z);
|
||||
lua_pushnumber(L, angle);
|
||||
lua_pushnumber(L, x);
|
||||
lua_pushnumber(L, y);
|
||||
lua_pushnumber(L, z);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int l_lovrBodySetOrientation(lua_State* L) {
|
||||
Body* body = luax_checktype(L, 1, Body);
|
||||
float angle = luaL_checknumber(L, 2);
|
||||
float x = luaL_checknumber(L, 3);
|
||||
float y = luaL_checknumber(L, 4);
|
||||
float z = luaL_checknumber(L, 5);
|
||||
lovrBodySetOrientation(body, angle, x, y, z);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg lovrBody[] = {
|
||||
{ "getPosition", l_lovrBodyGetPosition },
|
||||
{ "setPosition", l_lovrBodySetPosition },
|
||||
{ "getOrientation", l_lovrBodyGetOrientation },
|
||||
{ "setOrientation", l_lovrBodySetOrientation },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "physics.h"
|
||||
#include "math/quat.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void lovrPhysicsInit() {
|
||||
|
@ -104,3 +105,16 @@ void lovrBodyGetPosition(Body* body, float* x, float* y, float* z) {
|
|||
void lovrBodySetPosition(Body* body, float x, float y, float z) {
|
||||
dBodySetPosition(body->id, x, y, z);
|
||||
}
|
||||
|
||||
void lovrBodyGetOrientation(Body* body, float* angle, float* x, float* y, float* z) {
|
||||
const dReal* q = dBodyGetQuaternion(body->id);
|
||||
float quaternion[4] = { q[0], q[1], q[2], q[3] };
|
||||
quat_getAngleAxis(quaternion, angle, x, y, z);
|
||||
}
|
||||
|
||||
void lovrBodySetOrientation(Body* body, float angle, float x, float y, float z) {
|
||||
float axis[3] = { x, y, z };
|
||||
float quaternion[4];
|
||||
quat_fromAngleAxis(quaternion, angle, axis);
|
||||
dBodySetQuaternion(body->id, quaternion);
|
||||
}
|
||||
|
|
|
@ -31,3 +31,5 @@ Body* lovrBodyCreate();
|
|||
void lovrBodyDestroy(const Ref* ref);
|
||||
void lovrBodyGetPosition(Body* body, float* x, float* y, float* z);
|
||||
void lovrBodySetPosition(Body* body, float x, float y, float z);
|
||||
void lovrBodyGetOrientation(Body* body, float* angle, float* x, float* y, float* z);
|
||||
void lovrBodySetOrientation(Body* body, float angle, float x, float y, float z);
|
||||
|
|
Loading…
Reference in New Issue