Ok I figured it out. I am posting the code for posterity:
void AddXForms (mgrec *node,Point translate,Vector3* axis, Float angle )
{
cout<<mgGetName(node)<<endl;
node = mgGetChild(node);
cout<<mgGetName(node)<<endl;
//Rotatemgrec* xformRotate = mgNewRec (fltXmRotate);
mgSetCoord3d (xformRotate, fltXmRotateCenter, 0, 0, 0);
mgSetAttList (xformRotate, fltXmRotateAngle, angle, mgNULL);
mgrec* nestedAttrib = mgGetAttRec(xformRotate,fltXmRotateAxis,MG_NULL);
mgSetAttList (nestedAttrib,
fltVectorI, axis->x,
fltVectorJ, axis->y,
fltVectorK, axis->z,
mgNULL);
mgAttach (node, xformRotate);
//Testfloat i, j, k;
double x, y, z;
mgrec* xrec = mgGetXform(node);
mgGetCoord3d (xrec, fltXmRotateCenter, &x, &y, &z);
printf ("RotateCenter: %f, %f, %f\n", x, y, z);
mgGetAttList (xrec,
fltVectorI, &i,
fltVectorJ, &j,
fltVectorK, &k,
mgNULL);
printf ("RotateAxis: %f, %f, %f\n", i, j, k);
printf ("RotateAxis should be this: %f, %f, %f\n", axis->x, axis->y, axis->z);
mgGetAttList (xrec, fltXmRotateAngle, ∠, mgNULL);
printf ("RotateAngle: %f\n", angle);
//Translate
mgrec* xformTranslate = mgNewRec(fltXmTranslate);
mgSetCoord3d(xformTranslate,fltXmTranslateFrom,0,0,0);
mgSetCoord3d(xformTranslate,fltXmTranslateDelta,translate.x,translate.y,translate.z);
//Puts the translation xform before the rotation xform
mgAttach(node,xformTranslate);
//Test
xrec = mgGetXform(node);
mgGetCoord3d (xrec, fltXmTranslateFrom, &x, &y, &z);
printf ("TranslateFrom xyz: %f, %f, %f\n", x, y, z);
mgGetCoord3d (xrec, fltXmTranslateDelta, &x, &y, &z);
printf ("TranslateDelta xyz: %f, %f, %f\n", x, y, z);
}
FYI, I found the answer in the API Ref manual in the FAQ section. "How do I access a value in a record nested inside another record?"
Alternatively, it may be more convenient to use mgSetVector and mgGetVector to set and get the record fltXmRotateAxis.
Craig
Hello,
I am having issues using fltXmRotate. I can set the fltXmRotateCenter and fltXmRotateAngle, but the fltXmRotateAxis doesn't take. Here is my code:
This is the output I get:
db
g1
RotateCenter: 0.000000, 0.000000, 0.000000
RotateAxis: 0.000000, 0.000000, 0.000000
RotateAxis should be this: -0.208057, 0.693214, -0.360366
RotateAngle: 3.902997
TranslateFrom xyz: 0.000000, 0.000000, 0.000000
TranslateDelta xyz: 577859.941915, 5497972.248549, 3170373.815528
As you can see my RotateAxis gets set to (0,0,0) and it should be (-0.208047,0.693214,-0.360366). What am I doing wrong? I am following the code from the User's Guide. Thanks in advance.