working on 3d picking -- angle calculation incorrect...

git-svn-id: svn://anubis/anaglym/trunk@250 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2010-02-20 19:50:56 +00:00
parent e2dc4529cc
commit 0ec9d0e74d
4 changed files with 44 additions and 0 deletions

View File

@ -53,6 +53,18 @@ static void debug_hook(lua_State * L, lua_Debug * debug)
g_engine->debug_hook(debug);
}
static void normalize(dVector3 vec)
{
float len = vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2];
if (! FP_EQ(len, 1.0)) /* normalize if necessary */
{
len = sqrtf(len);
vec[0] /= len;
vec[1] /= len;
vec[2] /= len;
}
}
#define DEBUG_GL_ERROR
#ifdef DEBUG_GL_ERROR
#define checkGLError() checkGLErrorLine(__FUNCTION__, __LINE__)
@ -642,7 +654,20 @@ refptr< vector<int> > Engine::pickObjects(int x, int y)
initial_direction[2] = m_video.getHeight() / 2 - y;
dMultiply0(rotated_direction, initial_direction, r, 1, 3, 3);
normalize(rotated_direction);
/* TODO: finish */
refptr< vector<float> > args = new vector<float>();
args->push_back(0.5);
for (float d = 3.0; d < 10.0; d += 2.0)
{
int o = addObject(false, false, OdeWorld::SPHERE, args);
m_objects[o]->setPosition(
m_center[0] + d * rotated_direction[0],
m_center[1] + d * rotated_direction[1],
m_center[2] + d * rotated_direction[2]);
}
return new vector<int>();
}
void Engine::debug_hook(lua_Debug * debug)

11
ag.cc
View File

@ -47,6 +47,7 @@ namespace ag
{ "loadModelSpecify", loadModelSpecify },
{ "loadTexture", loadTexture },
{ "next", next },
{ "pickObjects", pickObjects },
{ "print", print },
{ "println", println },
{ "registerEventHandler", registerEventHandler },
@ -82,6 +83,16 @@ namespace ag
lua_pcall(L, 0, 0, 0);
}
int pickObjects(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 2 && lua_isnumber(L, 1) && lua_isnumber(L, 2))
{
g_engine->pickObjects(lua_tointeger(L, 1), lua_tointeger(L, 2));
}
return 0;
}
static void print_val(lua_State * L, int index)
{
int type = lua_type(L, index);

1
ag.h
View File

@ -26,6 +26,7 @@ namespace ag
int loadModelSpecify(lua_State * L);
int loadTexture(lua_State * L);
int next(lua_State * L);
int pickObjects(lua_State * L);
int print(lua_State * L);
int println(lua_State * L);
int registerEventHandler(lua_State * L);

View File

@ -10,6 +10,7 @@ function init_event()
ag.println("error importing rot_camera")
ag.exit()
end
ag.setCursorVisible(true)
end
function init_obj(obj)
@ -56,3 +57,9 @@ function key_down_event(key)
ag.setCursorVisible(not ag.getCursorVisible())
end
end
function mousebutton_down_event(button, x, y)
if (button == 1) then
ag.pickObjects(x, y)
end
end