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

Reply via email to