I maybe know understand it all a little bit better so i thoug i make a new shorter question to eventually get an answer.
Get back or delete an existing OpenGL object, then change it and draw at new. How?
So if and Admin reads this post, he can feel free to delete it.
I'm working on OpenGL since a Week, so i'm new to the most stuff. (also my englisch isn't the best. Hop you can understand the most anyway)
So i'm working on an Tamagotchi App for a school project and want to make it with OpenGL. I allready came this far:
But now i want to animate things. My mind told me that it shoud be possible to change or modify an existing OpenGL object. In my situation there are 3 opjekts:
- Body
- Eyes
- Mouth
For example her is my code from the mouth:
public class GLMouth {
private int points = 1000;
private float vertices[]={0.0f,0.0f,0.0f};
private FloatBuffer vertBuff;
private FloatBuffer vertBuff2;
public GLMouth(){
vertices = new float[points * 2];
for(int i=0; i<= (points+3); i+=3)
{
double rad = (Math.PI *i) / points;
vertices[i]=(float)Math.cos(rad);
vertices[i+1]=(float)Math.sin(rad);
vertices[i+2]=0;
}
ByteBuffer bBuff=ByteBuffer.allocateDirect(vertices.length*4);
bBuff.order(ByteOrder.nativeOrder());
vertBuff=bBuff.asFloatBuffer();
vertBuff.put(vertices);
vertBuff.position(0);
vertices = new float[points * 2];
for(int i=0; i< (points+3); i+=3)
{
double rad = -(Math.PI *i) / points;
vertices[i]=(float)Math.cos(rad);
vertices[i+1]=(float)Math.sin(rad);
vertices[i+2]=0;
}
bBuff=ByteBuffer.allocateDirect(vertices.length*4);
bBuff.order(ByteOrder.nativeOrder());
vertBuff2=bBuff.asFloatBuffer();
vertBuff2.put(vertices);
vertBuff2.position(0);
}
public void draw(GL10 gl){
gl.glPushMatrix();
gl.glTranslatef(0.0f, -1.0f, 0.0f);
gl.glScalef(1.8f, 0.15f, 1.0f);
gl.glColor4f(0.0f,0.0f,0.0f, 1.0f);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertBuff);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, points/2);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glPopMatrix();
gl.glPushMatrix();
gl.glTranslatef(0.0f, -1.0f, 0.0f);
gl.glScalef(1.8f, 1.0f, 1.0f);
gl.glColor4f(0.0f,0.0f,0.0f, 1.0f);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertBuff2);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, points/2);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glPopMatrix();
}
}
In my renderer i just creat a mouth object and then draw it with mouth.draw.
So i thought i have allready drawn the mouth and now i can cange for example the gl.glScalef(1.8f, 0.15f, 1.0f); from that existing mouth to zero with some time in between to let it look like the mouth is closing.
But how can i do that? I don't find anything with google, mostly because i don't know what i have to look up. If i understand OpenGL right, than it will just draw new mouths over the original.
edit Or it is a question about where is the opjekt? Can i save it an take it back (delete it etc) and draw it new with other properties.
No comments:
Post a Comment