?? java-codes.txt
字號:
//變換量
transx.rotX(Math.toRadians(0));//anglex
transy.rotY(Math.toRadians(0));
transz.rotZ(Math.toRadians(0));
transp.setTranslation(new Vector3f(fx,fy,fz));
//生效
transGroupp.setTransform(transp);
transGroupx.setTransform(transx);
transGroupy.setTransform(transy);
transGroupz.setTransform(transz);
}
int[] jisuanNextXYZ(char doType,int totateArg,int oldx,int oldy,int oldz)
//需要變量x,y,z,doType,totateArg,輸出返回到數組
{
//System.out.println("計算下一個點。。。");
//用于計算
int newz=0;
int newy=0;
int newx=0;
//返回時的標準格式
int[] nextXYZ={0,0,0};
//計算時接收調用外面函數的返回函數值
int[] myShunShiNext={0,0};
if(totateArg==0)
{
//當totateArg為0時,沒有可用的if匹配,返回原位置
newx=oldx;
newy=oldy;
newz=oldz;
//返回結果
nextXYZ[0]=newx;
nextXYZ[1]=newy;
nextXYZ[2]=newz;
//System.out.println("\n變為位置:"+newx+newy+newz);
return nextXYZ;
}
//
//System.out.println("\n原位置:"+oldx+oldy+oldz);
//System.out.println("繞:"+doType+"轉"+totateArg);
switch(doType)
{
case 'Z' :
newz=oldz ;
if(totateArg==90)
{myShunShiNext=quXiaYiGe(oldx,oldy,1);
}
else if (totateArg==180)
{myShunShiNext=quXiaYiGe(oldx,oldy,2);
}
else if(totateArg==-90)
{myShunShiNext=quXiaYiGe(oldx,oldy,3);
}
newx=myShunShiNext[0];
newy=myShunShiNext[1];
break;
case 'Y' :
newy=oldy ;
if(totateArg==90)
{myShunShiNext=quXiaYiGe(oldz,oldx,1);
}
else if(totateArg==180)
{myShunShiNext=quXiaYiGe(oldz,oldx,2);
}
else if(totateArg==-90)
{myShunShiNext=quXiaYiGe(oldz,oldx,3);
}
newz=myShunShiNext[0];
newx=myShunShiNext[1];
break;
case 'X' :
newx=oldx ;
if(totateArg==90)
{myShunShiNext=quXiaYiGe(oldy,oldz,1);
}
else if(totateArg==180)
{myShunShiNext=quXiaYiGe(oldy,oldz,2);
}
else if(totateArg==-90)
{myShunShiNext=quXiaYiGe(oldy,oldz,3);
}
newy=myShunShiNext[0];
newz=myShunShiNext[1];
break;
}
//返回結果
nextXYZ[0]=newx;
nextXYZ[1]=newy;
nextXYZ[2]=newz;
//System.out.println("\n變為位置:"+newx+newy+newz);
return nextXYZ;
}
boolean fangXiangCorrect(int argx,int argy,int argz)
{//用三個差向量判斷自轉
//System.out.println("方向判斷。。。");
//(blockIdX-1),(blockIdY-1),(blockIdZ-1)為初始點位置,分別加1得到三個初始向量
//xvec,yvec,zvec為保存的變化
//減去當前的方塊位置,得到每個方向點當前向量chaxvec,chayvec,chazvec
//X點
int[] p1X=jisuanNextXYZ('X',argx,1,0,0);//原始x點便移
int[] p2X=jisuanNextXYZ('Y',argy,p1X[0],p1X[1],p1X[2]);
int[] p3X=jisuanNextXYZ('Z',argz,p2X[0],p2X[1],p2X[2]);//新的x點便移
//Y點
int[] p1Y=jisuanNextXYZ('X',argx,0,1,0);
int[] p2Y=jisuanNextXYZ('Y',argy,p1Y[0],p1Y[1],p1Y[2]);
int[] p3Y=jisuanNextXYZ('Z',argz,p2Y[0],p2Y[1],p2Y[2]);
//Z點
int[] p1Z=jisuanNextXYZ('X',argx,0,0,1);
int[] p2Z=jisuanNextXYZ('Y',argy,p1Z[0],p1Z[1],p1Z[2]);
int[] p3Z=jisuanNextXYZ('Z',argz,p2Z[0],p2Z[1],p2Z[2]);
//System.out.println("坐標系:"+chaX+" "+chaY+" "+chaZ);
// 新的x點便移=當前位置x點的偏移
if(
((p3X[0]==chaxvec.x)&&(p3X[1]==chaxvec.y)&&(p3X[2]==chaxvec.z))&&
((p3Y[0]==chayvec.x)&&(p3Y[1]==chayvec.y)&&(p3Y[2]==chayvec.z))&&
((p3Z[0]==chazvec.x)&&(p3Z[1]==chazvec.y)&&(p3Z[2]==chazvec.z))
)
{System.out.println("坐標軸到位了");
return true;
}
else
{
//System.out.println("坐標軸沒到位");
return false;
}
}
boolean weiZhiCorrect(int aidx,int aidy,int aidz,int argx,int argy,int argz)
{
int[] p1=jisuanNextXYZ('X',argx,blockIdX-1,blockIdY-1,blockIdZ-1);
int[] p2=jisuanNextXYZ('Y',argy,p1[0],p1[1],p1[2]);
int[] p3=jisuanNextXYZ('Z',argz,p2[0],p2[1],p2[2]);
if((p3[0]==aidx)&&(p3[1]==aidy)&&(p3[2]==aidz))
{System.out.println("位置對了");
return true;
}
else
{
System.out.println("位置不對");
return false;
}
}
//僅計算逆時針旋轉時的坐標變化,當轉逆時針-90度時,轉化為3個逆時針90度
int[] quXiaYiGe(int num1,int num2,int n)
{
int[][] xiangXianZhi={{1,1},{-1,1},{-1,-1},{1,-1}}; //一,二,三,四,0,1,2,3
int[][] zouShangZhi={{1,0},{0,1},{-1,0},{0,-1}}; //
int[] result={0,0};
//System.out.println("旋轉次數為:"+n);
//System.out.println(num1+" , "+num2+"旋轉到:");
int temp=0;
for(int i=0;i<n;i++)
{
//循環一次轉一次
if(num1==0&&num2==0)//
{
num1=0;
num2=0;
//System.out.println("0");
}
else if(num1>0&&num2>0)//一象限轉到二象限
{
temp=num1;
num1=-num2;
num2=temp;
//System.out.println("1");
}
else if(num1<0&&num2>0)//二象限轉到三象限
{
temp=num1;
num1=-num2;
num2=temp;
////System.out.println("2");
}
else if(num1<0&&num2<0)//三象限轉到四象限
{
temp=num1;
num1=-num2;
num2=temp;
////System.out.println("3");
}
else if(num1>0&&num2<0)//四象限轉到一象限
{
temp=num1;
num1=-num2;
num2=temp;
//System.out.println("4");
}
else if(num1>0&&num2==0)//X上到Y上
{
temp=num1;
num1=0;
num2=temp;
//System.out.println("5");
}
else if(num1==0&&num2>0)//Y上到X上
{
temp=num1;
num1=-num2;
num2=0;
//System.out.println("6");
}
else if(num1<0&&num2==0)//
{
temp=num1;
num1=0;
num2=temp;
//System.out.println("7");
}
else if(num1==0&&num2<0)//
{
temp=num1;
num1=-num2;
num2=0;
//System.out.println("8");
}
else
{System.out.println("no");}
}
//System.out.println(num1+" , "+num2);
result[0]=num1;
result[1]=num2;
return result;
}
public void run()
{
//System.out.println("我的動畫開始了");
//動畫協調,取一個id,并放出令牌
myDonghuaId=selectDonghuaId++;
selectDonghuaId%=9;
yunXingThread++;
switch(selectedC)
{
case 'Z':
{startDonghuaZ();break;
}
case 'Y':
{startDonghuaY();break;
}
case 'X':
{startDonghuaX();break;
}
}
//最終位置
while(!canNew)//當canNew=true時,輸出到3D界面,否則只計算
{//System.out.println(" 我在等待計算出新值...");
}
//變換生效
transGroupp.setTransform(transp);
transGroupx.setTransform(transx);
transGroupy.setTransform(transy);
transGroupz.setTransform(transz);
canNew=false;
//System.out.println("我的動畫完成了");
yunXingThread--;
}
//用來從一個原坐標和結果坐標來 搜索 3個x,y,z順序的旋轉操作,返回到needRotate[3]中
//使用了int[] jisuanNextXYZ(char doType,int totateArg,int oldx,int oldy,int oldz)
int[] shouSuoXYZRotate(int oldx,int oldy,int oldz,int aidx,int aidy,int aidz)
{//搜索自轉,不看位置,只看三個向量對不對
System.out.println("塊原始位置:"+oldx+","+oldy+","+oldz);
System.out.println("塊目標位置:"+aidx+","+aidy+","+aidz);
//存放結果
int needRotatex=0;
int needRotatey=0;
int needRotatez=0;
//轉換返回
int[] needRotate={0,0,0};
int num=0;
wancheng:
for(int j=0;j<=3;j++)
{
int toArg=0;//j=3時取0
if(j==1){toArg=90;}
if(j==2){toArg=-90;}
if(j==3){toArg=180;}
for(int jj=0;jj<=3;jj++)
{
int ttoArg=0;
if(jj==1){ttoArg=90;}
if(jj==2){ttoArg=-90;}
if(jj==3){ttoArg=180;}
for(int jjj=0;jjj<=3;jjj++)
{
int tttoArg=0;
if(jjj==1){tttoArg=90;}
if(jjj==2){tttoArg=-90;}
if(jjj==3){tttoArg=180;}
//System.out.println("驗證xyz旋轉.."+toArg+" "+ttoArg+" "+tttoArg);
// 這個打開 有的會找不到
//boolean myBoolean1=weiZhiCorrect(nexyz[0],nexyz[1],nexyz[2],toArg,ttoArg,tttoArg);
boolean myBoolean=fangXiangCorrect(toArg,ttoArg,tttoArg);
//MoFang.myWait();
if (myBoolean)
{
needRotatex=toArg;
needRotatey=ttoArg;
needRotatez=tttoArg;
needRotate[0]=needRotatex;
needRotate[1]=needRotatey;
needRotate[2]=needRotatez;
num++;
System.out.println("*****找到了x,y,z旋轉即可*****"+toArg+" , "+ttoArg+" , "+tttoArg+"");
//return needRotate;
}
}
}
}
if(num==0)
{
System.out.println("沒有適合的xyz旋轉,不旋轉..");
MoFang.myWait();
}
else if(num>=2)
{System.out.println("###########################找到了num="+num+"個");
}
return needRotate;
}
void startDonghuaX()
{
//動畫模塊
int chuJiao ;
int oneTime ;
int bianJiao ;
int nowJiao ;
//測試
//totateArg=90;
chuJiao=getChujiao(yuany,yuanz);
if(totateArg==-90)
oneTime=-15 ;
else
oneTime=15 ;
//System.out.println("chuJiao="+chuJiao);
//System.out.println("totateArg="+totateArg);
//nowJiao=chuJiao+bianJiao ;
//這是目前角度公式,可見,據坐標可以判斷它的角度嘛
for(bianJiao=0;bianJiao!=(totateArg+oneTime);bianJiao+=oneTime)
{
if(!closeDonghua)
{
while(myDonghuaId!=selectDonghuaId)//動畫同步相關輪到自己時才執行,把令牌交給下一個
{;//System.out.println("我是"+myDonghuaId+"號,而令牌現在是"+selectDonghuaId+"號,我要等...");
try
{
//System.in.read();//暫停
myThread.sleep(whileDelay);
}
catch(Exception e)
{
}
}
}
//計算x,y和角度輸出
float fx ;
float fy ;
float fz ;
//半徑
float r;
if(yuany==0&&yuanz==0)
r=0;//(x,y)不變,故不用計算,直接給(0,0),初角返回任何值都可;
else
{
if(yuany==0||yuanz==0)
r=1.0f;
else
r=1.414f;
}
nowJiao=chuJiao+bianJiao ;
//使用初角直為了計算當前(x,y)位置,當前jiaodu1與他無關,只與老角有關
//(-1,-1)距離原點為根2,約1.732
//0.3指定了1點在0.3,-0.3處
fy=(float)kuaiZhongXinWeizhi*r*(float)Math.cos(Math.PI*nowJiao/180);
fz=(float)kuaiZhongXinWeizhi*r*(float)Math.sin(Math.PI*nowJiao/180);
fx=(float)kuaiZhongXinWeizhi*(yuanx);
//z坐標不變,這里的z早減過了1
//計算出了全部數據,OK,開始刷新
//用變換量
//transz.rotZ(Math.toRadians(anglez));
//transy.rotY(Math.toRadians(angley));
//transx.rotX(Math.toRadians(bianJiao+oldJiaoDu));
transp.setTranslation(new Vector3f(fx,fy,fz));
//生效
//transGroupz.setTransform(transz);
//transGroupy.setTransform(transy);
//transGroupx.setTransform(transx);
transGroupp.setTransform(transp);
//停不了,只能使用多線程或定時
//System.out.println("bianJiao="+bianJiao);
try
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -