#include <iostream>
#include<fstream>
#include <string>
#include "dumbbell.h"
#include <cstdlib>
using namespace std;
Dumbbell::Dumbbell()
{
gp = new SoSeparator;
cp = new SoCylinder;
rgb = new RGBColor;
// tr = new Trans;
// ro = new Rotate;
}
SoSeparator *Dumbbell::makeDumbbell()
{
int seg[1000][7];
SoSeparator *segment[1000];
SoSeparator *buf[1000];
SoCylinder *cyl;
Trans *trn;
Rotate *rot;
ifstream input_file("data4d.out");
int n, s=0;
for(int k=1;k<=22; k++){
//cout << "k=" << k <<endl;
for(int j=1;j<=5; j++){
input_file >> n;
for(int i=0; i<n; i++){
seg[s][0]=n;
seg[s][5]=j;
seg[s][6]=k;
for(int l=1; l<5; l++){
input_file >> seg[s][l];
}
s++;
}
}
}
int smax =s-1;
/* for(int i=0; i<s; i++){
cout << endl;
for(int j=0;j<=6; j++){
cout << "seg[" << i << "][" << j << "]=" << seg[i][j] << endl;
}
}
*/
ifstream input_file2("data6d.out");
int bufa[1000][6], o=0;
for(int p=1;p<=17; p++){
//cout << "p=" << p <<endl;
for(int q=0;q<6; q++){
for(int r=0; r<4; r++){
bufa[o][4]=p;
//cout << bufa[o][4]<<endl;
bufa[o][5]=q;
bufa[o][6]=r;
// input_file2 >> bufa[o][q];
//cout << r<< endl;
}
o++;
}
}
int omax = o - 1;
/*cout << omax<<endl;
for(int i=0; i<o; i++){
cout << endl;
for(int j=0;j<=6; j++){
cout << "bufa[" << i << "][" << j << "]=" << bufa[i][j] << endl;
}
}
*/
int g;
printf("net number(1-22)->");
scanf("%d",&g);
for(int s=0; s<=smax; s++){
cout << "here s=" << s << endl;
double w=seg[s][3]-seg[s][1];
double h=seg[s][4]-seg[s][2];
double d=seg[s][5];
segment[s] = new SoSeparator;
trn = new Trans;
rot = new Rotate;
cyl = new SoCylinder;
if(seg[s][1] == seg[s][3]){
double a= seg[s][1]*2;
double b=(seg[s][2] + seg[s][4]);
double c= seg[s][5]*2;
if(g == seg[s][6])
segment[s]->addChild(rgb->ycolor());
else
segment[s]->addChild(rgb->rcolor());
segment[s] ->addChild(trn->trans(a,b,c));
segment[s]->addChild(rot->roty_m());
cyl->radius=0.2*2;
cyl->height =h*2;
}
if(seg[s][2] == seg[s][4]){
double d=(seg[s][1] + seg[s][3]);
double e =seg[s][2]*2;
double f= seg[s][5]*2;
if(g == seg[s][6])
segment[s]->addChild(rgb->ycolor());
else
segment[s]->addChild(rgb->bcolor());
segment[s]->addChild(trn->trans(d,e,f));
segment[s]->addChild(rot->rotx_p());
cyl->radius=0.2*2;
cyl->height =w*2;
}
segment[s]->addChild(cyl);
gp->addChild(segment[s]);
}
for(int o=0; o<=omax; o++){
buf[o] = new SoSeparator;
trn = new Trans;
rot = new Rotate;
// cyl = new SoCylinder;
if (buf!=0){
double x=bufa[o][4]*2;
double y=-(bufa[o][5]*2);
double z=r*2;
cout<<"Z=" << z<<endl;
buf[o]->addChild(rgb->wcolor());
buf[o]->addChild(trn->trans(x,y,z));
buf[o]->addChild(rot->rotz_p());
cyl = new SoCylinder;
cyl->radius=0.4;
cyl->height=1;
buf[o]->addChild(cyl);
gp->addChild(buf[o]);
}
}
return (gp);
}
Dumbbell::~Dumbbell()
{
}
読み込みを行った時のbufa[o][6]と
表示させる時のbufa[o][6]の値が変わってしまっています。
どこかおかしなところはありますか?