Thank you for your advice.
Mike Heck wrote:
> As far as I know it works. You didn't say exactly what problem you
> are seeing or what code you are trying, but the most common problem
> is doing static intialization of an array of complex objects. In
> this case it's particularly tricky because constructing an SbRotation
> from four floats causes the floats to be interpreted as a quaternion
> (rather than axis/angle). I've found it easier/safer to use the
> set1Value method instead, like this:
>
> const int numval = 3;
> static float axis[][3] = {{1,0,0},{0,1,0},{0,0,1}};
> static float angle[] = {0, 3.14f, 3.14f};
> SoVRMLOrientationInterpolator *pNode = new SoVRMLOrientationInterpolator;
> for (int i = 0; i < numval; i++) {
> pNode->keyValue.set1Value( i, SbRotation(axis[i],angle[i]) );
> }
>
> -Mike
> TGS Inc, http://www.tgs.com
What I would like to do is to make a simple animation that a cone rotates.
I was able to set rotation values to keyValue filed. But still, my program
doesn't
work. Could you tell me what the problem is?
Following are the sorce code. I am using TGS OIV 2.6 on Windows 98.
#include <Inventor/Xt/SoXt.h>
#include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
#include <Inventor/VRMLnodes/SoVRMLCone.h>
#include <Inventor/VRMLnodes/SoVRMLDirectionalLight.h>
#include <Inventor/VRMLnodes/SoVRMLMaterial.h>
#include <Inventor/VRMLnodes/SoVRMLAppearance.h>
#include <Inventor/VRMLnodes/SoVRMLShape.h>
#include <Inventor/VRMLnodes/SoVRMLGroup.h>
#include <Inventor/VRMLnodes/SoVRMLOrientationInterpolator.h>
#include <Inventor/SbLinear.h>
#include <Inventor/nodes/SoTransform.h>
#include <Inventor/sensors/SoTimerSensor.h>
#include <Inventor/VRMLnodes/SoVRMLTimeSensor.h>
#include <Inventor/VRMLnodes/SoVRMLTransform.h>
#include <Inventor/SoDB.h>
#ifdef WIN32
#define main ivMain
#endif
void
main(int , char **argv)
{
// Initialize Inventor. This returns a main window to use.
// If unsuccessful, exit.
Widget myWindow = SoXt::init(argv[0]); // pass the app name
if (myWindow == NULL) exit(1);
SoVRMLGroup *root = new SoVRMLGroup;
SoVRMLMaterial *myMaterial = new SoVRMLMaterial;
SoVRMLAppearance *myAppearance = new SoVRMLAppearance;
SoVRMLShape *myShape = new SoVRMLShape;
SoVRMLCone *myCone = new SoVRMLCone;
SoVRMLOrientationInterpolator *myOriInter = new
SoVRMLOrientationInterpolator;
SoVRMLTransform *mytrans = new SoVRMLTransform;
SoVRMLTimeSensor *myTimer = new SoVRMLTimeSensor;
//refrence the root nodes
root->ref();
//set a light
root->addChild(new SoVRMLDirectionalLight);
//set a TimeSensor
myTimer->cycleInterval.setValue(2.0);
myTimer->loop.setValue(True);
root->addChild(myTimer);
//set a Transform nodes
root->addChild(mytrans);
//set a interpolater node
const float val[]={0,1};
myOriInter->key.setValues(0,2,val);
const int numval = 3;
static float axis[][3] = {{0,1,0},{0,1,0},{0,0,1}};
static float angle[] = {0, 3.14f, 3.14f};
for (int i = 0; i < numval; i++)
myOriInter->keyValue.set1Value( i,SbRotation(axis[i],angle[i]) );
root->addChild(myOriInter);
//connect myOriInter to mytrans and myTimer
SoDB::createRoute(myTimer,"fraction_changed",myOriInter,"set_fraction");
SoDB::createRoute(myOriInter,"value_changed",mytrans,"rotation_changed");
//set Shape of an Object
myMaterial->diffuseColor.setValue(1.0, 0.0, 0.0); //Red
myAppearance->material.setValue(myMaterial);
myShape->appearance.setValue(myAppearance);
myShape->geometry.setValue(myCone);
root->addChild(myShape);
// Create an Examiner Viewer in which to see our scene graph.
SoXtExaminerViewer *myViewer =
new SoXtExaminerViewer(myWindow);
myViewer->setSceneGraph(root);
myViewer->setTitle("Cone");
myViewer->show();
myViewer->viewAll();
SoXt::show(myWindow); // Display main window
SoXt::mainLoop(); // Main Inventor event loop
}
--
*****************************************
Hiroshi akiba
University of Tsukuba
Computer Vision & Image Media LAB
TEL 090-2665-0049
E-mail: akiba@xxxxxxxxxxxxxxxxxxxxxxxx
******************************************
|