Re: [info-performer] Performer working with DOF

New Message Reply Date view Thread view Subject view Author view

From: Paolo Farinelli (paolo++at++sgi.com)
Date: 01/30/2003 17:12:46


Hi Chee Tzuon,

The flt loader for Performer automatically creates a pfDCS node in place
of each
DOF bead found in the .flt file. You can assign a name to your DOF bead
within
Creator, and look for it after having loaded the model using method
pfNode::find.

For example, if the DOF bead transforming your tank's turret is called
'turret' and
your tank model is called 'tank.flt', the following (libpfv-based)
program should
work:

#include <Performer/pfv/pfvViewer.h>
#include <Performer/pfdu.h>
#include <Performer/pf/pfDCS.h>
int main(int argc, char**argv){
  pfInit();
  pfvViewer* viewer = new pfvViewer;
  viewer->addModule(pfvModule::load("pfvmTrackball"));
  pfdInitConverter("flt");
  viewer->config();
  pfNode* root = pfdLoadFile("tank.flt");
  viewer->addNode(root);
  pfDCS* dcsTurret = (pfDCS*)root->find("turret",pfDCS::getClassType());
  float h = 0.0f;
  int revs = 0;
  while(revs<20){
    dcsTurret->setRot(h,0.0f,0.0f);
    if( (h+=2.0f) >= 360.0f ){
      revs++;
      h-=360.0f;
    }
    viewer->frame();
  }
  pfExit();
}

The main problem with the above solution is that it doesn't take into
account
the positioning matrix (putmat) associated with the DOF bead in the flt
file.
The above example would thus rotate the turret around the z-axis, even
if this
does not correspond to the z-axis as defined by the positioning matrix
assigned
to the DOF bead.
A work around for this particular example could be implemented within
creator,
by modelling the turret at the origin, and then translating it to its
position above
the tank through a translation component in its DOF's putmat.

Alternatively, you may need to bind a user callback to the flt loader.
This allows
you to inspect every single bead (a node in the flt hierarchy) as it is
loaded and
converted to performer objects.
When the turret DOF is being loaded, you can obtain and store the
associated putmat
(and putinvmat), which will allow you to rotate the turret around the
intended axis.

Here is an example of how to set this up:

#include <Performer/pfv/pfvViewer.h>
#include <Performer/pfdu.h>
#include <Performer/pf/pfDCS.h>
#include <Performer/pfdb/pfflt.h>

pfDCS* dcsTurret = NULL;
DOFcb* dofTurret = NULL;

void myFltCallBack( pfNode* node, int mgOp, int* cbs, COMMENTcb* cbcom,
void* userData ){
  switch ( mgOp ){
    case CB_DOF:
      if( !strcmp(node->getName(),"turret")){
        dcsTurret = (pfDCS*)node;
        dofTurret = (DOFcb*)cbs;
      }
    break;
    case CB_CLEANNODE:
      *cbs = TRUE;
    break;
    default:
      if ( cbs ) pfFree( cbs );
      if ( cbcom ) pfFree( cbcom );
    break;
  }
}

int main(int argc, char**argv){
  pfInit();
  pfvViewer* viewer = new pfvViewer;
  viewer->addModule(pfvModule::load("pfvmTrackball"));
  pfdInitConverter("flt");
  viewer->config();
  fltRegisterNodeT pFunc = myFltCallBack;
  void* hFunc = & pFunc;
  pfdConverterAttr( "flt", PFFLT_REGISTER_NODE, hFunc );
  pfNode* root = pfdLoadFile("tank.flt");
  viewer->addNode(root);
  float h = 0.0f;
  int revs = 0;
  while(revs<20){
    pfMatrix mat;
    mat.makeRot(h,0.0f,0.0f,1.0f);
    mat.preMult(dofTurret->putmat);
    mat.postMult(dofTurret->putinvmat);
    dcsTurret->setMat(mat);
    if( (h+=5.0f) >= 360.0f )
    {
      revs++;
      h-=360.0f;
    }
    viewer->frame();
  }
  pfExit();
}

Take a look at the
/usr/share/Performer/src/lib/libpfdb/libpfflt/README.FLT.R15_4
for more details on DOFs, DCSs and flt-loader user-callbacks.

Hope this helps, let me know if you need further assistance.

Regards,
Paolo

Chee Tzuon wrote:

>Hi all,
>
>I've this problem of implementing and working with the Degree Of Freedom
>data from a .FLT file.
>
>Is there any pf functions that i can use to do that.
>For example, i have a armoured tank object, if i want to rotate the turret
>while it is moving how can i go about doing that??
>
>I've tried using the pfDCS and pfSCS nodes but seem unable to add a DCS to
>DCS, only able to add a DCS to a SCS.
>
>Any solutions??
>
>Jason
>
>-----------------------------------------------------------------------
> List Archives, Info, FAQ: http://www.sgi.com/software/performer/
> Open Development Project: http://oss.sgi.com/projects/performer/
> Submissions: info-performer++at++sgi.com
> Admin. requests: info-performer-request++at++sgi.com
>-----------------------------------------------------------------------
>
>

-- 
Paolo Farinelli                                           paolo++at++sgi.com
Member of Technical Staff, OpenGL Performer              1-650-933-1808
Silicon Graphics        1600 Amphitheatre Pkwy, Mountain View, CA 94043


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Thu Jan 30 2003 - 17:12:55 PST

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.