encode Shift_JIS;
/*
================================================
631truncationDodecaIcosahedron / 120319
================================================
*/
//==============================================
import Graphics;
import Graphics3D;
import GUI;
import Math ;
int BG_RED = 255 ;
int BG_GREEN = 255 ;
int BG_BLUE = 255 ;
//----------------------------------------------
int MAIN_GRAPHICS
, MAIN_WINDOW
, MAIN_DISPLAY_LABEL
, RENDERER ;
bool ROOP = true ;
//----------------------------------------------
int WIDTH;
int HEIGHT;//画面の縦横
WIDTH=
(int
)(256*3.0
); HEIGHT=
(int
)(256*2.25
);
int WndPstX=900-WIDTH;
//----------------------------------------------
// ウィンドウの構築などの初期化処理を行う関数、メインプログラムから呼び出す
void G3D_INIT
( ){MAIN_GRAPHICS =
newGraphics( ) ; RENDERER =
newGraphics3DRenderer( WIDTH
, HEIGHT
, MAIN_GRAPHICS
) ;
MAIN_WINDOW =
newWindow(WndPstX
, 0
, WIDTH+14
, HEIGHT+39
, " Hello 3DCG ! "
);
MAIN_DISPLAY_LABEL =
newGraphicsLabel( 0
, 0
, WIDTH
, HEIGHT
, MAIN_GRAPHICS
) ;
addComponent( MAIN_DISPLAY_LABEL
, MAIN_WINDOW
);
setGraphics3DDefaultEventHandler( RENDERER
, MAIN_DISPLAY_LABEL
) ;
setGraphics3DColor( RENDERER
, BG_RED
, BG_GREEN
, BG_BLUE
, 255
) ;
int light =
newLight( 1.2
, 1.5
, 1.0
, 0.8
) ;
addLight( light
, RENDERER
) ;
}
// ウィンドウを閉じた際に呼び出される関数
void onWindowClose
( int id
){ROOP = false ;
} //ループを脱出
hide
();
//==============================================
float nbw=o;//背景色(1.0-0.0)
int rrate=20;//1秒間にループを回る回数*sec
float t=0.0;//時刻カウンタ変数
float flowt=1.0;//時間の流れの速さ
float step=flowt/
(float
)rrate;
int picid=10000*5;//save id
int picnumber=1;//file id
int TIME_END = 2000 ; // アニメーションの終了枚数
//----------------------------------------------
BG_RED =
(int
)255*nbw; BG_GREEN =
(int
)255*nbw; BG_BLUE =
(int
)255*nbw;
G3D_INIT
() ; // 3D画面を起動
//==============================================
int Nre=2;//設定数
int Opcty
[Nre
]=255;//表不透明度
float Emssv
[Nre
]=0.1;//Emissive
(1.0-0.0
)
float Dffrctv
[Nre
]=0.5;//Diffractive
(1.0-0.0
)
float Dffs
[Nre
]=1.0;//Diffuse
(1.0-0.0
)
float SpclrAngl
[Nre
]=1.3;//Specular angle
(1.5-0.0
)
float SpclrRf
[Nre
]=1.0;//Specular ref
(1.0-0.0
)
float Ambnt
[Nre
]=0.0;//Ambient
(1.0-0.0
)
for(int i=0; i<=Nre-1; i++
){
Opcty
[i
]=255;
Emssv
[i
]=0.1; Dffrctv
[i
]=0.7; Dffs
[i
]=0.5; Ambnt
[i
]=0.2;
SpclrAngl
[i
]=1.2; SpclrRf
[i
]=0.5;
}
//==============================================
float o=0.0;
float Gld=2*
sin(0.3*PI
);
float Slv=2^0.5;
float IGld=Gld-1.0;
float ISlv=Slv/2;
float ATGl=
atan(Gld
)/PI;
float ATIG=
atan(IGld
)/PI;
float ATSl=
atan(Slv
)/PI;
float ATIS=
atan(ISlv
)/PI;
float a=1.0;
float s=o*a; a=a-s;//aより一回り小さくして計算
int txt=
newTextPolygon(o
, o
, o
, 0.2*a
, "http://rusen.seesaa.net/"
);
setPolygonColor(txt
, 0
, 0
, 0
, 0
);
//==============================================
//element
int N3=100;//3d
int N2V3=12;//3dあたりの2d
int N2=N2V3*N3;//2d
int NTV2=10+5*2;//2dあたりのTrianglePolygon
int N1V2;
int N1;//1d
int N0V2=11;//2dあたりの0d
int N0V3=14;//3dあたりの0d
int N0=N0V3*N3;//0d
//==============================================
//座標系の生成と配置
//bcd on gcd on hcd
int hcd=
newCoordinate();
addCoordinate(hcd
, RENDERER
);
int gcd=
newCoordinate();
addCoordinate(gcd
, RENDERER
, hcd
);
int bcd=
newCoordinate();
addCoordinate(bcd
, RENDERER
, gcd
);
int bc
[N3
];
int cd
[N3
][N2V3
];
for(int i=0; i<=N3-1; i++
){
bc
[i
]=
newCoordinate();
addCoordinate(bc
[i
], RENDERER
, bcd
);
for(int j=0; j<=N2V3-1; j++
){
cd
[i
][j
]=
newCoordinate();
addCoordinate(cd
[i
][j
], RENDERER
, bc
[i
]);
}
}
//==============================================
//calclation
(1
)
float RdCP=a;//Radius of circumscribed circle of Pentagon
float CAnD=PI/5;//Central Angle of Decagon
float TnOm=Gld-1.0;//正五角形面心、正十二面体中心、正五角形辺心の角度
float RdID;//Radius of inscribed Sphere of dodecahedron
RdID=
((Gld+1.0
)/2
)*RdCP;
//==============================================
//calclation
(2
)
//dodecahedronと切頂してえられる三角形の1/3
int PCVc;//Pentagon Center Vector
int TCVc;//Triangle Center Vector
, truncated part
int VrVc;//Vertex Vector
,truncated dodecahedron
float TrnAng=o;//angle
for truncation
PCVc=
newVector(o
, o
, RdID
);
TCVc=
newVector(o
, RdCP*TrnFnc
(TrnAng
), RdID*TrnFnc
(TrnAng
));
VrVc=
newVector(-RdsVct
(TrnAng
)*
sin(TrnAng
), RdsVct
(TrnAng
)*
cos(TrnAng
), RdID
);
//切頂面の中心を、多面体中心を始点とするpentagonの頂点ベクトルのTrncFn倍として与える
float TrnFnc
(float angle
){
float yvalue=RdsVct
(angle
)*
cos(angle
);
return
(RdCP*yvalue+RdID^2
)/
(RdCP^2+RdID^2
);
}
//RdsVct
, Radius Vector of Pentagon side
float RdsVct
(float angle
){
return RdCP*Gld/
(Gld*
cos(angle
)+
((3.0-Gld
)^0.5
)*
sin(angle
));
}
//==============================================
//calclation
(3
)
//ET
[][][]指定用vetor
int 0dVc
[11+5*2
];
for(int i=0; i<=20; i++
){0dVc
[i
]=
newVector();
}
St0dVc
();
//0dVcをsetする関数
void St0dVc
(){
int CSVc=
newVector();//Center of pentagon Side
setVector(CSVc
,
-Gld*
((3.0-Gld
)^0.5
)*RdCP/4
,
(Gld+1.0
)*RdCP/4
,
(Gld+1.0
)*RdCP/2
);
int oddVertex=
newVector(VrVc
);
rotZVector(oddVertex
, 2*CAnD-2*TrnAng
);
for(int i=0; i<=9; i++
){
if(i%2==0
){
if(i>0
){rotZVector
(VrVc
, 2*CAnD
);
}
setVector(0dVc
[i
], VrVc
);
}else{
if(i>1
){rotZVector
(oddVertex
, 2*CAnD
);
}
setVector(0dVc
[i
], oddVertex
);
}
}
int i=10;
setVector(0dVc
[i
], PCVc
);
for(int i=11; i<=15; i++
){
if(i>11
){rotZVector
(TCVc
, 2*CAnD
);
}
setVector(0dVc
[i
], TCVc
);
}
for(int i=16; i<=20; i++
){
if(i>16
){rotZVector
(CSVc
, 2*CAnD
);
}
setVector(0dVc
[i
], CSVc
);
}
}
//truncated icosahedronのときの0dVcをsetする関数
float TrnPrmtr=o;
void St0dVcTrnIcs
(){
float pntgoncntrz=
((Gld+1.0
)/2+TrnPrmtr/2
)*RdCP;
setVector(PCVc
, o
, o
, pntgoncntrz
);
setVector(TCVc
, o
, RdCP*TrnFnc
(CAnD
), RdID*TrnFnc
(CAnD
));
setVector(VrVc
,
-Gld*
((3.0-Gld
)^0.5
)*RdCP*
(1.0-TrnPrmtr
)/4
,
(Gld+1.0
)*RdCP*
(1.0-TrnPrmtr
)/4
,
pntgoncntrz
);
int CSVc=
newVector();//Center of pentagon Side
setVector(CSVc
,
-Gld*
((3.0-Gld
)^0.5
)*RdCP/4
,
(Gld+1.0
)*RdCP/4
,
(Gld+1.0
)*RdCP/2
);
int i=10;
setVector(0dVc
[i
], PCVc
);
for(int i=11; i<=15; i++
){//正十二面体切頂部分の三角形の重心
if(i>11
){rotZVector
(TCVc
, 2*CAnD
);
}
setVector(0dVc
[i
], TCVc
);
}
for(int i=0; i<=9; i++
){//0〜9はpentagonの頂点
if((i>0
)&&
(i%2==0
)){rotZVector
(VrVc
, 2*CAnD
);
}
setVector(0dVc
[i
], VrVc
);
}
for(int i=16; i<=20; i++
){//16〜20はicosidodecahedronの頂点
if(i>16
){rotZVector
(CSVc
, 2*CAnD
);
}
setVector(0dVc
[i
], CSVc
);
}
}
//==============================================
//calclation
(3
)
//coordiate attitude
for(int j=0; j<=N3-1; j++
){//first solid
for(int i=1; i<=5; i++
){
SZC
(cd
[j
][i
], (2*i-1
)*CAnD/PI
);
SXC
(cd
[j
][i
], -2*
atan(TnOm
)/PI
);
}
for(int i=1; i<=5; i++
){
SZC
(cd
[j
][5+i
], (2*i-1
)*CAnD/PI
);
SXC
(cd
[j
][5+i
], -2*
atan(TnOm
)/PI
);
SZC
(cd
[j
][5+i
], CAnD/PI
);
SXC
(cd
[j
][5+i
], -2*
atan(TnOm
)/PI
);
}
{int i=11;
SZC
(cd
[j
][i
], CAnD/PI
);
SXC
(cd
[j
][i
], -2*
atan(TnOm
)/PI
);
SZC
(cd
[j
][i
], CAnD/PI
);
SXC
(cd
[j
][i
], -2*
atan(TnOm
)/PI
);
SZC
(cd
[j
][i
], -CAnD/PI
);
SXC
(cd
[j
][i
], -2*
atan(TnOm
)/PI
);
}
}
void StSystmOrgn
(){//set bc Origin
float smmtn
[3
]; smmtn=o;
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=2; j++
){
smmtn
[j
]=smmtn
[j
]+bcOgn
[i
][j
];
}}
smmtn=smmtn/N3;
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=2; j++
){
bcOgn
[i
][j
]=bcOgn
[i
][j
]-smmtn
[j
];
}
SCO
(bc
[i
], bcOgn
[i
][0
], bcOgn
[i
][1
], bcOgn
[i
][2
]);
}
}
//bc
[ix0
]をbc
[ix1
]に重ねる関数
void SprCrd
(int ix0
, int ix1
){
float aang=GCEAA
(bc
[ix1
])/PI;
float bang=GCEAB
(bc
[ix1
])/PI;
float gang=GCEAG
(bc
[ix1
])/PI;
float xcrd=GCOX
(bc
[ix1
]);
float ycrd=GCOY
(bc
[ix1
]);
float zcrd=GCOZ
(bc
[ix1
]);
SCEA
(bc
[ix0
], aang
, bang
, gang
);
SCO
(bc
[ix0
], xcrd
, ycrd
, zcrd
);
}
//El3d
[ix0
]をEl3d
[ix1
]のix2面に接合させる関数
void CncSld
(int ix0
, int ix1
, int ix2
){
SprCrd
(ix0
, ix1
);
if(ix2==0
){
}else
if(ix2<6
){
SZC
(bc
[ix0
], (2*ix2-1
)*CAnD/PI
);
SXC
(bc
[ix0
], -2*
atan(TnOm
)/PI
);
}else
if(ix2<11
){
SZC
(bc
[ix0
], (2*
(ix2-5
)-1
)*CAnD/PI
);
SXC
(bc
[ix0
], -2*
atan(TnOm
)/PI
);
SZC
(bc
[ix0
], -CAnD/PI
);
SXC
(bc
[ix0
], -2*
atan(TnOm
)/PI
);
}else{
SYC
(bc
[ix0
], 1.0
);
SZC
(bc
[ix0
], 1.0
);
}
SZC
(bc
[ix0
], CAnD/PI
);
walkCoordinate(bc
[ix0
], o
, o
, 2*RdID
);
}
//==============================================
//TrianglePolygon
int ET
[N3
][N2V3
][NTV2
];
void StET
(int ix0
, int ix1
){
for(int i=0; i<=4; i++
){
int j;
if(i<4
){j=2*i+2;
}else{j=0;
}
ET
[ix0
][ix1
][i
]=
newTrianglePolygon(0dVc
[10
], 0dVc
[2*i+1
], 0dVc
[j
]);
ET
[ix0
][ix1
][5+2*i
]=
newTrianglePolygon(0dVc
[10
], 0dVc
[2*i
], 0dVc
[i+16
]);
ET
[ix0
][ix1
][5+2*i+1
]=
newTrianglePolygon(0dVc
[10
], 0dVc
[i+16
], 0dVc
[2*i+1
]);
}
for(int i=0; i<=4; i++
){//切頂部分の三角形
int j;
if(i>0
){j=2*i-1;
}else{j=9;
}
ET
[ix0
][ix1
][15+i
]=
newTrianglePolygon(0dVc
[11+i
], 0dVc
[2*i
], 0dVc
[j
]);
}
}
void StPlgnVctrTrnIcs
(int ix0
, int ix1
){
for(int i=0; i<=4; i++
){//truncated part of icosahedron
int j;
if(i<4
){j=2*i+2;
}else{j=0;
}
setPolygonVector(ET
[ix0
][ix1
][i
], 0dVc
[10
], 0dVc
[2*i
], 0dVc
[j
]);
int k;
if(i>0
){k=2*i-1;
}else{k=9;
}
int l;
if(i>0
){l=16+i-1;
}else{l=20;
}
setPolygonVector(ET
[ix0
][ix1
][5+2*i
], 0dVc
[11+i
], 0dVc
[k
], 0dVc
[l
]);
setPolygonVector(ET
[ix0
][ix1
][5+2*i+1
], 0dVc
[11+i
], 0dVc
[16+i
], 0dVc
[2*i
]);
int m;
if(i>0
){m=2*i-1;
}else{m=9;
}
setPolygonVector(ET
[ix0
][ix1
][15+i
], 0dVc
[11+i
], 0dVc
[2*i
], 0dVc
[m
]);
}
}
void PntDdc
(int ix0
, int ix1
, int ix2
){cdx0=11; cdx1=10;
if(ix2<15
){SPCAuto
(ET
[ix0
][ix1
][ix2
], Opcty
[0
], cdx0+2*ix0
, 24
);
}
else{SPCAuto
(ET
[ix0
][ix1
][ix2
], Opcty
[0
], cdx1+2*ix0
, 12
);
}
}
void PntIcs
(int ix0
, int ix1
, int ix2
){cdx0=11; cdx1=10;
if(ix2<5
){SPCAuto
(ET
[ix0
][ix1
][ix2
], Opcty
[0
], cdx0+2*ix0
, 24
);
}
else{SPCAuto
(ET
[ix0
][ix1
][ix2
], Opcty
[0
], cdx1+2*ix0
, 12
);
}
}
void PntFcbfc
(int ix0
){
for(int k=0; k<=14; k++
){
SPCAuto
(ET
[ix0
][0
][k
], Opcty
[0
], 3
, 6
);
SPCAuto
(ET
[ix0
][1
][k
], Opcty
[0
], 4
, 6
);
SPCAuto
(ET
[ix0
][2
][k
], Opcty
[0
], 5
, 6
);
SPCAuto
(ET
[ix0
][3
][k
], Opcty
[0
], 0
, 6
);
SPCAuto
(ET
[ix0
][4
][k
], Opcty
[0
], 1
, 6
);
SPCAuto
(ET
[ix0
][5
][k
], Opcty
[0
], 2
, 6
);
}
}
void AdET
(int ix0
, int ix1
){
for(int i=0; i<=NTV2-1; i++
){
setPolygonCull(ET
[ix0
][ix1
][i
], false
, false
);
SPPht
(ET
[ix0
][ix1
][i
], Emssv
[0
], SpclrRf
[0
], SpclrAngl
[0
], Dffrctv
[0
], Dffs
[0
], Ambnt
[0
]);
PntDdc
(ix0
, ix1
, i
);
AP
(ET
[ix0
][ix1
][i
], cd
[ix0
][ix1
]);
}
}
void StETVctr
(int ix0
, int ix1
){
for(int i=0; i<=4; i++
){
int j;
if(i<4
){j=2*i+2;
}else{j=0;
}
setPolygonVector(ET
[ix0
][ix1
][i
], 0dVc
[10
], 0dVc
[2*i+1
], 0dVc
[j
]);
setPolygonVector(ET
[ix0
][ix1
][5+2*i
], 0dVc
[10
], 0dVc
[2*i
], 0dVc
[i+16
]);
setPolygonVector(ET
[ix0
][ix1
][5+2*i+1
], 0dVc
[10
], 0dVc
[i+16
], 0dVc
[2*i+1
]);
}
for(int i=0; i<=4; i++
){//切頂部分の三角形
int j;
if(i>0
){j=2*i-1;
}else{j=9;
}
setPolygonVector(ET
[ix0
][ix1
][15+i
], 0dVc
[11+i
], 0dVc
[2*i
], 0dVc
[j
]);
}
}
//==============================================
N3=1;
for(int j=0; j<=N3-1; j++
){for
(int i=0; i<=N2V3-1; i++
){
StET
(j
, i
); AdET
(j
, i
);
}}
float bcOgn
[N3
][3
];
for(int i=0; i<=N3-1; i++
){
bcOgn
[i
][0
]=GCOX
(bc
[i
]);
bcOgn
[i
][1
]=GCOY
(bc
[i
]);
bcOgn
[i
][2
]=GCOZ
(bc
[i
]);
}
StSystmOrgn
();
//==============================================
//GUI Component
int WINDOW;
int Prmtr0_SLIDER
, Prmtr1_SLIDER
, Prmtr2_SLIDER;
int SET_A_LABEL
, SET_B_LABEL
, SET_R_LABEL;
int GET_LABEL;
int GET_ANGLE_TITLE_LABEL
, SET_ANGLE_TITLE_LABEL;
double Prmtr0 =o;
double Prmtr1 =o;
void createSettingWindow
(){
int StWnPsY=HEIGHT+39;
WINDOW =
newWindow( WndPstX
, StWnPsY
, 610
, 180
, "Setting Window"
);
SET_A_LABEL =
newTextLabel( 30
, 30
, 610
, 15
, "変形・・・<正十二面体> 〜 <切頂十二面体> 〜 <二十・十二面体> 〜 <正二十面体>"
);
addComponent( SET_A_LABEL
, WINDOW
);
Prmtr0_SLIDER =
newHorizontalSlider( 30
, 50
, 520
, 15
, Prmtr0
);
addComponent( Prmtr0_SLIDER
, WINDOW
);
SET_B_LABEL =
newTextLabel( 30
, 85
, 610
, 15
, "不透明度"
);
addComponent( SET_B_LABEL
, WINDOW
);
Prmtr1_SLIDER =
newHorizontalSlider( 30
, 105
, 520
, 15
, Prmtr1
);
addComponent( Prmtr1_SLIDER
, WINDOW
);
paintComponent( WINDOW
);
}
void onSliderMove
( int id
, float value
){
if( id==Prmtr0_SLIDER
){
Prmtr0 = value *a;
float rng=0.02;
if(Prmtr0<o+rng
){
setComponentText( SET_A_LABEL
, "正二十面体
(regular dodecahedron
)"
);
}else
if((Prmtr0>=0.25-rng
)&&
(Prmtr0<0.25+rng
)){
setComponentText( SET_A_LABEL
, "切頂十二面体
(truncated dodecahedron
)"
);
}else
if((Prmtr0>=0.5-rng
)&&
(Prmtr0<0.5+rng
)){
setComponentText( SET_A_LABEL
, "二十・十二面体
(icosidodecahedron
)"
);
}else
if((Prmtr0>=2.0/3-rng
)&&
(Prmtr0<2.0/3+rng
)){
setComponentText( SET_A_LABEL
, "切頂二十面体
(truncated icosahedron
)"
);
}else
if(Prmtr0>=1.0-rng
){
setComponentText( SET_A_LABEL
, "正二十面体
(regular icosahedron
)"
);
}else{
setComponentText(SET_A_LABEL
, "<正十二面体> 〜 <切頂十二面体> 〜 <二十・十二面体> 〜 <正二十面体>"
);
}
paintComponent( SET_A_LABEL
);
}else
if( id==Prmtr1_SLIDER
){
Prmtr1 = value;
float opc=
(1.0-Prmtr1
)*255;
Opcty
[0
]=
(int
)opc;
setComponentText( SET_B_LABEL
, "不透明度
(255〜0
) = "+Opcty
[0
]);
paintComponent( SET_B_LABEL
);
}
if(Prmtr0<0.5
){
TrnAng=2*Prmtr0*CAnD;
setVector(TCVc
, o
, RdCP*TrnFnc
(TrnAng
), RdID*TrnFnc
(TrnAng
));
setVector(VrVc
, -RdsVct
(TrnAng
)*
sin(TrnAng
), RdsVct
(TrnAng
)*
cos(TrnAng
), RdID
);
St0dVc
();
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntDdc
(i
, j
, k
);
}
StETVctr
(i
, j
);
}}
}else{
TrnPrmtr=2*
(Prmtr0-0.5
);
St0dVcTrnIcs
();
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntIcs
(i
, j
, k
);
}
StPlgnVctrTrnIcs
(i
, j
);
}}
}
if(Prmtr0<0.5
){
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntDdc
(i
, j
, k
);
}
}}
}else{
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntIcs
(i
, j
, k
);
}
}}
}
}
//==============================================
// 座標軸モデルを生成
int axis0 =
newAxisModel(6*a
, 6*a
, 6*a
);
int axis1 =
newAxisModel(3.5*a
, 3.5*a
, 3.5*a
);
int axis2 =
newAxisModel(2*a
, 2*a
, 2*a
);
int axis3 =
newAxisModel(1.5*a
, 1.5*a
, 1.5*a
);
//==============================================
//animation
float X0=0.0
, Y0=0.0
, Z0=0.0
, X1=0.0
, Y1=0.0
, Z1=0.0;
int world =
getWorldCoordinate(RENDERER
);
bool MOVIE = false; // 動画への書き出しを制御するスイッチ(trueならON
, falseならOFF)
int time = 0;
//カウント
int count=0;
//----------------------------------------------
//時刻受け渡し用の変数
float tCPini
[20
]=10000.0;
float tCPfin
[20
]=10000.0;
float tCAini
[20
]=10000.0;
float tCAfin
[20
]=10000.0;
float thPini
[20
]=10000.0;
float thPfin
[20
]=10000.0;
float thAini
[20
]=10000.0;
float thAfin
[20
]=10000.0;
float tgPini
[20
]=10000.0;
float tgPfin
[20
]=10000.0;
float tgAini
[20
]=10000.0;
float tgAfin
[20
]=10000.0;
float tbPini
[20
]=10000.0;
float tbPfin
[20
]=10000.0;
float tbAini
[20
]=10000.0;
float tbAfin
[20
]=10000.0;
int ti=0;
float tc
[20
];
float t0=o
, t1=o
, dt=o
, dt0=o
, dt1=o
, t2=o
, t3=o;
//その他の変数
float c0=o;
float xt
[3
];
float rotY=-0.25*PI;
float rotX=
acos((2.0/3.0
)^0.5
);//bcd点心
float dy=0.0*a;
float dz=7*a;//カメラ原点
float amp0=1000.0;
int PNum=0;
int idxi=0
, idxj=0
, idxk=0
, idxl=0
, idxm=0
, idxn=0;
int cdx0=0
, cdx1=0
, cdx2=0
, clx0=0
, clx1=0;
//位置、角度
float bx
[3
]=o;
float by
[3
]=o;
float bz
[3
]=o;
//==============================================
while( ROOP
){t=t+step; count=count+1;
if(count%
(100
)==0
){print
(count/10+"/"
);
}
//==============================================
//----------------------------------------------
t1=step;
//----------------------------------------------
//カメラとworld座標系の位置関係
dt1=o; S
();
if(Bt
())
{
X0=GCOX
(world
); Y0=GCOY
(world
); Z0=GCOZ
(world
);
SCO
(world
, o
, o
, o
); SCEA
(world
, o
, o
, o
);
setCameraOrigin(world
, o
, dy
, dz
);
setCameraEulerAngle(world
, o
, o
, o
);
spinXCamera(world
, -
atan(dy/
(dz
)));
}
//----------------------------------------------
//頂点の真上
S
();
if(Bt
())
{
//
addModel(axis0
, RENDERER
, bc
[0
]);
//
addModel(axis1
, RENDERER
, bc
[10
]);
//
addModel(axis2
, RENDERER
, cd
[0
]);
}
//==============================================
tc
[0
]=1.0; tc
[1
]=1.5; tc
[2
]=2.0; tc
[3
]=2.5; tc
[4
]=5.0;
tc
[10
]=10.0;
//----------------------------------------------
D
(1.0
, tc
[2
]); T
();
if(Bt
()){tanAtO=0.8;
SCEA
(gcd
, 2*Tu
(), o
, o
);
}
D
(o
, tc
[2
]); T
();
if(Bt
()){tanAtO=0.8;
SCEA
(gcd
, o
, 2*Tu
(), o
);
}
D
(o
, tc
[2
]); T
();
if(Bt
()){tanAtO=0.8;
SCEA
(gcd
, o
, o
, o
); RXC
(gcd
, atan(0.5
)/PI*Tg
()); RYC
(gcd
, 0.2*Tg
());
}
D
(-2*dt0
, 1.6*tc
[4
]); T
();
if(Bt
()){tanAtO=1.0;
SCEA
(hcd
, 0.5
, (6.2
)*Tg
(), -0.5
);
}
D
(-dt0
, dt0/8
); T
();
if(Bt
()){
float prmt0=o;
prmt0=Tu
()*0.25;
if(prmt0<0.5
){
TrnAng=2*prmt0*CAnD;
setVector(TCVc
, o
, RdCP*TrnFnc
(TrnAng
), RdID*TrnFnc
(TrnAng
));
setVector(VrVc
, -RdsVct
(TrnAng
)*
sin(TrnAng
), RdsVct
(TrnAng
)*
cos(TrnAng
), RdID
);
St0dVc
();
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntDdc
(i
, j
, k
);
}
StETVctr
(i
, j
);
}}
}else{
TrnPrmtr=2*
(prmt0-0.5
);
St0dVcTrnIcs
();
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntIcs
(i
, j
, k
);
}
StPlgnVctrTrnIcs
(i
, j
);
}}
}
if(prmt0<0.5
){
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntDdc
(i
, j
, k
);
}
}}
}else{
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntIcs
(i
, j
, k
);
}
}}
}
}
D
(dt0/4
, dt0
); T
();
if(Bt
()){
float prmt0=o;
prmt0=0.25*TuR
()+0.5*Tu
();
if(prmt0<0.5
){
TrnAng=2*prmt0*CAnD;
setVector(TCVc
, o
, RdCP*TrnFnc
(TrnAng
), RdID*TrnFnc
(TrnAng
));
setVector(VrVc
, -RdsVct
(TrnAng
)*
sin(TrnAng
), RdsVct
(TrnAng
)*
cos(TrnAng
), RdID
);
St0dVc
();
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntDdc
(i
, j
, k
);
}
StETVctr
(i
, j
);
}}
}else{
TrnPrmtr=2*
(prmt0-0.5
);
St0dVcTrnIcs
();
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntIcs
(i
, j
, k
);
}
StPlgnVctrTrnIcs
(i
, j
);
}}
}
if(prmt0<0.5
){
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntDdc
(i
, j
, k
);
}
}}
}else{
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntIcs
(i
, j
, k
);
}
}}
}
}
D
(dt1
, dt0
); T
();
if(Bt
()){
float prmt0=o;
prmt0=0.5*TuR
()+2.0/3*Tu
();
if(prmt0<0.5
){
TrnAng=2*prmt0*CAnD;
setVector(TCVc
, o
, RdCP*TrnFnc
(TrnAng
), RdID*TrnFnc
(TrnAng
));
setVector(VrVc
, -RdsVct
(TrnAng
)*
sin(TrnAng
), RdsVct
(TrnAng
)*
cos(TrnAng
), RdID
);
St0dVc
();
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntDdc
(i
, j
, k
);
}
StETVctr
(i
, j
);
}}
}else{
TrnPrmtr=2*
(prmt0-0.5
);
St0dVcTrnIcs
();
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntIcs
(i
, j
, k
);
}
StPlgnVctrTrnIcs
(i
, j
);
}}
}
if(prmt0<0.5
){
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntDdc
(i
, j
, k
);
}
}}
}else{
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntIcs
(i
, j
, k
);
}
}}
}
}
D
(dt1
, dt0
); T
();
if(Bt
()){
float prmt0=o;
prmt0=2.0/3*TuR
()+Tu
();
if(prmt0<0.5
){
TrnAng=2*prmt0*CAnD;
setVector(TCVc
, o
, RdCP*TrnFnc
(TrnAng
), RdID*TrnFnc
(TrnAng
));
setVector(VrVc
, -RdsVct
(TrnAng
)*
sin(TrnAng
), RdsVct
(TrnAng
)*
cos(TrnAng
), RdID
);
St0dVc
();
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntDdc
(i
, j
, k
);
}
StETVctr
(i
, j
);
}}
}else{
TrnPrmtr=2*
(prmt0-0.5
);
St0dVcTrnIcs
();
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntIcs
(i
, j
, k
);
}
StPlgnVctrTrnIcs
(i
, j
);
}}
}
if(prmt0<0.5
){
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntDdc
(i
, j
, k
);
}
}}
}else{
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntIcs
(i
, j
, k
);
}
}}
}
}
D
(5*dt1
, 2*dt0
); T
();
if(Bt
()){
float prmt0=o;
prmt0=TuR
(); Opcty
[0
]=
(int
)(SuR
(Tu
())*255
);
if(Opcty
[0
]<180
){Opcty
[0
]=180;
}
if(prmt0<0.5
){
TrnAng=2*prmt0*CAnD;
setVector(TCVc
, o
, RdCP*TrnFnc
(TrnAng
), RdID*TrnFnc
(TrnAng
));
setVector(VrVc
, -RdsVct
(TrnAng
)*
sin(TrnAng
), RdsVct
(TrnAng
)*
cos(TrnAng
), RdID
);
St0dVc
();
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntDdc
(i
, j
, k
);
}
StETVctr
(i
, j
);
}}
}else{
TrnPrmtr=2*
(prmt0-0.5
);
St0dVcTrnIcs
();
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntIcs
(i
, j
, k
);
}
StPlgnVctrTrnIcs
(i
, j
);
}}
}
if(prmt0<0.5
){
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntDdc
(i
, j
, k
);
}
}}
}else{
for(int i=0; i<=N3-1; i++
){for
(int j=0; j<=N2V3-1; j++
){
for(int k=0; k<=NTV2-1; k++
){
PntIcs
(i
, j
, k
);
}
}}
}
}
dt1=o; S
();
if(Bt
()){createSettingWindow
();
}
//----------------------------------------------
//==============================================
//描画
sleep
(1000/rrate
) ; // 毎回1/rrateミリ秒だけ停止(ウェイト)
paintGraphics3D( RENDERER
) ; // 3DCGを描画
paintComponent( MAIN_DISPLAY_LABEL
) ; // GUIの再描画
paintComponent( MAIN_WINDOW
) ; // GUIの再描画
//----------------------------------------------
//save picture
// 連番ファイル名で画像出力( 動画スイッチがtrueのときのみ )
if( MOVIE == true
){time = time + 1; picnumber=picid+time;
exportGraphics( MAIN_GRAPHICS
, "./movie/0" + picnumber + ".png"
, "PNG"
);
}
//----------------------------------------------
// TIME_ENDループ目でプログラムを強制終了
if( time == TIME_END
){ alert
( "上限枚数に達したため、プログラムを終了します。 時刻=" + time
); exit
();
}
}
//==============================================
exit
(); // アニメーションループを脱出するとプログラムを終了
// キー入力があった際に呼び出される
void onKeyDown
( int id
, string key
){
// キー入力がスペースキーの場合
if( key == "SPACE"
){
// 動画スイッチがtrueのときはfalseにする
if( MOVIE == true
){
MOVIE = false; // 動画スイッチをfalse(OFF)に
alert
( "録画を一時停止しました。 時刻=" + time
);
// それ以外の場合、つまり動画スイッチがfalseのときはtrueにする
}else{
alert
( "録画を開始します。 時刻=" + time
);
MOVIE = true; // 動画スイッチをtrue(ON)に ※メッセージ表示のタイムラグを考慮してこの順番1
}
}
}
//==============================================
//時刻
void T
(){t0=t1+dt1; t1=t0+dt0;
}
void T2
(){t0=t2; t1=t3;
}
void S
(){t0=t1+dt1; t1=t0+step;
}
void D
(float delt1
, float delt0
){dt1=delt1; dt0=delt0;
}
//Ft
(var
)---var<0で0、var>1で1、それ以外はvarと等しい値を返す関数
float Ft
(float var
){
float value;
if(var<=o
){value=o;
}
else if((var>o
)&&
(var<1.0
)){value=var;
}
else{value=1.0;
}
return value;
}
//Tu
()---t=t0でTu
()=0、t=t1でTu
()=1
float Tu
(){return Ft
((t-t0
)/
(t1-step-t0
));
}
//TuR
()---Tuのreverse
float TuR
(){return 1.0-Tu
();
}
//Su
()---周期1で0-1-0
float Su
(float var
){
return
(1.0-
cos(2*PI*var
))/2;
}
//Su
()のreverse
float SuR
(float var
){
return 1.0-Su
(var
);
}
//Gt
(var
)---Ft
(var
)を滑らかにした関数
float Gt1
(float var
){return 0.5*
(1.0+
sin(PI*Ft
(var
)-0.5*PI
));
}//sin関数
float tanAtO=1.5;//3次関数の中心点での微分係数。0.8がちょうどよい
float Yt
(float var
){return
((1-tanAtO
)*
(2*var-1.0
)^3+tanAtO*
(2*var-1.0
)+1.0
)/2.0;
}
float Gt
(float var
){return Gt1
(Yt
(var
));
}
float Gt2
(float var
){return
(1/PI
)*
asin(2*var-1.0
)+1/2;
}//sin逆関数
float Zt
(float var
){return
(1/PI
)*
(2*var-1.0
)*
(1-
(2*var-1.0
)^2
)^
(1.0/2.0
);
}//lemni型関数
float Gt3
(float var
){return Gt2
(var
)+Zt
(var
);
}//半円の積分
//Tg
()---規格化時間Tu
()を滑らかにした関数。t0<=t<=t1で0<=Tg
()<=1
float Tg
(){return Gt
(Tu
());
}
//TgR
()---Tg
()のreverse
float TgR
(){return 1.0-Tg
();
}
//TgU
()---Tg
()のU-turn
float TgU
(){return 4*Tg
()*
(1.0-Tg
());
}
//TgUR
()---TgU
()のreverse
float TgUR
(){return 1.0-TgU
();
}
float Tg3
(){return Gt
(Tu
());
}
//Ti
(ixi
)---t0<=t<=t1内の幅trangeの区間でTg
()を規格化したもの。
//幅trangeの区間の外側ではTi
(ixi
)=0
, 1
//Ti
(0
)はt0<=t<=t0+trangeで0から1まで、Ti
(Nrg-1
)はt1-trange<=t<=t1で0から1まで
float trange;//Ti
(ixi
)が単調に増加する区間の幅
float Ti
(int ixi
){
float value
, shift0;
shift0=
(t1-trange-t0
)*ixi/
(float
)(N3d-1
);//時間のズレ
return Gt
((t-t0-shift0
)/trange
);
}
//TiR
(ixi
)---Ti
(ixi
)のreverse
float TiR
(int ixi
){return 1.0-Ti
(ixi
);
}
//GtRight
(var
)---0<=var<=1の右端幅bandの区間で0から1まで増加する関数
float band=0.2;//GtRight
(var
)が変化する区間の幅
float GtRight
(float var
){return Gt
((var-1.0+band
)/band
);
}
//GtLeft
(var
)---0<=var<=1の左端幅bandの区間で1から0まで減少する関数
float GtLeft
(float var
){return 1.0-Gt
(var/band
);
}
//TiRight
(ixi
)---Gt
(var
)からTi
(ixi
)と同様にGtRight
(var
)から作った右端幅bandの区間で0から1まで増加する関数
float TiRight
(int ixi
){
float value
, shift0;
shift0=
(t1-trange-t0
)*ixi/
(float
)(N3d-1
);//時間のズレ
return GtRight
((t-t0-shift0
)/trange
);
}
//TiLeft
(ixi
)---Gt
(var
)からTi
(ixi
)と同様にGt+eft
(var
)から作った左端幅bandの区間で1から0まで減少する関数
float TiLeft
(int ixi
){
float value
, shift0;
shift0=
(t1-trange-t0
)*ixi/
(float
)(N3d-1
);//時間のズレ
return GtLeft
((t-t0-shift0
)/trange
);
}
//MakeTrack
(var
)---0<=t<=1の中央幅twidthで値1をとり、それ以外では滑らかに0となる関数
float twidth=0.5;//MakeTrack
(var
)の幅
float MakeTrack
(float var
){
return Gt
(2*var/
(1.0-twidth
))-Gt
((2*var-1.0-twidth
)/
(1.0-twidth
));
}
//計算式
/* MakeTrack
(float var
)
=1.0-
(GtLeft
(var
)+GtRight
(var
)) ただし2*band=1.0-twidth*/
//MakeTracki
(ixi
)---Gt
(var
)からTi
(ixi
)と同様にMakeTrack
(var
)から作った、t0+shift0<t<t0+shift0+trangeの中央幅twidthで値1をとり、それ以外では滑らかに0となる関数
//区間端での微分係数はcutで調節可
float MakeTracki
(int ixi
){
float value
, shift0;
shift0=
(t1-trange-t0
)*ixi/
(float
)(N3d-1
);//時間のズレ
return MakeTrack
((t-t0-shift0
)/trange
);
}
bool Bt
(){return
(t>=t0
)&&
(t<t1
);
}
bool Bt2
(){return
(t>=t2
)&&
(t<t3
);
}
void Q
(float var1
, float var2
, int xvar
){
if((t>=var1
)&&
(t<var2
)){step=xvar/
(float
)rrate;
}else{step=1.0/
(float
)rrate;
}}
//----------------------------------------------
//angle
float GCEAA
(int coord
){return
getCoordinateEulerAngleAlpha(coord
);
}
float GCEAB
(int coord
){return
getCoordinateEulerAngleBeta(coord
);
}
float GCEAG
(int coord
){return
getCoordinateEulerAngleGamma(coord
);
}
void SCEA
(int coord
, float aangle
,float bangle
, float gangle
){
setCoordinateEulerAngle(coord
, PI*aangle
, PI*bangle
, PI*gangle
);
}
void RC
(int coord
, float angle
,
float axx
, float axy
, float axz
,
float ox
, float oy
, float oz
){
rotCoordinate(coord
, angle*PI
, axx
, axy
, axz
, ox
, oy
, oz
);
}
void RVC
(int coord
, float angle
,
float axx
, float axy
, float axz
,
float bxx
, float bxy
, float bxz
){
rotCoordinate(coord
, angle*PI
, axx-bxx
, axy-bxy
, axz-bxz
, bxx
, bxy
, bxz
);
}
void RXC
(int coord
, float angle
){
rotXCoordinate(coord
, angle*PI
);
}
void RYC
(int coord
, float angle
){
rotYCoordinate(coord
, angle*PI
);
}
void RZC
(int coord
, float angle
){
rotZCoordinate(coord
, angle*PI
);
}
void SXC
(int coord
, float angle
){
spinXCoordinate(coord
, angle*PI
);
}
void SYC
(int coord
, float angle
){
spinYCoordinate(coord
, angle*PI
);
}
void SZC
(int coord
, float angle
){
spinZCoordinate(coord
, angle*PI
);
}
//----------------------------------------------
//position
float GCOX
(int coord
){return
getCoordinateOriginX(coord
);
}
float GCOY
(int coord
){return
getCoordinateOriginY(coord
);
}
float GCOZ
(int coord
){return
getCoordinateOriginZ(coord
);
}
void SCO
(int coord
, float ox
, float oy
, float oz
){
setCoordinateOrigin(coord
, ox
, oy
, oz
);
}
//----------------------------------------------
//base
float
[] GCBX
(int coord
){return
getCoordinateBaseX(coord
);
}
float
[] GCBY
(int coord
){return
getCoordinateBaseY(coord
);
}
float
[] GCBZ
(int coord
){return
getCoordinateBaseZ(coord
);
}
//----------------------------------------------
//Vector
//Vector addition
//moveVector
void MVx
(int vcid
, float varx
, float vary
, float varz
){
moveVector(vcid
, varx
, vary
, varz
);
}
void MVc
(int vid0
, int vid1
){
moveVector(vid0
, vid1
);
}
//Vector subtraction
//Vector multiplication
void MltV
(int vid
, float var
){
scaleVector(vid
, var
, var
, var
);
}
//----------------------------------------------
//Color
//material optics
void SPPht
(int id
, float emss
, float spclr
, float spcla
, float dffr
, float dffs
, float ambn
){
setPolygonEmissive (id
, emss
);
setPolygonSpecular (id
, spclr
, spcla
);
setPolygonDiffractive (id
, dffr
);
setPolygonDiffuse (id
, dffs
);
setPolygonAmbient (id
, ambn
);
}
//Color
int Color
(int Nth
, int NofC
, float Offset
){
float x;
float var=
(float
)Nth/
(float
)NofC;
var=var+Offset;
while(var<o
){var=var+1.0;
}
while(var>1.0
){var=var-1.0;
}
if((var>=0
)&&
(var<1.0/6.0
)){x=1.0;
}
else if((var>=1.0/6.0
)&&
(var<1.0/3.0
)){x=-6*var+2.0;
}
else if((var>=1.0/3.0
)&&
(var<2.0/3.0
)){x=o;
}
else if((var>=2.0/3.0
)&&
(var<5.0/6.0
)){x=6*var-4.0;
}
else{x=1.0;
}
x=255*x;
int value=
(int
)x; return value;
}
int Color1
(int Nth
, int NofC
, float Offset
){
float x=
cos(2*PI*
((float
)Nth/
(float
)NofC+Offset
))+0.5;
if(x>1
){x=1.0;
} if(x<0
){x=0.0;
} x=255*x;
int value=
(int
)x; return value;
}
//set polygon color
void SPCAuto
(int polygon
, int opcty
, int Nth
, int NofC
){
float offset=1.0/6.0;
int rcolor=Color
(Nth
, NofC
, offset
);
int gcolor=Color
(Nth
, NofC
, offset-1.0/3.0
);
int bcolor=Color
(Nth
, NofC
, offset+1.0/3.0
);
setPolygonColor(polygon
, rcolor
, gcolor
, bcolor
, opcty
);
}
//----------------------------------------------
//add Polygon
void AP
(int polygon
, int cd
){
addPolygon(polygon
, RENDERER
, cd
);
}