diff --git a/Engine.cc b/Engine.cc index 2b44f52..4f710f6 100644 --- a/Engine.cc +++ b/Engine.cc @@ -14,7 +14,7 @@ #include #include #include -#include /* fabs() */ +#include /* fabs(), tan() */ #include #include #include "SDL.h" @@ -99,6 +99,7 @@ Engine::Engine(const string & path, Video & video) m_engine_cursor_visible = m_video.getCursorVisible(); m_script_cursor_visible = false; m_input_grabbed = m_video.getInputGrabbed(); + m_screen_dist = (m_video.getWidth() / 2.0) / tan(30.0 * M_PI / 180.0); size_t pos = path.find_last_of("\\/"); m_engine_path = (pos != string::npos) ? string(path, 0, pos) : "."; @@ -622,6 +623,28 @@ void Engine::clearWorld() } } +refptr< vector > Engine::pickObjects(int x, int y) +{ + dMatrix3 r; + dVector3 right, forward, up; + dVector3 rotated_direction, initial_direction; + up[0] = m_up[0]; + up[1] = m_up[1]; + up[2] = m_up[2]; + forward[0] = m_center[0] - m_eye[0]; + forward[1] = m_center[1] - m_eye[1]; + forward[2] = m_center[2] - m_eye[2]; + cross_product(right, forward, up); + dRFrom2Axes(r, right[0], right[1], right[2], + forward[0], forward[1], forward[2]); + initial_direction[0] = x - m_video.getWidth() / 2; + initial_direction[1] = m_screen_dist; + initial_direction[2] = m_video.getHeight() / 2 - y; + dMultiply0(rotated_direction, initial_direction, r, 1, 3, 3); + + /* TODO: finish */ +} + void Engine::debug_hook(lua_Debug * debug) { Uint32 ticks = SDL_GetTicks(); diff --git a/Engine.h b/Engine.h index b2843fb..66bcaf8 100644 --- a/Engine.h +++ b/Engine.h @@ -195,6 +195,7 @@ class Engine updateCursorVisibility(); } bool getScriptCursorVisible() { return m_script_cursor_visible; } + refptr< std::vector > pickObjects(int x, int y); void getScreenSize(int * width, int * height); void drawText(const char * text, GLfloat r, GLfloat g, GLfloat b, @@ -274,6 +275,7 @@ class Engine SDL_Event m_exitEvent; Uint32 m_event_time; FTFont * m_font; + double m_screen_dist; bool m_event_init_present; bool m_event_reinit_present;