added initial support for reference objects
git-svn-id: svn://anubis/anaglym/trunk@241 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
9d9c16f3ad
commit
9058dcfefc
4
.todo
4
.todo
@ -1 +1,3 @@
|
||||
- support reference objects
|
||||
change bowling demo to use reference objects
|
||||
update documentation for loadModel*(), create*()
|
||||
add documentation for motors
|
||||
|
104
Engine.cc
104
Engine.cc
@ -262,19 +262,20 @@ bool Engine::fileExists(const string & path)
|
||||
return false;
|
||||
}
|
||||
|
||||
int Engine::addObject(WFObj * obj, bool is_static, float scale)
|
||||
int Engine::addObject(WFObj * obj, bool is_static, bool is_reference,
|
||||
float scale)
|
||||
{
|
||||
int id = m_next_object_index++;
|
||||
Object * o = new Object(is_static, m_world, obj, scale);
|
||||
Object * o = new Object(is_static, is_reference, m_world, obj, scale);
|
||||
m_objects[id] = o;
|
||||
return id;
|
||||
}
|
||||
|
||||
int Engine::addObject(bool is_static, OdeWorld::GeomType geom_type,
|
||||
refptr< vector<float> > args)
|
||||
int Engine::addObject(bool is_static, bool is_reference,
|
||||
OdeWorld::GeomType geom_type, refptr< vector<float> > args)
|
||||
{
|
||||
int id = m_next_object_index++;
|
||||
Object * o = new Object(is_static, m_world, geom_type, args);
|
||||
Object * o = new Object(is_static, is_reference, m_world, geom_type, args);
|
||||
m_objects[id] = o;
|
||||
return id;
|
||||
}
|
||||
@ -514,7 +515,8 @@ int Engine::clearEventHandler(lua_State * L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Engine::loadModel(const string & name, bool static_data, float scale)
|
||||
int Engine::loadModel(const string & name, bool is_static, bool is_reference,
|
||||
float scale)
|
||||
{
|
||||
size_t pos = name.find_first_not_of(FILENAME_SAFE_CHARS);
|
||||
if (pos == string::npos)
|
||||
@ -526,7 +528,7 @@ int Engine::loadModel(const string & name, bool static_data, float scale)
|
||||
|
||||
if (obj->load(model_path))
|
||||
{
|
||||
int id = addObject(obj, static_data, scale);
|
||||
int id = addObject(obj, is_static, is_reference, scale);
|
||||
Engine::Object * engine_obj = getObject(id);
|
||||
if (engine_obj != NULL)
|
||||
{
|
||||
@ -1074,10 +1076,21 @@ void Engine::drawObjects()
|
||||
|
||||
/******** Engine::Object functions ********/
|
||||
|
||||
Engine::Object::Object(bool is_static, OdeWorld & world, WFObj * obj,
|
||||
float scale)
|
||||
/* used for objects loaded directly from model files */
|
||||
Engine::Object::Object(bool is_static, bool is_reference,
|
||||
OdeWorld & world, WFObj * obj, float scale)
|
||||
: m_world(world)
|
||||
{
|
||||
m_is_reference = is_reference;
|
||||
if (m_is_reference)
|
||||
{
|
||||
m_ode_object = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ode_object = world.createObject(is_static, scale);
|
||||
}
|
||||
m_is_static = is_static;
|
||||
m_display_list = obj->render();
|
||||
const float * obj_aabb = obj->getAABB();
|
||||
for (int i = 0; i < 6; i++)
|
||||
@ -1090,18 +1103,27 @@ Engine::Object::Object(bool is_static, OdeWorld & world, WFObj * obj,
|
||||
m_is_managed = false;
|
||||
}
|
||||
|
||||
Engine::Object::Object(bool is_static, OdeWorld & world,
|
||||
/* used for "managed" objects with one geom */
|
||||
Engine::Object::Object(bool is_static, bool is_reference, OdeWorld & world,
|
||||
OdeWorld::GeomType geom_type,
|
||||
refptr< std::vector<float> > args)
|
||||
: m_world(world)
|
||||
{
|
||||
m_is_reference = is_reference;
|
||||
m_is_static = geom_type == OdeWorld::PLANE ? false : is_static;
|
||||
m_is_visible = true;
|
||||
m_scale = 1.0f;
|
||||
m_is_scaled = false;
|
||||
m_display_list = 0;
|
||||
m_display_list_refcnt = NULL;
|
||||
m_ode_object = world.createObject(
|
||||
geom_type == OdeWorld::PLANE ? false : is_static,
|
||||
m_scale);
|
||||
if (m_is_reference)
|
||||
{
|
||||
m_ode_object = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ode_object = world.createObject(m_is_static, m_scale);
|
||||
}
|
||||
m_is_managed = true;
|
||||
m_geom_type = geom_type;
|
||||
m_args = args;
|
||||
@ -1110,12 +1132,19 @@ Engine::Object::Object(bool is_static, OdeWorld & world,
|
||||
m_texture = 0;
|
||||
m_texture_scale = 1.0f;
|
||||
createManagedObject();
|
||||
render();
|
||||
}
|
||||
|
||||
/* used to clone objects */
|
||||
Engine::Object::Object(const Engine::Object & orig)
|
||||
: m_world(orig.m_world)
|
||||
{
|
||||
m_is_reference = false;
|
||||
m_is_visible = orig.m_is_visible;
|
||||
m_ode_object = new OdeWorld::Object(*orig.m_ode_object);
|
||||
m_is_static = orig.m_is_static;
|
||||
m_scale = orig.m_scale;
|
||||
m_is_scaled = orig.m_is_scaled;
|
||||
m_phy = orig.m_phy;
|
||||
m_is_managed = orig.m_is_managed;
|
||||
if (m_is_managed)
|
||||
m_display_list = 0;
|
||||
@ -1124,20 +1153,31 @@ Engine::Object::Object(const Engine::Object & orig)
|
||||
m_display_list_refcnt = orig.m_display_list_refcnt;
|
||||
if (m_display_list_refcnt != NULL)
|
||||
(*m_display_list_refcnt)++;
|
||||
m_scale = orig.m_scale;
|
||||
m_is_scaled = orig.m_is_scaled;
|
||||
m_geom_type = orig.m_geom_type;
|
||||
m_args = orig.m_args;
|
||||
for (int i = 0; i < 4; i++)
|
||||
m_color[i] = orig.m_color[i];
|
||||
m_texture = orig.m_texture;
|
||||
m_texture_scale = orig.m_texture_scale;
|
||||
if (orig.m_is_reference)
|
||||
{
|
||||
m_ode_object = m_world.createObject(m_is_static, m_scale);
|
||||
instantiatePhy();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ode_object = new OdeWorld::Object(*orig.m_ode_object);
|
||||
}
|
||||
if (m_is_managed)
|
||||
{
|
||||
createManagedObject();
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
Engine::Object::~Object()
|
||||
{
|
||||
if (m_ode_object != NULL)
|
||||
delete m_ode_object;
|
||||
if (m_display_list_refcnt != NULL)
|
||||
{
|
||||
@ -1162,6 +1202,7 @@ void Engine::Object::createManagedObject()
|
||||
case OdeWorld::BOX: {
|
||||
while (m_args->size() < 9)
|
||||
m_args->push_back(0);
|
||||
if (m_ode_object != NULL)
|
||||
m_ode_object->addBox(m_args);
|
||||
float aabb[6] = {-(*m_args)[0], -(*m_args)[1], -(*m_args)[2],
|
||||
(*m_args)[0], (*m_args)[1], (*m_args)[2]};
|
||||
@ -1171,6 +1212,7 @@ void Engine::Object::createManagedObject()
|
||||
case OdeWorld::SPHERE: {
|
||||
while (m_args->size() < 4)
|
||||
m_args->push_back(0);
|
||||
if (m_ode_object != NULL)
|
||||
m_ode_object->addSphere(m_args);
|
||||
float aabb[6] = {-(*m_args)[0], -(*m_args)[0], -(*m_args)[0],
|
||||
(*m_args)[0], (*m_args)[0], (*m_args)[0]};
|
||||
@ -1180,6 +1222,7 @@ void Engine::Object::createManagedObject()
|
||||
case OdeWorld::PLANE: {
|
||||
while (m_args->size() < 4 || m_args->size() == 5)
|
||||
m_args->push_back(0);
|
||||
if (m_ode_object != NULL)
|
||||
m_ode_object->addPlane(m_args);
|
||||
for (int i = 0; i < 6; i++)
|
||||
m_aabb[i] = 0.0f;
|
||||
@ -1188,6 +1231,7 @@ void Engine::Object::createManagedObject()
|
||||
case OdeWorld::CYLINDER: {
|
||||
while (m_args->size() < 8)
|
||||
m_args->push_back(0);
|
||||
if (m_ode_object != NULL)
|
||||
m_ode_object->addCylinder(m_args);
|
||||
float aabb[6] = {-(*m_args)[0], -(*m_args)[0], -(*m_args)[1],
|
||||
(*m_args)[0], (*m_args)[0], (*m_args)[1]};
|
||||
@ -1197,6 +1241,7 @@ void Engine::Object::createManagedObject()
|
||||
case OdeWorld::CAPSULE: {
|
||||
while (m_args->size() < 8)
|
||||
m_args->push_back(0);
|
||||
if (m_ode_object != NULL)
|
||||
m_ode_object->addCapsule(m_args);
|
||||
float aabb[6] = {-(*m_args)[0], -(*m_args)[0], -(*m_args)[1],
|
||||
(*m_args)[0], (*m_args)[0], (*m_args)[1]};
|
||||
@ -1204,15 +1249,21 @@ void Engine::Object::createManagedObject()
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (m_ode_object != NULL)
|
||||
{
|
||||
m_ode_object->finalize();
|
||||
}
|
||||
if (!m_is_reference)
|
||||
{
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
/* render a managed object */
|
||||
/* prerequisite: m_args->size() is big enough */
|
||||
void Engine::Object::render()
|
||||
{
|
||||
if (!m_is_managed)
|
||||
if (!m_is_managed || m_is_reference)
|
||||
return;
|
||||
GLUquadric * quad = gluNewQuadric();
|
||||
if (m_display_list <= 0)
|
||||
@ -1410,11 +1461,19 @@ void Engine::Object::render()
|
||||
|
||||
void Engine::Object::loadPhy(FileLoader * fl, const FileLoader::Path & path)
|
||||
{
|
||||
PhyObj po;
|
||||
po.load(fl, path);
|
||||
for (int i = 0, sz = po.getNumGeoms(); i < sz; i++)
|
||||
m_phy = new PhyObj();
|
||||
m_phy->load(fl, path);
|
||||
if (!m_is_managed)
|
||||
instantiatePhy();
|
||||
}
|
||||
|
||||
void Engine::Object::instantiatePhy()
|
||||
{
|
||||
if (m_ode_object != NULL && !m_is_managed && !m_phy.isNull())
|
||||
{
|
||||
refptr<PhyObj::Geom> geom = po.getGeom(i);
|
||||
for (int i = 0, sz = m_phy->getNumGeoms(); i < sz; i++)
|
||||
{
|
||||
refptr<PhyObj::Geom> geom = m_phy->getGeom(i);
|
||||
refptr< vector<float> > args = geom->getArgs();
|
||||
switch (geom->getType())
|
||||
{
|
||||
@ -1435,6 +1494,7 @@ void Engine::Object::loadPhy(FileLoader * fl, const FileLoader::Path & path)
|
||||
}
|
||||
}
|
||||
m_ode_object->finalize();
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::Object::setTexture(GLuint tex)
|
||||
@ -1448,7 +1508,7 @@ void Engine::Object::setTexture(GLuint tex)
|
||||
|
||||
void Engine::Object::draw()
|
||||
{
|
||||
if (m_is_visible)
|
||||
if (!m_is_reference && m_is_visible);
|
||||
{
|
||||
checkGLError();
|
||||
const dReal * pos = m_ode_object->getPosition();
|
||||
|
23
Engine.h
23
Engine.h
@ -13,6 +13,7 @@
|
||||
#include "Video.h"
|
||||
#include "refptr/refptr.h"
|
||||
#include "ftgl.h"
|
||||
#include "PhyObj/PhyObj.h"
|
||||
|
||||
class Engine
|
||||
{
|
||||
@ -20,10 +21,11 @@ class Engine
|
||||
class Object
|
||||
{
|
||||
public:
|
||||
Object(bool is_static, OdeWorld & world, WFObj * wfobj,
|
||||
Object(bool is_static, bool is_reference,
|
||||
OdeWorld & world, WFObj * wfobj,
|
||||
float scale = 1.0f);
|
||||
Object(bool is_static, OdeWorld & world,
|
||||
OdeWorld::GeomType geom_type,
|
||||
Object(bool is_static, bool is_reference,
|
||||
OdeWorld & world, OdeWorld::GeomType geom_type,
|
||||
refptr< std::vector<float> > args);
|
||||
Object(const Object & orig);
|
||||
~Object();
|
||||
@ -37,6 +39,7 @@ class Engine
|
||||
m_ode_object->getPosition(x, y, z);
|
||||
}
|
||||
void loadPhy(FileLoader * fl, const FileLoader::Path & path);
|
||||
void instantiatePhy();
|
||||
void setVisible(bool visible) { m_is_visible = visible; }
|
||||
bool getVisible() { return m_is_visible; }
|
||||
void addForce(dReal fx, dReal fy, dReal fz)
|
||||
@ -93,7 +96,11 @@ class Engine
|
||||
float m_scale;
|
||||
bool m_is_scaled;
|
||||
bool m_is_managed;
|
||||
bool m_is_reference;
|
||||
bool m_is_static;
|
||||
float m_aabb[6];
|
||||
OdeWorld & m_world;
|
||||
refptr<PhyObj> m_phy;
|
||||
|
||||
/* for "pre-loaded" objects */
|
||||
int * m_display_list_refcnt;
|
||||
@ -125,8 +132,10 @@ class Engine
|
||||
void run();
|
||||
void reportErrors(int status);
|
||||
OdeWorld & getWorld() { return m_world; }
|
||||
int addObject(WFObj * obj, bool is_static, float scale = 1.0f);
|
||||
int addObject(bool is_static, OdeWorld::GeomType geom_type,
|
||||
int addObject(WFObj * obj, bool is_static, bool is_reference,
|
||||
float scale = 1.0f);
|
||||
int addObject(bool is_static, bool is_reference,
|
||||
OdeWorld::GeomType geom_type,
|
||||
refptr< std::vector<float> > args);
|
||||
int addAMotor(Object * o1, Object * o2);
|
||||
int addHinge(Object * o1, Object * o2,
|
||||
@ -156,8 +165,8 @@ class Engine
|
||||
bool getAutoDrawObjects() { return m_autoDrawObjects; }
|
||||
void startFrame();
|
||||
void endFrame();
|
||||
int loadModel(const std::string & name, bool static_data,
|
||||
float scale = 1.0f);
|
||||
int loadModel(const std::string & name, bool is_static,
|
||||
bool is_reference, float scale = 1.0f);
|
||||
bool isKeyDown(const std::string & key);
|
||||
void exit();
|
||||
bool import(const char * name);
|
||||
|
148
ag.cc
148
ag.cc
@ -43,8 +43,7 @@ namespace ag
|
||||
{ "getTextSize", getTextSize },
|
||||
{ "import", import },
|
||||
{ "isKeyDown", isKeyDown },
|
||||
{ "loadModel", loadModel },
|
||||
{ "loadModelStatic", loadModelStatic },
|
||||
{ "loadModelSpecify", loadModelSpecify },
|
||||
{ "loadTexture", loadTexture },
|
||||
{ "next", next },
|
||||
{ "print", print },
|
||||
@ -66,15 +65,10 @@ namespace ag
|
||||
{ "_createHinge", _createHinge },
|
||||
|
||||
/* managed object functions */
|
||||
{ "createBox", createBox },
|
||||
{ "createBoxStatic", createBoxStatic },
|
||||
{ "createCapsule", createCapsule },
|
||||
{ "createCapsuleStatic", createCapsuleStatic },
|
||||
// { "createCylinder", createCylinder },
|
||||
// { "createCylinderStatic", createCylinderStatic },
|
||||
{ "createPlane", createPlane },
|
||||
{ "createSphere", createSphere },
|
||||
{ "createSphereStatic", createSphereStatic },
|
||||
{ "createBoxSpecify", createBoxSpecify },
|
||||
{ "createCapsuleSpecify", createCapsuleSpecify },
|
||||
{ "createPlaneSpecify", createPlaneSpecify },
|
||||
{ "createSphereSpecify", createSphereSpecify },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
@ -353,19 +347,22 @@ namespace ag
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int loadModelSpecify(lua_State * L, bool static_data)
|
||||
int loadModelSpecify(lua_State * L)
|
||||
{
|
||||
bool added = false;
|
||||
float scale = 1.0f;
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
if (argc >= 2 && lua_isnumber(L, 2))
|
||||
scale = lua_tonumber(L, 2);
|
||||
|
||||
if (argc >= 1 && lua_isstring(L, 1))
|
||||
if (argc == 4
|
||||
&& lua_isstring(L, 1)
|
||||
&& lua_isnumber(L, 2)
|
||||
&& lua_isboolean(L, 3)
|
||||
&& lua_isboolean(L, 4))
|
||||
{
|
||||
string modelname = lua_tostring(L, 1);
|
||||
int id = g_engine->loadModel(modelname, static_data, scale);
|
||||
int id = g_engine->loadModel(
|
||||
lua_tostring(L, 1), /* name */
|
||||
lua_toboolean(L, 3), /* static */
|
||||
lua_toboolean(L, 4), /* reference */
|
||||
lua_tonumber(L, 2)); /* scale */
|
||||
if (id > 0)
|
||||
{
|
||||
createLuaObject(L, id);
|
||||
@ -377,16 +374,6 @@ namespace ag
|
||||
return 1;
|
||||
}
|
||||
|
||||
int loadModel(lua_State * L)
|
||||
{
|
||||
return loadModelSpecify(L, false);
|
||||
}
|
||||
|
||||
int loadModelStatic(lua_State * L)
|
||||
{
|
||||
return loadModelSpecify(L, true);
|
||||
}
|
||||
|
||||
int sleep(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
@ -795,71 +782,59 @@ namespace ag
|
||||
}
|
||||
|
||||
static void addManagedObject(lua_State * L, bool is_static,
|
||||
bool is_reference,
|
||||
OdeWorld::GeomType geom_type, refptr< vector<float> > args)
|
||||
{
|
||||
int id = g_engine->addObject(is_static, geom_type, args);
|
||||
int id = g_engine->addObject(is_static, is_reference, geom_type, args);
|
||||
createLuaObject(L, id);
|
||||
}
|
||||
|
||||
static int createBoxSpecify(lua_State * L, bool is_static)
|
||||
int createBoxSpecify(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
if (argc == 3 &&
|
||||
lua_isnumber(L, 1) &&
|
||||
lua_isnumber(L, 2) &&
|
||||
lua_isnumber(L, 3))
|
||||
if (argc == 5
|
||||
&& lua_isnumber(L, 1)
|
||||
&& lua_isnumber(L, 2)
|
||||
&& lua_isnumber(L, 3)
|
||||
&& lua_isboolean(L, 4)
|
||||
&& lua_isboolean(L, 5))
|
||||
{
|
||||
refptr< vector<float> > args = new vector<float>();
|
||||
for (int i = 1; i <= 3; i++)
|
||||
args->push_back(lua_tonumber(L, i));
|
||||
addManagedObject(L, is_static, OdeWorld::BOX, args);
|
||||
addManagedObject(L, lua_toboolean(L, 4), lua_toboolean(L, 5),
|
||||
OdeWorld::BOX, args);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int createBox(lua_State * L)
|
||||
{
|
||||
return createBoxSpecify(L, false);
|
||||
}
|
||||
|
||||
int createBoxStatic(lua_State * L)
|
||||
{
|
||||
return createBoxSpecify(L, true);
|
||||
}
|
||||
|
||||
static int createSphereSpecify(lua_State * L, bool is_static)
|
||||
int createSphereSpecify(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
if (argc == 1 && lua_isnumber(L, 1))
|
||||
if (argc == 3
|
||||
&& lua_isnumber(L, 1)
|
||||
&& lua_isboolean(L, 2)
|
||||
&& lua_isboolean(L, 3))
|
||||
{
|
||||
refptr< vector<float> > args = new vector<float>();
|
||||
args->push_back(lua_tonumber(L, 1));
|
||||
addManagedObject(L, is_static, OdeWorld::SPHERE, args);
|
||||
addManagedObject(L, lua_toboolean(L, 2), lua_toboolean(L, 3),
|
||||
OdeWorld::SPHERE, args);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int createSphere(lua_State * L)
|
||||
{
|
||||
return createSphereSpecify(L, false);
|
||||
}
|
||||
|
||||
int createSphereStatic(lua_State * L)
|
||||
{
|
||||
return createSphereSpecify(L, true);
|
||||
}
|
||||
|
||||
int createPlane(lua_State * L)
|
||||
int createPlaneSpecify(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
if (argc == 4 || argc == 6)
|
||||
if (argc == 5 || argc == 7)
|
||||
{
|
||||
bool valid = true;
|
||||
for (int i = 1; i <= argc; i++)
|
||||
bool valid = lua_isboolean(L, argc);
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (!lua_isnumber(L, i))
|
||||
{
|
||||
@ -870,9 +845,10 @@ namespace ag
|
||||
if (valid)
|
||||
{
|
||||
refptr< vector<float> > args = new vector<float>();
|
||||
for (int i = 1; i <= argc; i++)
|
||||
for (int i = 1; i < argc; i++)
|
||||
args->push_back(lua_tonumber(L, i));
|
||||
addManagedObject(L, true, OdeWorld::PLANE, args);
|
||||
addManagedObject(L, true, lua_toboolean(L, argc),
|
||||
OdeWorld::PLANE, args);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -880,56 +856,46 @@ namespace ag
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int createCylinderSpecify(lua_State * L, bool is_static)
|
||||
int createCylinderSpecify(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
if (argc == 2 && lua_isnumber(L, 1) && lua_isnumber(L, 2))
|
||||
if (argc == 4
|
||||
&& lua_isnumber(L, 1)
|
||||
&& lua_isnumber(L, 2)
|
||||
&& lua_isboolean(L, 3)
|
||||
&& lua_isboolean(L, 4))
|
||||
{
|
||||
refptr< vector<float> > args = new vector<float>();
|
||||
args->push_back(lua_tonumber(L, 1));
|
||||
args->push_back(lua_tonumber(L, 2));
|
||||
addManagedObject(L, is_static, OdeWorld::CYLINDER, args);
|
||||
addManagedObject(L, lua_toboolean(L, 3), lua_toboolean(L, 4),
|
||||
OdeWorld::CYLINDER, args);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int createCylinder(lua_State * L)
|
||||
{
|
||||
return createCylinderSpecify(L, false);
|
||||
}
|
||||
|
||||
int createCylinderStatic(lua_State * L)
|
||||
{
|
||||
return createCylinderSpecify(L, true);
|
||||
}
|
||||
|
||||
static int createCapsuleSpecify(lua_State * L, bool is_static)
|
||||
int createCapsuleSpecify(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
if (argc == 2 && lua_isnumber(L, 1) && lua_isnumber(L, 2))
|
||||
if (argc == 4
|
||||
&& lua_isnumber(L, 1)
|
||||
&& lua_isnumber(L, 2)
|
||||
&& lua_isboolean(L, 3)
|
||||
&& lua_isboolean(L, 4))
|
||||
{
|
||||
refptr< vector<float> > args = new vector<float>();
|
||||
args->push_back(lua_tonumber(L, 1));
|
||||
args->push_back(lua_tonumber(L, 2));
|
||||
addManagedObject(L, is_static, OdeWorld::CAPSULE, args);
|
||||
addManagedObject(L, lua_toboolean(L, 3), lua_toboolean(L, 4),
|
||||
OdeWorld::CAPSULE, args);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int createCapsule(lua_State * L)
|
||||
{
|
||||
return createCapsuleSpecify(L, false);
|
||||
}
|
||||
|
||||
int createCapsuleStatic(lua_State * L)
|
||||
{
|
||||
return createCapsuleSpecify(L, true);
|
||||
}
|
||||
|
||||
int startList(lua_State * L)
|
||||
{
|
||||
GLuint list = g_engine->startList();
|
||||
|
17
ag.h
17
ag.h
@ -22,8 +22,7 @@ namespace ag
|
||||
int getScreenSize(lua_State * L);
|
||||
int import(lua_State * L);
|
||||
int isKeyDown(lua_State * L);
|
||||
int loadModel(lua_State * L);
|
||||
int loadModelStatic(lua_State * L);
|
||||
int loadModelSpecify(lua_State * L);
|
||||
int loadTexture(lua_State * L);
|
||||
int next(lua_State * L);
|
||||
int print(lua_State * L);
|
||||
@ -56,15 +55,11 @@ namespace ag
|
||||
int getTextSize(lua_State * L);
|
||||
|
||||
/* managed object creation functions */
|
||||
int createBox(lua_State * L);
|
||||
int createBoxStatic(lua_State * L);
|
||||
int createCapsule(lua_State * L);
|
||||
int createCapsuleStatic(lua_State * L);
|
||||
int createCylinder(lua_State * L);
|
||||
int createCylinderStatic(lua_State * L);
|
||||
int createPlane(lua_State * L);
|
||||
int createSphere(lua_State * L);
|
||||
int createSphereStatic(lua_State * L);
|
||||
int createBoxSpecify(lua_State * L);
|
||||
int createCapsuleSpecify(lua_State * L);
|
||||
int createCylinderSpecify(lua_State * L);
|
||||
int createPlaneSpecify(lua_State * L);
|
||||
int createSphereSpecify(lua_State * L);
|
||||
|
||||
namespace object
|
||||
{
|
||||
|
80
ag.lua
80
ag.lua
@ -106,3 +106,83 @@ ag.createHinge = function(obj1, obj2, anchor, axis)
|
||||
axis[1], axis[2], axis[3])
|
||||
end
|
||||
|
||||
ag.loadModel = function(name, args)
|
||||
local scale = 1.0
|
||||
local static = false
|
||||
local reference = false
|
||||
if (type(args) == "table") then
|
||||
if (type(args.scale) == "number") then
|
||||
scale = args.scale
|
||||
end
|
||||
if (type(args.static) == "boolean") then
|
||||
static = args.static
|
||||
end
|
||||
if (type(args.reference) == "boolean") then
|
||||
reference = args.reference
|
||||
end
|
||||
end
|
||||
return ag.loadModelSpecify(name, scale, static, reference)
|
||||
end
|
||||
|
||||
ag.createBox = function(x, y, z, args)
|
||||
local static = false
|
||||
local reference = false
|
||||
if (type(args) == "table") then
|
||||
if (type(args.static) == "boolean") then
|
||||
static = args.static
|
||||
end
|
||||
if (type(args.reference) == "boolean") then
|
||||
reference = args.reference
|
||||
end
|
||||
end
|
||||
return ag.createBoxSpecify(x, y, z, static, reference)
|
||||
end
|
||||
|
||||
ag.createSphere = function(radius, args)
|
||||
local static = false
|
||||
local reference = false
|
||||
if (type(args) == "table") then
|
||||
if (type(args.static) == "boolean") then
|
||||
static = args.static
|
||||
end
|
||||
if (type(args.reference) == "boolean") then
|
||||
reference = args.reference
|
||||
end
|
||||
end
|
||||
return ag.createSphereSpecify(radius, static, reference)
|
||||
end
|
||||
|
||||
ag.createPlane = function(a, b, c, d, x, y, z)
|
||||
local t = nil
|
||||
if (type(x) == "table") then
|
||||
t = x
|
||||
end
|
||||
if (type(z) == "table") then
|
||||
t = z
|
||||
end
|
||||
local reference = false
|
||||
if (type(t) == "table") then
|
||||
if (type(t.reference) == "boolean") then
|
||||
reference = t.reference
|
||||
end
|
||||
end
|
||||
if (type(y) == "nil") then
|
||||
return ag.createPlaneSpecify(a, b, c, d, reference)
|
||||
else
|
||||
return ag.createPlaneSpecify(a, b, c, d, x, y, reference)
|
||||
end
|
||||
end
|
||||
|
||||
ag.createCapsule = function(radius, length, args)
|
||||
local static = false
|
||||
local reference = false
|
||||
if (type(args) == "table") then
|
||||
if (type(args.static) == "boolean") then
|
||||
static = args.static
|
||||
end
|
||||
if (type(args.reference) == "boolean") then
|
||||
reference = args.reference
|
||||
end
|
||||
end
|
||||
return ag.createCapsuleSpecify(radius, length, static, reference)
|
||||
end
|
||||
|
@ -63,17 +63,17 @@ function setupScore()
|
||||
end
|
||||
|
||||
function init_event()
|
||||
lane = ag.loadModelStatic("bowling_lane")
|
||||
lane = ag.loadModel("bowling_lane", {static = true})
|
||||
local minx, miny, minz, maxx, maxy, maxz = lane:getAABB()
|
||||
local lane_bottom = minz
|
||||
local lane_top = maxz
|
||||
pins = {}
|
||||
reference_pin = ag.loadModel("bowling_pin", 1.0/4.3)
|
||||
reference_pin = ag.loadModel("bowling_pin", {scale = 1.0/4.3})
|
||||
minx, miny, minz, maxx, maxy, maxz = reference_pin:getAABB()
|
||||
pin_minz = minz
|
||||
pin_maxz = maxz
|
||||
pin_standing_position = lane_top - pin_minz
|
||||
local box = ag.createBoxStatic(1, 10, 0.1)
|
||||
local box = ag.createBox(1, 10, 0.1, {static = true})
|
||||
box:setVisible(false)
|
||||
box:setPosition(0, 0, lane_bottom - (maxz - minz) - 0.4)
|
||||
reference_pin:setPosition(0, 0, lane_bottom - maxz - 0.1)
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
function createWorld()
|
||||
board = ag.createBoxStatic(8, 8, 0.01)
|
||||
board = ag.createBox(8, 8, 0.01, {static = true})
|
||||
board:setPosition(0, 0, -0.005)
|
||||
board:setTexture(checker)
|
||||
board:setTextureScale(2)
|
||||
|
@ -70,7 +70,7 @@ end
|
||||
-- model_name: the string containing the name of the model to load
|
||||
-- max_x, max_y, max_z:
|
||||
std.loadModelBounds = function(model_name, max_x, max_y, max_z)
|
||||
local tmp_model = ag.loadModel(model_name)
|
||||
local tmp_model = ag.loadModel(model_name, {reference = true})
|
||||
local sx, sy, sz = tmp_model:getSize()
|
||||
tmp_model:destroy()
|
||||
local scale = 1.0
|
||||
@ -93,5 +93,5 @@ std.loadModelBounds = function(model_name, max_x, max_y, max_z)
|
||||
scale_set = true
|
||||
end
|
||||
end
|
||||
return ag.loadModel(model_name, scale)
|
||||
return ag.loadModel(model_name, {scale = scale})
|
||||
end
|
||||
|
@ -1,13 +1,13 @@
|
||||
|
||||
function init_event()
|
||||
arena = ag.loadModelStatic("boxarena")
|
||||
arena = ag.loadModel("boxarena", { static = true })
|
||||
ball = ag.loadModel("checkerball")
|
||||
ball:setPosition(-7, 7.4, 12)
|
||||
ball2 = ball:clone()
|
||||
ball2:setPosition(-7, 7.4, 14)
|
||||
ball3 = ball:clone()
|
||||
ball3:setPosition(-7, 7.4, 16)
|
||||
logo = ag.loadModel("dwlogo", 0.5)
|
||||
logo = ag.loadModel("dwlogo", {scale = 0.5})
|
||||
logo:setPosition(-1, 2, 11)
|
||||
crate = ag.loadModel("crate")
|
||||
crate:setPosition(-5, -3, 10)
|
||||
|
@ -4,7 +4,7 @@ function init_event()
|
||||
|
||||
local rows = 5
|
||||
local offset = 1
|
||||
local pin = ag.loadModel("bowling_pin", 0.5)
|
||||
local pin = ag.loadModel("bowling_pin", {scale = 0.5})
|
||||
pin:setPosition(0, 0, 2)
|
||||
for row = 2, rows do
|
||||
for x = 1, row do
|
||||
@ -21,7 +21,7 @@ function init_event()
|
||||
ag.setCamera(0.3, -25, 10, 0, 0, 1, 0, 0, 1)
|
||||
camx, camy, camz, cx, cy, cz = ag.getCamera()
|
||||
|
||||
ball = ag.loadModel("checkerball", 0.5)
|
||||
ball = ag.loadModel("checkerball", {scale = 0.5})
|
||||
ball:setPosition(2*camx - cx, 2*camy - cy, 2*camz - cz)
|
||||
ball:setMass(5)
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
function init_event()
|
||||
local levels = 7
|
||||
local crate = ag.loadModel("crate", 0.5)
|
||||
local crate = ag.loadModel("crate", {scale = 0.5})
|
||||
local offset = 0.5
|
||||
crate:setPosition(0, 0, offset + levels + 0.5)
|
||||
for level = 2, levels do
|
||||
@ -12,7 +12,7 @@ function init_event()
|
||||
end
|
||||
end
|
||||
|
||||
local ground = ag.loadModelStatic("crate", 10)
|
||||
local ground = ag.loadModel("crate", { static = true, scale = 10 })
|
||||
ground:setPosition(0, 0, -10)
|
||||
ag.setCamera(levels/2, -2*levels, levels, 0, 0, levels/2, 0, 0, 1)
|
||||
camx, camy, camz, cx, cy, cz = ag.getCamera()
|
||||
|
@ -3,7 +3,7 @@ function init_event()
|
||||
crates = {}
|
||||
|
||||
levels = 5
|
||||
local crate = ag.loadModel("crate", 0.5)
|
||||
local crate = ag.loadModel("crate", {scale=0.5})
|
||||
crates[1] = crate
|
||||
offset = 0.5
|
||||
crate:setPosition(0, 0, offset + levels + 0.5)
|
||||
@ -18,7 +18,7 @@ function init_event()
|
||||
end
|
||||
end
|
||||
|
||||
ground = ag.loadModelStatic("crate", 10)
|
||||
ground = ag.loadModel("crate", {static = true, scale = 10})
|
||||
ground:setPosition(0, 0, -10)
|
||||
ag.setCamera(2, -12, 8, 0, 0, 2, 0, 0, 1)
|
||||
end
|
||||
|
@ -2,7 +2,7 @@
|
||||
function init_event()
|
||||
ag.import("std")
|
||||
image = ag.loadTexture("transparent.png")
|
||||
local crate = ag.loadModelStatic("crate")
|
||||
local crate = ag.loadModel("crate", {static = true})
|
||||
ag.setCamera(5, -5, 5)
|
||||
end
|
||||
|
||||
|
@ -25,10 +25,10 @@ function key_down_event(key)
|
||||
if (key == "b") then
|
||||
local box = ag.createBox(1, 1, 1)
|
||||
init_obj(box)
|
||||
elseif (key == "c") then
|
||||
-- cylinders are buggy in ODE
|
||||
local cyl = ag.createCylinder(0.5, 1)
|
||||
init_obj(cyl)
|
||||
-- elseif (key == "c") then
|
||||
-- -- cylinders are buggy in ODE
|
||||
-- local cyl = ag.createCylinder(0.5, 1)
|
||||
-- init_obj(cyl)
|
||||
elseif (key == "a") then
|
||||
local ccyl = ag.createCapsule(0.5, 1)
|
||||
init_obj(ccyl)
|
||||
|
Loading…
x
Reference in New Issue
Block a user