Friday, January 12, 2018

How to draw an OpenGL object in another on Android? -> Eyes and Eyeballs


As i allready wrote in another question:



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. -> How to change/modify or animate an existing OpenGL object on Android?




So this is a further question.


My Tamagotchi is haveing to eyes. Like this: two eyes of the Tamagotchi


To make it look real i want the eyes to blink and the eyeballs to move arround. But the question here is what happens with the eyeball when the eyes are closed. In my Situation you woud not see the eyeballs because they are the same color then the body of the Tamagotchi. But i want the eyeballs to be a part of the eye. So if the Eye is closing the eyeballs shoud disapear where the eyes are closed whereever the eyeball is at the moment.


Here you can see the eye closed (down scaled y) but the eyeball is still visible.... enter image description here


I want the eyeball to be cut of or not shown where the eye is closed like this:


enter image description here


But i have no idear how to solve this.


Edit Here is my Code for someone who want to look at it. But i think it is not necessary.


public class GLEyes {


private int points = 1000;
private float vertices[]={0.0f,0.0f,0.0f};
private FloatBuffer vertBuff;

//Der Kreis wird von der Mitte der Fläche gezeichnet

public GLEyes(){

vertices = new float[points * 2];

for(int i=0; i< (points+3); i+=3)
{
double rad = 2*(Math.PI *i) / points; //Berechnung des radius

vertices[i]=(float)Math.cos(rad); //X Achsen Abschnitt
vertices[i+1]=(float)Math.sin(rad); //Y Achsen Abschnitt
vertices[i+2]=0; //Z Achsen Abschnitt wird nur für 3D gebraucht
}

ByteBuffer bBuff=ByteBuffer.allocateDirect(vertices.length*4);

bBuff.order(ByteOrder.nativeOrder());
vertBuff=bBuff.asFloatBuffer();
vertBuff.put(vertices);
vertBuff.position(0);
}

public void draw(GL10 gl){

lefteye(gl);
righteye(gl);


}

private void lefteye (GL10 gl){
gl.glPushMatrix();
gl.glTranslatef(1, 1, 0);
gl.glScalef(0.5f, 0.45f, 1.0f); //Skalierung einstellen
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(1, 1, 0);
gl.glScalef(0.1f, 0.1f, 1.0f); //Skalierung einstellen
gl.glColor4f(1.0f,1.0f,1.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();
}

private void righteye (GL10 gl){
gl.glPushMatrix();
gl.glTranslatef(-1, 1, 0);
gl.glScalef(0.5f, 0.45f, 1.0f); //Skalierung einstellen
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(-1, 1, 0);
gl.glScalef(0.1f, 0.1f, 1.0f); //Skalierung einstellen
gl.glColor4f(1.0f,1.0f,1.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();

}


}



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...