Question

Before I ask my Question, I would like to apologize for my awkward English because I am a foreigner.

I want to make an application that will rotate a view on button click. I am modifying triangle vertex on button click.

After the operation is completed, I wish to redraw the triangle that has modified vertex, but triangle does not change.

I have received log message that button has changed vertex of triangle but triangle didn't change.

I need help guys.

This is my code:-

method pos_change / sign_changed / plus and minus is modification for triangle vertex rotate

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];
}

And that was button code:

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');

        }
    });

And that code was in the onDrawFrame:

@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);
}
Was it helpful?

Solution

lol i solve my problem it just simple problem

i draw array that used float buffer.

I want draw realtime that mean i click button and that redraw with new vertex

So.. i have many manymanymanymanymanymanymanymany think about my problem

answer was constructor . constructor is method that was only one build in class

Yes, vertex was changed but buffer was not changed!!

    public void draw(GL10 gl){
    array_Plus();
    mVertexBuffer = getFloatBufferFromFloatArray(vertices);
    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);
    //mVertexBuffer.clear();
    array_Minus();
}

ㅁ and that i delete constructor(default)

I`m ashamed register answer for my question but i know who have problem same to me in USA or my country

so i post with get brave

ps.sorry for my awkward english

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top