(Android で) OpenGL を学習しています。私のコードでは、四面体を形成する 4 つの三角形を指定していますが、何らかの理由で 2 つの側面が欠けているように見え、その理由がわかりません。考えられるほとんどすべての方法で微調整しましたが、まだうまくいきません。
これが私のコードです。何か間違ったことをしている場合は教えてください。
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import javax.microedition.khronos.opengles.GL10;
public class Tetrahedron {
private IntBuffer ver;
private IntBuffer nor;
private ByteBuffer ind;
private float[] mat_ambient;
private float[] mat_diffuse;
private float[] mat_specular;
private float[] mat_emission;
public Tetrahedron() {
int one = toInt(1.0f);
int vertices[] = {
//face 1
-one, -one, one, //point 1
0 , one, 0 , //point 2
one, -one, one, //point 3
//face 2
0 , one, 0 , //point 2
one, -one, one, //point 3
0 , 0 , -one, //point 4
//face 3
one, -one, one, //point 3
0 , 0 , -one, //point 4
-one, -one, one, //point 1
//face 4
0 , 0 , -one, //point 4
-one, -one, one, //point 1
0 , one, 0 //point 2
};
int normals[] = {
-one, -one, one,
0 , one, one,
one, -one, one,
one, one, -one,
one, 0 , 0 ,
one, one, -one,
one, -one, one,
0 , -one, -one,
-one, -one, one,
-one, one, -one,
-one, 0 , 0 ,
-one, one, -one
};
byte indices[] = {
0, 1, 2,
3, 4, 5,
6, 7, 8,
9,10,11
};
ver=getIntBuffer(vertices);
nor=getIntBuffer(normals);
ind=getByteBuffer(indices);
mat_ambient = new float[4];
mat_ambient[0] = 0.3f;
mat_ambient[1] = 0.3f;
mat_ambient[2] = 0.3f;
mat_ambient[3] = 1.0f;
mat_diffuse = new float[4];
mat_diffuse[0] = 0.9f;
mat_diffuse[1] = 0.9f;
mat_diffuse[2] = 0.9f;
mat_diffuse[3] = 1.0f;
mat_specular = new float[4];
mat_specular[0] = 0.1f;
mat_specular[1] = 0.1f;
mat_specular[2] = 0.1f;
mat_specular[3] = 1.0f;
mat_emission = new float[4];
mat_emission[0] = 0.0f;
mat_emission[1] = 1.0f;
mat_emission[2] = 0.0f;
mat_emission[3] = 1.0f;
}
private IntBuffer getIntBuffer(int[] data){
ByteBuffer byteBuf = ByteBuffer.allocateDirect(data.length * 4);
byteBuf.order(ByteOrder.nativeOrder());
IntBuffer buf = byteBuf.asIntBuffer();
buf.put(data);
buf.position(0);
return buf;
}
private ByteBuffer getByteBuffer(byte[] data){
ByteBuffer buf = ByteBuffer.allocateDirect(data.length);
buf.put(data);
buf.position(0);
return buf;
}
private int toInt(float num){
return (int)(num*65536);
}
public void draw(GL10 gl){
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, mat_ambient, 0);
gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, mat_diffuse, 0);
gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR, mat_specular, 0);
gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_EMISSION, mat_emission, 0);
gl.glMaterialf(GL10.GL_FRONT, GL10.GL_SHININESS, 56);
gl.glFrontFace(GL10.GL_CW);
gl.glVertexPointer(3, GL10.GL_FIXED, 0, ver);
gl.glNormalPointer(GL10.GL_FIXED, 0, nor);
gl.glDrawElements(GL10.GL_TRIANGLES, ind.capacity(), GL10.GL_UNSIGNED_BYTE, ind);
gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
}