int[] bits = new int[16]; float[] model = new float[16]; float[] proj = new float[16]; gl.glGetIntegerv(gl.GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES, bits, 0); for(int i = 0; i < bits.length; i++){ model[i] = Float.intBitsToFloat(bits[i]); } ((GL11)gl).glGetIntegerv(gl.GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES, bits, 0); for(int i = 0; i < bits.length; i++){ proj[i] = Float.intBitsToFloat(bits[i]); }
float[] ret = new float[3]; GLU.gluUnProject((float)curX, (float)curY, 0f, model, 0, proj, 0, new int[]{0, 0, getWidth(), getHeight()}, 0, ret, 0); int x = (int)(ret[0] * 0x10000); int y = (int)(ret[1] * 0x10000); int z = (int)(ret[2] * 0x10000);
public class Plane{ protected ByteBuffer mIndexBuffer; protected IntBuffer mVertexBuffer; protected int x, y, z; protected int rotateX, rotateY, rotateZ; protected int width, height;
protected int one = 0x10000; protected int vertices[] = { -one, one, 0, one, one, 0, one, -one, 0, -one, -one, 0, };
protected byte indices[] = { 0, 1, 2, 2, 3, 0 };
public Plane(){ this(1, 1); }
public Plane(int width, int height){ for(int i = 0; i < vertices.length; i+=3){ vertices[i] *= width; vertices[i+1] *= height; } mVertexBuffer = GLUtil.createIntBuffer(vertices); mIndexBuffer = GLUtil.createByteBuffer(indices); }
public void setX(int x){ this.x = x; for(int i = 0; i < vertices.length; i+=3){ mVertexBuffer.put(i, vertices[i] + x); } }
public void setY(int y){ this.y = y; for(int i = 1; i < vertices.length; i+=3){ mVertexBuffer.put(i, vertices[i] + y); } }
public void setZ(int z){ this.z = z; for(int i = 2; i < vertices.length; i+=3){ mVertexBuffer.put(i, vertices[i] + z); } }
public void setRotateX(int rotateX){ this.rotateX = rotateX; double theta = rotateX * Math.PI / 0x10000; double cos = Math.cos(theta); double sin = Math.sin(theta); for(int i = 1; i < vertices.length; i+=3){ double y = (double)(vertices[i]) / 0x10000; double z = (double)(vertices[i+1]) / 0x10000; int flagY = y > 0 ? 1 : -1; double r = Math.sqrt(y * y + z * z); mVertexBuffer.put(i, flagY * (int)(r * cos * 0x10000) + this.y); mVertexBuffer.put(i+1, - flagY * (int)(r * sin * 0x10000) + this.z); } }
public void setRotateY(int rotateY){ this.rotateY = rotateY; double theta = rotateY * Math.PI / 0x10000; double cos = Math.cos(theta); double sin = Math.sin(theta); for(int i = 0; i < vertices.length; i+=3){ double x = (double)(vertices[i]) / 0x10000; double z = (double)(vertices[i+2]) / 0x10000; int flagX = x > 0 ? 1 : -1; double r = Math.sqrt(x * x + z * z); mVertexBuffer.put(i, flagX * (int)(r * cos * 0x10000) + this.x); mVertexBuffer.put(i+2, - flagX * (int)(r *sin * 0x10000) + this.z); } }
public void setRotateZ(int rotateZ){ this.rotateZ = rotateZ; double theta = rotateZ * Math.PI / 0x10000; double cos = Math.cos(theta); double sin = Math.sin(theta); for(int i = 0; i < vertices.length; i+=3){ double x = (double)(vertices[i]) / 0x10000; double y = (double)(vertices[i+1]) / 0x10000; int flagX = x > 0 ? 1 : -1; double r = Math.sqrt(x * x + y * y); mVertexBuffer.put(i, flagX * (int)(r * cos * 0x10000) + this.x); mVertexBuffer.put(i+1, - flagX * (int)(r * sin * 0x10000) + this.y); } }
public int getX(){return x;} public int getY(){return y;} public int getZ(){return z;} public int getRotateX(){return rotateX;} public int getRotateY(){return rotateY;} public int getRotateZ(){return rotateZ;}
public class Android3D extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); View view = new View3D(this); setContentView(view); } }
public class Android3D extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(new View3D(this)); } }
最近のコメント