//Get a bounding box. This is used for when we display the formation continously. void FormationBhvr::GetWorldBoundBox(TimeValue t, ViewExp *vpt, Box3& box) { if ( ! vpt || ! vpt->IsAlive() ) { box.Init(); return; } //make sure we have everything we need... if(DisplayFormation(t)==FALSE) return; if(GetFollowerCount(t)<=0) return; if(GetFollowerMatrixCount(t)<=0) return; //possible to not have this set when the follower is set.. INode *leaderNode; leaderNode = GetLeader(t); if(leaderNode==NULL) return; //for each follower we need to increase the bounding box by it's //world position location... for(int i =0;i<GetFollowerCount(t);i++) { if(GetFollower(t,i)) //if we have a a node... { Matrix3 worldSpace = GetFollowerMatrix(t,i)*GetCurrentMatrix(leaderNode,t); Point3 trans(worldSpace.GetTrans()); //expand the box by the worldposition... box += trans; } } }
//The display function that is used to display the formation. int FormationBhvr::Display(TimeValue t, ViewExp *vpt) { // setup int i,j; if(DisplayFormation(t)==FALSE) return FALSE; if(GetFollowerCount(t)<=0) return FALSE; if(GetFollowerMatrixCount(t)<=0) return FALSE; INode *leaderNode; leaderNode = GetLeader(t); if(leaderNode==NULL) return FALSE; //check tgo see if we have created a default sphere for drawing yet... //if we haven't then create it.. if (numpts == 0) GetSpherePoints(Point3(0.0f,0.0f,0.0f), 1.0, SpherePts); GraphicsWindow *gw = vpt->getGW(); //set the identity matrix... Matrix3 idMat; idMat.IdentityMatrix(); gw->setTransform(idMat); gw->setColor(LINE_COLOR,.815f,.976f,1.0f); float scaleRadius = GetDisplayScale(t); //set the drawing radius values based upon what the radius size is. for (i=0; i<NUMAROUND * 3; i++) ScaledPts[i] = ((SpherePts[i] * scaleRadius)); //for each follower we need to increase the bounding box by it's //world position location... for(i =0;i<GetFollowerCount(t);i++) { INode *followerNode = GetFollower(t,i); if(followerNode) //if we have a a node... { Matrix3 leaderMat = GetCurrentMatrix(leaderNode,t); leaderMat.NoScale(); Matrix3 followerMat = GetFollowerMatrix(t,i); Matrix3 worldSpace = followerMat *leaderMat; for (j=0; j<NUMAROUND * 3; j++) CurPts[j] = worldSpace*ScaledPts[j]; //adding the center to the point positions gw->polyline(NUMAROUND,&CurPts[0],NULL,NULL,TRUE,NULL); gw->polyline(NUMAROUND,&CurPts[NUMAROUND],NULL,NULL,TRUE,NULL); gw->polyline(NUMAROUND,&CurPts[NUMAROUND * 2],NULL,NULL,TRUE,NULL); } } return TRUE; }