changed OdeWorld::pickObjects and Engine::pickObjects to return distance, position, and normal information along with object identifier

git-svn-id: svn://anubis/anaglym/trunk@304 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2010-09-16 21:12:38 +00:00
parent 23088dbdfe
commit 59f8c7a28e
3 changed files with 39 additions and 10 deletions

View File

@ -658,7 +658,7 @@ void Engine::clearWorld()
} }
} }
refptr< vector<int> > Engine::pickObjects(int x, int y) refptr< vector<Engine::PickedObjectRef> > Engine::pickObjects(int x, int y)
{ {
dMatrix3 r; dMatrix3 r;
dVector3 right, forward, up; dVector3 right, forward, up;
@ -678,17 +678,17 @@ refptr< vector<int> > Engine::pickObjects(int x, int y)
dMultiply0(rotated_direction, r, initial_direction, 3, 3, 1); dMultiply0(rotated_direction, r, initial_direction, 3, 3, 1);
normalize(rotated_direction); normalize(rotated_direction);
refptr< vector<OdeWorld::Object *> > objects = refptr< vector<OdeWorld::PickedObjectRef> > objects =
m_world.pickObjects(m_eye[0], m_eye[1], m_eye[2], m_world.pickObjects(m_eye[0], m_eye[1], m_eye[2],
rotated_direction[0], rotated_direction[1], rotated_direction[2]); rotated_direction[0], rotated_direction[1], rotated_direction[2]);
refptr< vector<int> > ret = new vector<int>(); refptr< vector<PickedObjectRef> > ret = new vector<PickedObjectRef>();
for (vector<OdeWorld::Object *>::const_iterator it = objects->begin(); for (vector<OdeWorld::PickedObjectRef>::const_iterator it
= objects->begin();
it != objects->end(); it != objects->end();
it++) it++)
{ {
Object * o = (Object *) (*it)->getUserData(); ret->push_back(new PickedObject(*it));
ret->push_back(o->getID());
} }
return ret; return ret;
} }
@ -1729,3 +1729,19 @@ string Engine::EngineFileLoader::resolvePath(const Path & path)
file_path = path.fullPath; file_path = path.fullPath;
return file_path; return file_path;
} }
/******** Engine::PickedObject functions ********/
Engine::PickedObject::PickedObject(OdeWorld::PickedObjectRef por)
{
Object * o = (Object *) por->obj->getUserData();
id = o->getID();
dist = por->dist;
pos[0] = por->pos[0];
pos[1] = por->pos[1];
pos[2] = por->pos[2];
normal[0] = por->normal[0];
normal[1] = por->normal[1];
normal[2] = por->normal[2];
}

View File

@ -136,6 +136,18 @@ class Engine
Engine * m_engine; Engine * m_engine;
}; };
class PickedObject
{
public:
int id;
float dist;
float pos[3];
float normal[3];
PickedObject(OdeWorld::PickedObjectRef por);
};
typedef refptr<PickedObject> PickedObjectRef;
Engine(const std::string & path, AV & av); Engine(const std::string & path, AV & av);
~Engine(); ~Engine();
@ -203,7 +215,7 @@ class Engine
updateCursorVisibility(); updateCursorVisibility();
} }
bool getScriptCursorVisible() { return m_script_cursor_visible; } bool getScriptCursorVisible() { return m_script_cursor_visible; }
refptr< std::vector<int> > pickObjects(int x, int y); refptr< std::vector<PickedObjectRef> > pickObjects(int x, int y);
void getScreenSize(int * width, int * height); void getScreenSize(int * width, int * height);
void drawText(const char * text, GLfloat r, GLfloat g, GLfloat b, void drawText(const char * text, GLfloat r, GLfloat g, GLfloat b,

7
ag.cc
View File

@ -97,15 +97,16 @@ namespace ag
{ {
lua_newtable(L); lua_newtable(L);
int next_index = 1; int next_index = 1;
refptr< vector<int> > objects = refptr< vector<Engine::PickedObjectRef> > objects =
g_engine->pickObjects(lua_tointeger(L, 1), lua_tointeger(L, 2)); g_engine->pickObjects(lua_tointeger(L, 1), lua_tointeger(L, 2));
for (vector<int>::const_iterator it = objects->begin(); for (vector<Engine::PickedObjectRef>::const_iterator it
= objects->begin();
it != objects->end(); it != objects->end();
it++) it++)
{ {
lua_getfield(L, LUA_GLOBALSINDEX, "ag"); /* pushes 1 */ lua_getfield(L, LUA_GLOBALSINDEX, "ag"); /* pushes 1 */
lua_getfield(L, -1, "_objects"); /* pushes 1 */ lua_getfield(L, -1, "_objects"); /* pushes 1 */
lua_pushinteger(L, *it); /* pushes 1 */ lua_pushinteger(L, (*it)->id); /* pushes 1 */
lua_gettable(L, -2); /* replace top */ lua_gettable(L, -2); /* replace top */
lua_remove(L, -3); /* remove 1 */ lua_remove(L, -3); /* remove 1 */
lua_remove(L, -2); /* remove 1 */ lua_remove(L, -2); /* remove 1 */