#include <cstdlib> #include <Inventor/SbTime.h> #include <Inventor/SoDB.h> #include <Inventor/SoInteraction.h> #include <Inventor/collision/SoIntersectionDetectionAction.h> #include <Inventor/errors/SoDebugError.h> #include <Inventor/nodekits/SoNodeKit.h> #include <Inventor/nodes/SoSeparator.h> static SoIntersectionDetectionAction::Resp intersectionCB(void * closure, const SoIntersectingPrimitive * pr1, const SoIntersectingPrimitive * pr2) { (void)fprintf(stdout, "intersection hit!/n"); return SoIntersectionDetectionAction::NEXT_PRIMITIVE; } int main(int argc, char ** argv) { SoDB::init(); SoNodeKit::init(); SoInteraction::init(); if (argc != 2) { (void)fprintf(stderr, "/n/tUsage: testapp <filename.iv>/n/n"); exit(1); } SoInput in; SbBool ok = in.openFile(argv[1]); assert(ok); SoSeparator * root = SoDB::readAll(&in); assert(root); root->ref(); SoIntersectionDetectionAction ida; ida.addIntersectionCallback(intersectionCB, NULL); ida.setManipsEnabled(FALSE); ida.setDraggersEnabled(FALSE); ida.setIntersectionDetectionEpsilon(10.0f); SbTime starttime = SbTime::getTimeOfDay(); SoDebugError::postInfo("main", "SoIntersectionDetectionAction::apply"); ida.apply(root); SoDebugError::postInfo("main", "apply() done after %f seconds.", (SbTime::getTimeOfDay() - starttime).getValue()); root->unref(); return 0; }
Open Inventor接触交互SoIntersectionDetectionAction
最新推荐文章于 2017-12-27 14:20:33 发布