3DxInput Polling

Post questions, comments and feedback to our 3Dconnexion Windows Development Team.

Moderator: Moderators

Post Reply
chrislu
Posts: 11
Joined: Sun Jun 07, 2009 8:58 am

3DxInput Polling

Post by chrislu »

Hi,
i am using code similar to an old 3DxInput example to poll the transformations from the device:

Code: Select all

    CComPtr<IAngleAxis> rotation;
    CComPtr<IVector3D>  translation;
    double              rotation_angle;
    double              translation_length;

    _3d_sensor->get_Rotation(&rotation);
    _3d_sensor->get_Translation(&translation);
    rotation->get_Angle(&rotation_angle);
    translation->get_Length(&translation_length);

    _device->_rotation    = mat4f::identity();
    _device->_translation = mat4f::identity();

    if (   (rotation_angle     > 0.0)
        || (translation_length > 0.0)) {

        _timer.stop();
        _timer.start();

        double time_factor = 1.0;
        double  period; // in millisec
        _3d_sensor->get_Period(&period);
        time_factor = scm::time::to_milliseconds(_timer.get_time()) / (period * 1000.0);

        // translation
        vec3d  trans_vec;
        translation->get_X(&trans_vec.x);
        translation->get_Y(&trans_vec.y);
        translation->get_Z(&trans_vec.z);

        trans_vec *= vec3d(_device->_translation_sensitivity) * time_factor;
        translate(_device->_translation, math::vec3f(trans_vec));


        // rotation
        vec3d  rot_axis;
        rotation->get_X(&rot_axis.x);
        rotation->get_Y(&rot_axis.y);
        rotation->get_Z(&rot_axis.z);

        rotation_angle *= time_factor;
        rotate(_device->_rotation, static_cast<float>(math::rad2deg(rotation_angle)), (math::vec3f(rot_axis)));
    }

    rotation.Release();
    translation.Release();

Now i call the method containing the code fragment above in every iteration of my frame loop. This works fine until the frame rate drops. Even at 25ms (40fps), i get very jittery motion from the device to the point where almost no values come in.

Where is this problem coming from? Why do i not get the actual values from the device?

-chris
DaveLock
Posts: 8
Joined: Thu Feb 24, 2011 2:02 am

Re: 3DxInput Polling

Post by DaveLock »

chrislu wrote: i am using code similar to an old 3DxInput example to poll the transformations from the device:

...

Now i call the method containing the code fragment above in every iteration of my frame loop. This works fine until the frame rate drops. Even at 25ms (40fps), i get very jittery motion from the device to the point where almost no values come in.

Where is this problem coming from? Why do i not get the actual values from the device?
Hi Chris,

I'm currently writing a C++ plug-in for an existing 3D software application to give it 3Dx support, but by no means am I an authority on C++ or writing to the TDxInput COM lib. I'm answering because I see nobody else has yet.

I'm not using ATL as you are, but from what you've posted I think your issue is it seems you are trying to poll the ingoing COM interfaces to detect activity from your 3Dx device. That would then make the performance dependant on your application & system resources, & I wouldn't be surprised if it bogs down your app.

Instead, I am connecting to the events dispinterfaces within the TDxInput COM library, which only fire when some device activity has occured, & feed that back to your app via the sink methods. I believe this is how the TDxInput lib was designed to be interfaced with. For an explanation of creating connection points into a COM lib's dispinterfaces, I found this article to be good for me:
http://www.codeproject.com/KB/COM/TEventHandler.aspx

If for some reason you still wish to keep the polling approach, maybe you could at least split it out to a different thread so it runs concurrently, as is done with serial port comms etc to stop them bogging the app down.

I hope this gives you some ideas. :)


Dave.
When I think of something profound & original to say, I'll cut & paste it here.
Post Reply