PageRenderTime 18ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Research/Example projects/CameraTest/src/com/example/Cursor.java

https://bitbucket.org/DeveloperUX/behaviortree
Java | 66 lines | 55 code | 10 blank | 1 comment | 1 complexity | bd3fa1336548119533ae2cde97a67f1d MD5 | raw file
 1package com.example;
 2import java.nio.ByteBuffer;
 3import java.nio.ByteOrder;
 4import java.nio.FloatBuffer;
 5
 6import javax.microedition.khronos.egl.EGLConfig;
 7import javax.microedition.khronos.opengles.GL10;
 8import android.opengl.GLSurfaceView;
 9import android.opengl.GLU;
10
11public class Cursor {
12	public int x;
13	public int y;
14	public int rx;
15	public int by;
16	public boolean bHasToBeOnScreen;
17	
18	float[] square = new float[] 
19	                  	     { 	10f, 10f, 0.0f,
20	                  			-10f, 10f, 0.0f,
21	                  			10f, -10f, 0.0f,
22	                  			-10f, -10f, 0.0f };
23	FloatBuffer floatBuff;
24	
25	public Cursor(int x, int y, boolean onScreen)
26	{
27		this.x = x;
28		this.y = y;		
29		this.rx = x + 20;
30		this.by = y + 20;
31		this.bHasToBeOnScreen = onScreen;
32		floatBuff = makeFloatBuffer(square);
33    }
34    
35    protected static FloatBuffer makeFloatBuffer(float[] arr) 
36    {
37		ByteBuffer bb = ByteBuffer.allocateDirect(arr.length*4);
38		bb.order(ByteOrder.nativeOrder());
39		FloatBuffer fb = bb.asFloatBuffer();
40		fb.put(arr);
41		fb.position(0);
42		return fb;
43	}
44
45	
46	public void Draw(GL10 gl)
47	{
48		gl.glPushMatrix();
49		
50		if(bHasToBeOnScreen)
51		{
52			gl.glColor4f(0.5f, 0.5f, 0, 0.5f);
53		}
54		else
55		{
56			gl.glColor4f(0, 0.5f, 0.5f, 0.5f);
57		}
58		
59		gl.glTranslatef(x,y,0);	
60		gl.glVertexPointer(3, GL10.GL_FLOAT, 0, floatBuff);
61		//gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
62		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
63		
64		gl.glPopMatrix();
65	}
66}