1
在我問我的問題之前,我想爲我的尷尬英語道歉,因爲我是一個外國人。Opengl三角形旋轉頂點修改
我想創建一個應用程序,它將旋轉按鈕單擊視圖。我正在修改按鈕點擊上的三角形頂點。
操作完成後,我想重繪修改頂點的三角形,但是三角形不會改變。我已收到日誌消息button has changed vertex of triangle
但三角形沒有改變。
我需要幫助的人。
這是我的代碼: -
方法pos_change/sign_changed /加號和減號是修改爲三角形頂點旋轉
private int delx = 0;
private int dely = 0;
public float vertices[] = { delx, dely,
delx, dely,
delx, dely};
public static float pvertices[] = { 0.0f, 0.8f ,0.8f , -0.8f , -0.8f , -0.8f};
private String[] Status = {"up","right","down","left"};
private String now_Status = Status[0];
int Status_Stack =0;
int change =0;
public drawtri(){
array_Plus();
mVertexBuffer = getFloatBufferFromFloatArray(vertices);
}
public void draw(GL10 gl){
gl.glFrontFace(GL10.GL_CW);
gl.glVertexPointer(2, GL10.GL_FLOAT, 0, mVertexBuffer);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDrawArrays(GL10.GL_TRIANGLES, 0, vertices.length/2);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
public void Matrix_Change(char a){
switch(a){
//right
case 'R' :
if(now_Status=="up"){
array_Minus();
array_Pos_Change();
Status_Stack++;
now_Status= Status[Status_Stack];
array_Plus();
}
else if(now_Status=="right"){
array_Minus();
array_Pos_Change();
array_Sign_Change();
now_Status= Status[++Status_Stack];
array_Plus();
}
else if(now_Status=="down"){
array_Minus();
array_Pos_Change();
now_Status= Status[++Status_Stack];
array_Plus();
}
else if(now_Status=="left"){
array_Minus();
array_Pos_Change();
array_Sign_Change();
Status_Stack=0;
now_Status= Status[Status_Stack];
array_Plus();
}
//left
case 'L':
if(now_Status=="up"){
array_Minus();
array_Pos_Change();
array_Sign_Change();
Status_Stack=3;
now_Status= Status[Status_Stack];
array_Plus();
}
else if(now_Status=="left"){
array_Minus();
array_Pos_Change();
now_Status= Status[--Status_Stack];
array_Plus();
}
else if(now_Status=="down"){
array_Minus();
array_Pos_Change();
array_Sign_Change();
now_Status= Status[--Status_Stack];
array_Plus();
}
else if(now_Status=="right"){
array_Minus();
array_Pos_Change();
now_Status= Status[--Status_Stack];
array_Plus();
}
break;
}
}
public void array_Pos_Change(){
float buffer;
buffer = pvertices[0];
pvertices[0] = pvertices[1];
pvertices[1] = buffer;
buffer = pvertices[5];
pvertices[5] = pvertices[2];
pvertices[2] = buffer;
buffer = pvertices[3];
pvertices[3] = pvertices[4];
pvertices[4] = buffer;
}
public void array_Sign_Change(){
for(int i = 0; i<6 ; i++) pvertices[i] *= -1;
}
public void array_Minus(){
for(int i=0; i<6; i++) vertices[i]-=pvertices[i];
}
public void array_Plus(){
for(int i=0; i<6; i++) vertices[i]+=pvertices[i];
}
,那是按鈕的代碼:
left.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
drawtri.Matrix_Change('L');
}
});
right.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
drawtri.Matrix_Change('R');
}
});
而且該代碼在:
@Override
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
GLU.gluLookAt(gl, View_Pos_x, View_Pos_y,height,View_Pos_x, View_Pos_y, 0, 0, +1,0);
draw_Obj(gl);
}