[osg-users] How to extend my screen space handling to z-direction?
Hi osg-community, I am working on a stereoscopic renderer which can receive mouse and on-screen-touch-events to handle translations of the scene. Now I want to extend this to handle gestures of the Xbox-Kinect camera. I already got it working for the x and y on-screen translation. Unfortunatly I don't know how to handle movements of the z-direction (towards/into the screen). I already ensure that my coordinates from my kinect-camera are scaled from -1 to 1 for all directions. Here is the code that is already working for X and Y directions. I have tried to extend (commented out) it for the Z direction but couldn't get it to work. Maybe someone has any idea how to do it. My implementation for the z-direction was a complete guess, so it is possible that I am way off. Code: double dist = opencover::cover-getViewerScreenDistance(); // // The center is (0.5, 0.5) only if the viewer position is exactly in the middle // of the screen // On the table, we are way more nearer to the bottom, thus, the center is calculated // dynamically. This way, head-tracking is possible // double horzFrustum = this-frustum.right + fabsf(this-frustum.left ); double vertFrustum = this-frustum.top + fabsf(this-frustum.bottom); //double forwardFrustum = fabsf(this-frustum.zfar) + fabsf(this-frustum.znear); // // For stereo, we are interacting on the screen surface and not on the near plane, // thus calculate the motion on the surface // double surfaceRight = (horzFrustum / 2.0f) * dist / this-frustum.znear; double surfaceTop = (vertFrustum / 2.0f) * dist / this-frustum.znear; //double surfaceFar = (forwardFrustum / 2.0f) * dist / this-frustum.znear; double screenCenterX = this-frustum.right / horzFrustum; double screenCenterY = this-frustum.top / vertFrustum; //double screenCenterZ = this-frustum.zfar / forwardFrustum; // // Compute x0 and y0 in world coords using the theorem on intersecting lines // double x0 = (cur.down.x() - screenCenterX) * 2.0 * surfaceRight; double y0 = (cur.down.y() - screenCenterY) * 2.0 * surfaceTop; //double z0 = (cur.down.z() - screenCenterZ) * 2.0 * surfaceFar; // // Compute xc and yc in world coords using the theorem on intersecting lines // double xc = (cur.curr.x() - screenCenterX) * 2.0 * surfaceRight; double yc = (cur.curr.y() - screenCenterY) * 2.0 * surfaceTop; //double zc = (cur.curr.z() - screenCenterZ) * 2.0 * surfaceFar; // // Compute translation // osg::Vec3 direction = Vec3(xc-x0, zc-z0, yc-y0); // // Get the viewer position // osg::Vec3 viewerPosition = opencover::cover-getViewerMat().getTrans(); // // Compute new transform matrix // osg::Matrix transform = this-rootTransform * osg::Matrix::translate(-viewerPosition) * osg::Matrix::translate(direction) * osg::Matrix::translate(viewerPosition); // // Apply the new transformation matrix -- if it's valid // if (transform.valid()) { opencover::VRSceneGraph::instance()-getTransform()-setMatrix(transform); } variable cur.down is where the cursor of mouse started clicking / touch on the screen first appeared / kinect started captureing the skeleton variable cur.curr is the current position of the corresponding cursor (mouse/touch/kinect). I hope someone can help! Thank you! Cheers, Charma -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=52065#52065 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] How to draw a simple frustum wireframe cube?
Hello Forum, I am an absolute osg-beginner. I am currently working on a very huge project which is using osg. I now would like to draw something in the existing scene without messing everything up. I will try to give you as much detail as I can to make it easier to understand. I have access to a callback-function which is called before every frame drawing. Also I have access to the two matices Code: this-rootTransform = opencover::cover-getObjectsXform()-getMatrix(); // Get camera frustum parameters osg::Matrix matProj = opencover::coVRConfig::instance()-screens[0].camera-getProjectionMatrix(); matProj.getFrustum( this-frustum.left, this-frustum.right, this-frustum.bottom, this-frustum.top, this-frustum.znear, this-frustum.zfar ); As you probably see the call opencover::coVRConfig::instance() also returns the instance. What I would like to do now is draw some simple lines (as in like glBegin) but in screen coordinates, so with positions in the frustum corners like (1,1,1) or (1,-1,-1). The reason for this is that I want to make the whole frustum visible because I am using a stereoscopic VR-renderer and I want to validiate how big the frustum is and when do you step into the 3D scene. I hope anyone can help me with this and can provide some simple sample code. If you need more detail, feel free to ask back. Thank you! Cheers, Charma -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50045#50045 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org