Shape:getOrientation; Shape:setOrientation;

This commit is contained in:
bjorn 2017-05-16 12:48:01 -06:00
parent 327022461e
commit 73ec387545
3 changed files with 37 additions and 3 deletions

View File

@ -87,3 +87,24 @@ int l_lovrShapeSetPosition(lua_State* L) {
lovrShapeSetPosition(shape, x, y, z);
return 0;
}
int l_lovrShapeGetOrientation(lua_State* L) {
Shape* shape = luax_checktypeof(L, 1, Shape);
float angle, x, y, z;
lovrShapeGetOrientation(shape, &angle, &x, &y, &z);
lua_pushnumber(L, angle);
lua_pushnumber(L, x);
lua_pushnumber(L, y);
lua_pushnumber(L, z);
return 4;
}
int l_lovrShapeSetOrientation(lua_State* L) {
Shape* shape = luax_checktypeof(L, 1, Shape);
float angle = luaL_checknumber(L, 1);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
lovrShapeSetOrientation(shape, angle, x, y, z);
return 0;
}

View File

@ -113,10 +113,9 @@ void lovrBodyGetOrientation(Body* body, float* angle, float* x, float* y, float*
}
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);
float axis[3] = { x, y, z };
dBodySetQuaternion(body->id, quat_fromAngleAxis(quaternion, angle, axis));
}
void lovrBodyGetLinearVelocity(Body* body, float* x, float* y, float* z) {
@ -314,3 +313,15 @@ void lovrShapeGetPosition(Shape* shape, float* x, float* y, float* z) {
void lovrShapeSetPosition(Shape* shape, float x, float y, float z) {
dGeomSetOffsetPosition(shape->id, x, y, z);
}
void lovrShapeGetOrientation(Shape* shape, float* angle, float* x, float* y, float* z) {
float quaternion[4];
dGeomGetOffsetQuaternion(shape->id, quaternion);
quat_getAngleAxis(quaternion, angle, x, y, z);
}
void lovrShapeSetOrientation(Shape* shape, float angle, float x, float y, float z) {
float quaternion[4];
float axis[3] = { x, y, z };
dGeomSetOffsetQuaternion(shape->id, quat_fromAngleAxis(quaternion, angle, axis));
}

View File

@ -84,3 +84,5 @@ void* lovrShapeGetUserData(Shape* shape);
void lovrShapeSetUserData(Shape* shape, void* data);
void lovrShapeGetPosition(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 lovrShapeSetOrientation(Shape* shape, float angle, float x, float y, float z);