- Joined
- Jan 13, 2008
- Messages
- 2,302
- Reaction score
- 6
- Points
- 38
- Location
- Atlanta, GA, USA, North America
I have been struggling mightily with creating the radiator animation for my truss system. I've narrowed down the problem to something going badly wrong with the parent animations when applied to different meshes. I've done back and forth style animations before, most notably in my Solar Service Module, but on the same mesh, just different mesh groups. Because it doesn't appear Wings3d spits out its model groups in order, the resultant mesh doesn't have the groups in order so that I can use a for loop to create the animations just incrementing the group index each time. So my solution was to separate the vessel into multiple meshes, add each mesh in the loop, and use the resultant UINT returned from AddMesh in the mesh number parameter when constructing my MGROUP_TRANSFORMs and only having to know a few mesh group numbers.
Here's the code in question:
I've checked my numbers multiple times and the coordinates are correct, but the result of that code is this:
It's a simple zig-zag animation, but the support arms aren't rotating about the ends like they're supposed to. I've only tried to animate one of the panels so far, and it's not the parent of anything yet. Does anyone see anything wrong with my code or know of a problem doing animations like this?
Thanks for any help,
Matt
Here's the code in question:
Code:
//The Header file
MGROUP_ROTATE* supports[4][16];
MGROUP_ROTATE* panels[4][16];
ANIMATIONCOMPONENT_HANDLE supportanims[4][16];
ANIMATIONCOMPONENT_HANDLE panelanims[4][16];
//The .cpp file
void Truss::setRadAnims(void)
{
radiatoranimation=CreateAnimation(0.0);
static UINT group1[2]={16,18};
//supports[0][0] = new MGROUP_ROTATE(0,group1,2,_V(1.455,0.85,0.23),_V(1,0,0),(float)60*(float)RAD);
static MGROUP_ROTATE sup(0,group1,2,_V(1.455,0.85,0.23),_V(1,0,0),(float)60*(float)RAD); //Newing or using a static MGROUP_ROTATE yielded the same result
supportanims[0][0] = AddAnimationComponent(radiatoranimation,0,1,&sup);
static UINT group2[2] = {4};
panels[0][0] = new MGROUP_ROTATE(0,group2,1,_V(1.455,.845,0),_V(-1,0,0),(float)120*(float)RAD);
panelanims[0][0] = AddAnimationComponent(radiatoranimation,0,1,panels[0][0],supportanims[0][0]);
[COLOR="Green"]//The following animations have been commented out in order to focus on one problem at a time
/*static UINT group3[2] = {22,20};
supports[1][0] = new MGROUP_ROTATE(0,group3,2,_V(-1.455,.85,0.23),_V(1,0,0),(float)60*(float)RAD);
supportanims[1][0] = AddAnimationComponent(radiatoranimation,0,1,supports[1][0]);
static UINT group4[1] = {6};
panels[1][0] = new MGROUP_ROTATE(0,group4,1,_V(-1.455,.845,0),_V(-1,0,0),(float)120*(float)RAD);
panelanims[1][0] = AddAnimationComponent(radiatoranimation,0,1,panels[1][0],supportanims[1][0]);
static UINT group5[2] = {14,12};
supports[2][0] = new MGROUP_ROTATE(0,group5,2,_V(1.455,-.85,0.23),_V(1,0,0),(float)60*(float)RAD);
supportanims[2][0] = AddAnimationComponent(radiatoranimation,0,1,supports[2][0]);
static UINT group6[1] = {2};
panels[2][0] = new MGROUP_ROTATE(0,group6,1,_V(1.455,-.845,0),_V(-1,0,0),(float)120*(float)RAD);
panelanims[2][0] = AddAnimationComponent(radiatoranimation,0,1,panels[2][0],supportanims[2][0]);
static UINT group7[2] = {10,8};
supports[3][0] = new MGROUP_ROTATE(0,group7,2,_V(-1.455,-.85,0.23),_V(1,0,0),(float)60*(float)RAD);
supportanims[3][0] = AddAnimationComponent(radiatoranimation,0,1,supports[3][0]);
static UINT group8[1] = {0};
//group[0] = 0;
panels[3][0] = new MGROUP_ROTATE(0,group8,1,_V(-1.455,-.845,0),_V(-1,0,0),(float)120*(float)RAD);
panelanims[3][0] = AddAnimationComponent(radiatoranimation,0,1,panels[3][0],supportanims[3][0]);*/[/COLOR]
static UINT groupl[16][3];
for(int i = 1; i<15; i++)
{
double side = pow((double)(-1),(int)i); //flip the sign each iteration
char tempblargh[256]; //yes, real creative name isn't it?
sprintf(tempblargh,"%lf",side);
oapiWriteLog(tempblargh); //print side to enure that part is working right
char tempmesh[256]; //another real creative name
sprintf(tempmesh,"Truss\\radpanel%d",i%2); //only two meshes, radpanel0 or radpanel1, are used
UINT msh = AddMesh(tempmesh,&_V(1.45522,.835+(i*0.01),0)); //add the mesh and get the mesh index
groupl[i][0] = 0;
groupl[i][1] = 2;
supports[0][i] = new MGROUP_ROTATE(msh,groupl[i],2,_V(1.455,(0.01*i)+0.84,(side)*0.2325),_V(1,0,0),(float)(side*120)*(float)RAD);
supportanims[0][i] = AddAnimationComponent(radiatoranimation,0,1,supports[0][i],supportanims[0][i-1]);
sprintf(tempblargh,"Y-pos: %lf; Z-pos: %lf",(0.01*i)+0.84,supports[0][i]->ref.z); //make sure the animation axis reference positions are correct (they are)
oapiWriteLog(tempblargh);
groupl[i][2] = 1;
panels[0][i] = new MGROUP_ROTATE(msh,groupl[i]+2,1,_V(1.455,.835+(.01*i),0),_V(1,0,0),(float)(-side*240)*(float)RAD);
panelanims[0][i] = AddAnimationComponent(radiatoranimation,0,1,panels[0][i],supportanims[0][i]);
[COLOR="Green"]//The following part of the loop is commented out in order to focus on one problem at a time
/*msh = AddMesh(tempmesh,&_V(-1.455,.845+(i*.01),0));
supports[1][i] = new MGROUP_ROTATE(msh,groupl[i],2,_V(-1.455,.84+(.01*i),-0.232),_V(1,0,0),(float)120*(float)RAD);
supportanims[1][i] = AddAnimationComponent(radiatoranimation,0,1,supports[1][i],supportanims[1][i-1]);
//group[0] = 1;
panels[1][i] = new MGROUP_ROTATE(msh,groupl[i]+2,1,_V(-1.455,.835+(.01*i),0),_V(-1,0,0),(float)240*(float)RAD);
panelanims[1][i] = AddAnimationComponent(radiatoranimation,0,1,panels[1][i],supportanims[1][i]);
sprintf(tempmesh,"Truss\\radpanel%d",(i+1)%2);
msh = AddMesh(tempmesh,&_V(1.455,-.845-(i*.01),0));
supports[2][i] = new MGROUP_ROTATE(msh,groupl[i],2,_V(1.455,-.84-(.01*i),0.232),_V(1,0,0),(float)120*(float)RAD);
supportanims[2][i] = AddAnimationComponent(radiatoranimation,0,1,supports[2][i],supportanims[2][i-1]);
//group[0] = 1;
panels[2][i] = new MGROUP_ROTATE(msh,groupl[i]+2,1,_V(1.455,-.835-(.01*i),0),_V(-1,0,0),(float)240*(float)RAD);
panelanims[2][i] = AddAnimationComponent(radiatoranimation,0,1,panels[2][i],supportanims[2][i]);
msh = AddMesh(tempmesh,&_V(-1.455,-.845-(i*.01),0));
//group[0] = 0; //change later
//group[1] = 2; //change later
supports[3][i] = new MGROUP_ROTATE(msh,groupl[i],2,_V(-1.455,-.84-(.01*i),0.232),_V(1,0,0),(float)120*(float)RAD);
supportanims[3][i] = AddAnimationComponent(radiatoranimation,0,1,supports[3][i],supportanims[3][i-1]);
//group[0] = 1;
panels[3][i] = new MGROUP_ROTATE(msh,groupl[i]+2,1,_V(-1.455,-.835-(.01*i),0),_V(-1,0,0),(float)240*(float)RAD);
panelanims[3][i] = AddAnimationComponent(radiatoranimation,0,1,panels[3][i],supportanims[3][i]);*/[/COLOR]
}
static UINT group9[2] = {17,19};
//group[0] = 17; //change later
//group[1] = 19; //change later
supports[0][15] = new MGROUP_ROTATE(0,group9,2,_V(1.455,.839008,0.232871),_V(1,0,0),(float)120*(float)RAD);
supportanims[0][15] = AddAnimationComponent(radiatoranimation,0,1,supports[0][15],supportanims[0][14]);
static UINT group10[1] = {5};
panels[0][15] = new MGROUP_ROTATE(0,group10,1,_V(1.455,.839008,0.235),_V(1,0,0),(float)-180*(float)RAD);
panelanims[0][15] = AddAnimationComponent(radiatoranimation,0,1,panels[0][15],supportanims[0][15]);
[COLOR="Green"] //The following code commented out to focus on one problem at a time
/*static UINT group11[2] = {21,23};
supports[1][15] = new MGROUP_ROTATE(0,group11,2,_V(-1.455,.839008,0.232871),_V(1,0,0),(float)180*(float)RAD);
supportanims[1][15] = AddAnimationComponent(radiatoranimation,0,1,supports[1][15],supportanims[1][14]);
static UINT group12[1] = {7};
panels[1][15] = new MGROUP_ROTATE(0,group12,1,_V(-1.455,.839008,0.235),_V(1,0,0),(float)-180*(float)RAD);
panelanims[1][15] = AddAnimationComponent(radiatoranimation,0,1,panels[1][15],supportanims[1][15]);
//msh = AddMesh(tempmesh,_V(1.455,-.845-i*.01,0));
static UINT group13[2] = {13,15};
//group[0] = 13; //change later
//group[1] = 15; //change later
supports[2][15] = new MGROUP_ROTATE(0,group13,2,_V(1.455,-.839008,0.232871),_V(1,0,0),(float)90*(float)RAD);
supportanims[2][15] = AddAnimationComponent(radiatoranimation,0,1,supports[2][15],supportanims[2][14]);
static UINT group14[1] = {3};
panels[2][15] = new MGROUP_ROTATE(0,group14,1,_V(1.455,.839008,0.235),_V(1,0,0),(float)-90*(float)RAD);
panelanims[2][15] = AddAnimationComponent(radiatoranimation,0,1,panels[2][15],supportanims[2][15]);
//msh = AddMesh(tempmesh,_V(-1.455,-.845-i*.01,0));
static UINT group15[2] = {9,11};
//group[0] = 9; //change later
//group[1] = 11; //change later
supports[3][15] = new MGROUP_ROTATE(0,group15,2,_V(-1.455,-.839008,0.232871),_V(1,0,0),(float)90*(float)RAD);
supportanims[3][15] = AddAnimationComponent(radiatoranimation,0,1,supports[3][15],supportanims[3][14]);
static UINT group16[2] = {1};
panels[3][15] = new MGROUP_ROTATE(0,group16,1,_V(-1.455,.849008,0.235),_V(1,0,0),(float)-90*(float)RAD);
panelanims[3][15] = AddAnimationComponent(radiatoranimation,0,1,panels[3][15],supportanims[3][15]);*/
}[/COLOR]
It's a simple zig-zag animation, but the support arms aren't rotating about the ends like they're supposed to. I've only tried to animate one of the panels so far, and it's not the parent of anything yet. Does anyone see anything wrong with my code or know of a problem doing animations like this?
Thanks for any help,
Matt
Last edited: