MatrixState中的参数与 CP_Na_Cl中参数的比较
MatrixState:
public static void setInitStack()//获取不变换初始矩阵 { currMatrix=new float[16]; Matrix.setRotateM(currMatrix, 0, 0, 1, 0, 0); } public static void pushMatrix()//保护变换矩阵 { stackTop++; for(int i=0;i<16;i++) { mStack[stackTop][i]=currMatrix[i]; } } public static void popMatrix()//恢复变换矩阵 { for(int i=0;i<16;i++) { currMatrix[i]=mStack[stackTop][i]; } stackTop--; } public static void translate(float x,float y,float z)//设置沿xyz轴移动 { Matrix.translateM(currMatrix, 0, x, y, z); } public static void rotate(float angle,float x,float y,float z)//设置绕xyz轴移动 { Matrix.rotateM(currMatrix,0,angle,x,y,z); } public static void scale(float x,float y,float z) { Matrix.scaleM(currMatrix,0, x, y, z); } //插入自带矩阵 public static void matrix(float[] self) { float[] result=new float[16]; Matrix.multiplyMM(result,0,currMatrix,0,self,0); currMatrix=result; }
CP_Na_Cl:
public void drawSelf(){ MatrixState.rotate(roateX, 1, 0, 0); MatrixState.rotate(roateY, 0, 1, 0); MatrixState.rotate(roateZ, 0, 0, 1); drawLine(-offset, 1, 1, 1, 1); MatrixState.pushMatrix(); MatrixState.rotate(90, 0, 1, 0); drawLine(-offset, 1, 1, 1, 1); MatrixState.popMatrix(); MatrixState.pushMatrix(); MatrixState.rotate(90, 1, 0, 0); drawLine(-offset, 1, 1, 1, 1); MatrixState.popMatrix(); drawLine(0, 1, 1, 1, 1); MatrixState.pushMatrix(); MatrixState.rotate(90, 0, 1, 0); drawLine(0, 1, 1, 1, 1); MatrixState.popMatrix(); MatrixState.pushMatrix(); MatrixState.rotate(90, 1, 0, 0); drawLine(0, 1, 1, 1, 1); MatrixState.popMatrix(); drawLine(offset, 1, 1, 1, 1); MatrixState.pushMatrix(); MatrixState.rotate(90, 0, 1, 0); drawLine(offset, 1, 1, 1, 1); MatrixState.popMatrix(); MatrixState.pushMatrix(); MatrixState.rotate(90, 1, 0, 0); drawLine(offset, 1, 1, 1, 1); MatrixState.popMatrix(); draw5Big(-offset, 0, 1, 0, 1); draw4Small(-offset, 1, 1, 0, 1); draw4Big(0, 0, 1, 0, 1); draw5Small(0, 1, 1, 0, 1); draw5Big(offset, 0, 1, 0, 1); draw4Small(offset, 1, 1, 0, 1); }
总结:CP_Na_Cl中的rotatex是在MatrixState中rotate上进行的,rotatex用于计算比较,不过相当于rotate中的X!