VRML

canon

ドーナツ

#include<stdio.h> #include<math.h> main() { FILE *infp,*outfp; int i,j,n1,n2; float th1,th2; float PI=3.141592; float r,r1,r2,x1,y1,z1,x2,y2,z2; outfp=fopen("tamen.wrl","w"); n1=16; n2=16; r1=1.0; r2=5.0; printf("ドーナツを作るプログラムです。\n"); printf("太さは?"); scanf("%f",&r1); printf("直径は?"); scanf("%f",&r2); vrmlfaceset1(outfp); // Coordinateのpointを生成開始 for(j=0;j<n2;j++) { th2=2*PI*j/n2; r=r1*cos(th2)+r2; y1=r1*sin(th2); for(i=0;i<n1;i++) { th1=2*PI*i/n1; x1=r*cos(th1); z1=r*sin(th1); fprintf(outfp," %7.3f %7.3f %7.3f,\n",x1,y1,z1); } } // vrmlfaceset2(outfp); // CoordinateのcodeIndexを生成 for(j=0;j<n2;j++) { for(i=0;i<n1;i++) { fprintf(outfp," %d %d %d %d -1,\n",i+n1*j,i+n1*((j+1)%n2),(i+1)%n1+n1*((j+1)%n2),(i+1)%n1+n1*j); } } vrmlfaceset3(outfp); fclose(outfp); } // // vrmlfaceset functions // vrmlfaceset1(FILE *outfp) { fprintf(outfp,"#VRML V2.0 utf8 Background{ skyColor 0.9 0.9 1 } Transform{ translation 0 0 -10 children[ Shape{ appearance Appearance{ material Material{diffuseColor 1 0.6 0} } geometry IndexedFaceSet{ coord Coordinate{ point[ "); } vrmlfaceset2(FILE *outfp) { fprintf(outfp," ] } coordIndex[ "); } vrmlfaceset3(FILE *outfp) { fprintf(outfp," ] solid TRUE } } ] } "); }


上のドーナツにギザギザをつけてタイヤみたいにしたもの

#include<stdio.h> #include<math.h> main() { FILE *infp,*outfp; int i,j,n1,n2; float th1,th2; float PI=3.141592; float r,r1,r2,x1,y1,z1,x2,y2,z2; outfp=fopen("tamen.wrl","w"); n1=500; n2=100; r1=1.0; r2=5.0; /* printf("ドーナツを作るプログラムです。\n"); printf("太さは?"); scanf("%f",&r1); printf("直径は?"); scanf("%f",&r2); */ vrmlfaceset1(outfp); // Coordinateのpointを生成開始 for(j=0;j<n2;j++) { th2=2*PI*j/n2; r=r1*cos(th2)+r2*(1+0.01*sin(20*th2)); y1=r1*sin(th2); for(i=0;i<n1;i++) { th1=2*PI*i/n1; x1=r*cos(th1)*(1+0.01*sin(th1*n1/4+PI/4)); z1=r*sin(th1)*(1+0.01*sin(th1*n1/4+PI/4)); fprintf(outfp," %7.3f %7.3f %7.3f,\n",x1,y1,z1); } } // vrmlfaceset2(outfp); // CoordinateのcodeIndexを生成 for(j=0;j<n2;j++) { for(i=0;i<n1;i++) { fprintf(outfp," %d %d %d %d -1,\n",i+n1*j,i+n1*((j+1)%n2),(i+1)%n1+n1*((j+1)%n2),(i+1)%n1+n1*j); } } vrmlfaceset3(outfp); fclose(outfp); } // // vrmlfaceset functions // vrmlfaceset1(FILE *outfp) { fprintf(outfp,"#VRML V2.0 utf8 Background{ skyColor 0.9 0.9 1 } Transform{ translation 0 0 -10 children[ Shape{ appearance Appearance{ material Material{diffuseColor 1 0.6 0} } geometry IndexedFaceSet{ coord Coordinate{ point[ "); } vrmlfaceset2(FILE *outfp) { fprintf(outfp," ] } coordIndex[ "); } vrmlfaceset3(FILE *outfp) { fprintf(outfp," ] solid TRUE } } ] } "); }


自由に動かせる関節

#VRML V2.0 utf8 Background{ skyColor[1 1 1] } DEF Hako2 Transform{ translation 0 0 0 rotation 0 0 1 0 children[ DEF Sensor2 SphereSensor{}, Transform{ translation 0 -1 0 children[ Shape{ geometry Box{size 1 2 1} appearance Appearance{material Material{diffuseColor 1 1 0}} } DEF Hako Transform{ translation 0 -1 0 rotation 0 0 1 0 children[ DEF Sensor SphereSensor{}, Transform{ translation 0 -1 0 children[ Shape{ geometry Box{size 1 2 1} appearance Appearance{material Material{diffuseColor 0 1 1}} } ] } ] } ] } ] } ROUTE Sensor.rotation_changed TO Hako.set_rotation ROUTE Sensor2.rotation_changed TO Hako2.set_rotation