Commit f5df23af authored by Eric Bruneton's avatar Eric Bruneton
Browse files

added getWorldCoordinates method in SceneManager

added optional "name" attribute in ShowInfoTask

git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/ork/trunk@22 28599a00-4e59-401b-b2d8-d34d4661a6c9
parent 652ae58c
......@@ -306,6 +306,24 @@ double SceneManager::getElapsedTime()
return dt;
}
vec3d SceneManager::getWorldCoordinates(int x, int y)
{
float winx, winy, winz;
ptr<FrameBuffer> fb = FrameBuffer::getDefault();
vec4<GLint> vp = fb->getViewport();
float width = (float) vp.z;
float height = (float) vp.w;
fb->readPixels(x, vp.w - y, 1, 1, DEPTH_COMPONENT, FLOAT, Buffer::Parameters(), CPUBuffer(&winz));
winx = (x * 2.0f) / width - 1.0f;
winy = 1.0f - (y * 2.0f) / height;
winz = 2.0f * winz - 1.0f;
mat4d screenToWorld = getWorldToScreen().inverse();
vec4d p = screenToWorld * vec4d(winx, winy, winz, 1);
return vec3d(p.x / p.w, p.y / p.w, p.z / p.w);
}
SceneManager::visibility SceneManager::getVisibility(const vec4d &clip, const box3d &b)
{
double x0 = b.xmin * clip.x;
......
......@@ -220,6 +220,16 @@ public:
*/
double getElapsedTime();
/**
* Returns the 3D coordinates in world space corresponding to the given
* screen space position.
*
* @param x horizontal screen position.
* @param y vertical screen position.
* @return ths 3D coordinates in world space corresponding to x,y
*/
vec3d getWorldCoordinates(int x, int y);
/**
* Returns the current FrameBuffer.
*/
......
......@@ -34,7 +34,7 @@ void initInfoTask(ptr<ResourceManager> manager, const string &name, ptr<Resource
ptr<Font> &f, ptr<Program> &p, int &c, float &size, vec3i &pos)
{
e = e == NULL ? desc->descriptor : e;
Resource::checkParameters(desc, e, "x,y,maxLines,font,fontSize,fontColor,fontProgram,");
Resource::checkParameters(desc, e, "name,x,y,maxLines,font,fontSize,fontColor,fontProgram,");
int x = 4;
int y = -4;
int maxLines = 8;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment