From 3aa41bedd85b644d230b4c95a855eeb4ab93a05d Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 19 Oct 2009 17:25:51 +0000 Subject: [PATCH] added ag::object::setRotation() git-svn-id: svn://anubis/anaglym/trunk@109 99a6e188-d820-4881-8870-2d33a10e2619 --- Engine.h | 4 ++++ ag.cc | 32 ++++++++++++++++++++++++++++---- ag.h | 1 + 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Engine.h b/Engine.h index 0f26103..f69d5dd 100644 --- a/Engine.h +++ b/Engine.h @@ -51,6 +51,10 @@ class Engine { m_ode_object->addRelTorque(fx, fy, fz); } + void setRotation(dReal x, dReal y, dReal z) + { + m_ode_object->setRotation(x, y, z); + } void draw(); diff --git a/ag.cc b/ag.cc index 32401b4..9ceea78 100644 --- a/ag.cc +++ b/ag.cc @@ -117,6 +117,8 @@ namespace ag lua_setfield(L, -2, "setPosition"); lua_pushcfunction(L, object::getPosition); lua_setfield(L, -2, "getPosition"); + lua_pushcfunction(L, object::setRotation); + lua_setfield(L, -2, "setRotation"); lua_pushcfunction(L, object::clone); lua_setfield(L, -2, "clone"); lua_pushcfunction(L, object::destroy); @@ -305,10 +307,9 @@ namespace ag double position[3]; for (int i = 0; i < 3; i++) { - if (lua_isnumber(L, i + 2)) - { - position[i] = lua_tonumber(L, i + 2); - } + position[i] = (lua_isnumber(L, i + 2)) + ? lua_tonumber(L, i + 2) + : 0.0; } obj->setPosition(position[0], position[1], position[2]); } @@ -336,6 +337,29 @@ namespace ag return 0; } + int setRotation(lua_State * L) + { + int argc = lua_gettop(L); + + if (argc == 4) + { + Engine::Object * obj = getObject(L, 1); + if (obj != NULL) + { + double rot[3]; + for (int i = 0; i < 3; i++) + { + rot[i] = (lua_isnumber(L, i + 2)) + ? lua_tonumber(L, i + 2) + : 0.0; + } + obj->setRotation(rot[0], rot[1], rot[2]); + } + } + + return 0; + } + int clone(lua_State * L) { int argc = lua_gettop(L); diff --git a/ag.h b/ag.h index f7a36d3..409a63e 100644 --- a/ag.h +++ b/ag.h @@ -29,6 +29,7 @@ namespace ag int draw(lua_State * L); int setPosition(lua_State * L); int getPosition(lua_State * L); + int setRotation(lua_State * L); int clone(lua_State * L); int destroy(lua_State * L); int setVisible(lua_State * L);