1 package com.intel.realsense.librealsense;
3 import android.graphics.Rect;
4 import android.opengl.GLES10;
5 import android.renderscript.Float3;
7 import java.nio.ByteBuffer;
8 import java.nio.ByteOrder;
9 import java.nio.IntBuffer;
14 final private Float3
X =
new Float3(1,0,0);
15 final private Float3
Y =
new Float3(0,1,0);
16 final private Float3
Z =
new Float3(0,0,1);
18 public int getTexture() {
return mGlTexture.array()[0]; }
21 public Color(
float r,
float g,
float b){
31 float newHeight = in.height();
32 float newWidth = in.height() * ratio;
33 if(newWidth > in.width()){
34 ratio = in.width() / newWidth;
39 float newLeft = in.left + (in.width() - newWidth) / 2
f;
40 float newTop = in.top + (in.height() - newHeight) / 2
f;
41 float newRight = newLeft + newWidth;
42 float newBottom = newTop + newHeight;
43 return new Rect((
int)newLeft, (
int)newTop, (
int)newRight, (
int)newBottom);
49 Float3 center =
new Float3(0,0,0);
51 float[] verArray =
new float[N * 3];
52 for (
int i = 0;
i < N;
i++)
54 final double theta = (2* Math.PI / N) *
i;
55 final double cost = Math.cos(theta);
56 final double sint = Math.sin(theta);
57 verArray[
i*3] = ((float) (center.x + radius * (x.x * cost + y.x * sint)));
58 verArray[
i*3 + 1] = ((float) (center.y + radius * (x.y * cost + y.y * sint)));
59 verArray[
i*3 + 2] = ((float) (center.z + radius * (x.z * cost + y.z * sint)));
62 drawLine(verArray, axisWidth, color);
67 ByteBuffer ver = ByteBuffer.allocateDirect(verArray.length * 4);
68 ver.order(ByteOrder.nativeOrder());
69 ver.asFloatBuffer().put(verArray);
71 GLES10.glEnableClientState(GLES10.GL_VERTEX_ARRAY);
73 GLES10.glColor4f(color.red, color.green, color.blue, 1
f);
74 GLES10.glLineWidth(axisWidth);
76 GLES10.glVertexPointer(3, GLES10.GL_FLOAT, 0, ver);
78 GLES10.glDrawArrays(GLES10.GL_LINES,0,verArray.length / 3);
80 GLES10.glDisableClientState(GLES10.GL_VERTEX_ARRAY);
81 GLES10.glColor4f(1
f, 1
f, 1
f, 1
f);
86 ByteBuffer ver = ByteBuffer.allocateDirect(verArray.length * 4);
87 ver.order(ByteOrder.nativeOrder());
88 ver.asFloatBuffer().put(verArray);
90 GLES10.glEnableClientState(GLES10.GL_VERTEX_ARRAY);
92 GLES10.glColor4f(color.red, color.green, color.blue, 1
f);
94 GLES10.glVertexPointer(3, GLES10.GL_FLOAT, 0, ver);
96 GLES10.glDrawArrays(GLES10.GL_TRIANGLES,0,verArray.length / 3);
98 GLES10.glDisableClientState(GLES10.GL_VERTEX_ARRAY);
99 GLES10.glColor4f(1
f, 1
f, 1
f, 1
f);
104 float baseSize = 0.05f * axisSize;
105 float basePos = 0.9f * axisSize;
107 float[] verAxisX = { 0, 0, 0, axisSize, 0, 0 };
108 float[] verTriangleX = {
110 basePos, baseSize, 0,
111 basePos, -baseSize, 0
113 float[] verAxisY = { 0, 0, 0, 0, axisSize, 0 };
114 float[] verTriangleY = {
116 baseSize, basePos, 0,
117 -baseSize, basePos, 0
119 float[] verAxisZ = { 0, 0, 0, 0, 0, axisSize };
120 float[] verTriangleZ = {
122 0, baseSize, basePos,
123 0, -baseSize, basePos
131 drawLine(verAxisY, axisWidth, green);
133 drawLine(verAxisZ, axisWidth, blue);
138 float size = (float) Math.sqrt(md.x * md.x + md.y * md.y + md.z * md.z);
140 (md.x / size) * norm,
141 (md.y / size) * norm,
142 (md.z / size) * norm);
154 GLES10.glMatrixMode(GLES10.GL_PROJECTION);
155 GLES10.glPushMatrix();
156 GLES10.glLoadIdentity();
158 GLES10.glOrthof(-2.8
f, 2.8
f, -2.4
f, 2.4
f, -7
f, 7
f);
160 GLES10.glRotatef(25, 1.0
f, 0.0
f, 0.0
f);
162 GLES10.glTranslatef(0, -0.33
f, -1.
f);
164 GLES10.glRotatef(-135, 0.0
f, 1.0
f, 0.0
f);
165 GLES10.glRotatef(180, 0.0
f, 0.0
f, 1.0
f);
166 GLES10.glRotatef(-90, 0.0
f, 1.0
f, 0.0
f);
179 float norm = axisSize / 2.f;
182 float[] verArray = { 0, 0, 0, md.x, md.y, md.z};
183 Color dir =
new Color(Math.abs(md.x/norm), Math.abs(md.y/norm), Math.abs(md.z/norm));
187 GLES10.glMatrixMode(GLES10.GL_PROJECTION);
188 GLES10.glPopMatrix();
196 return sp.getType().name() +
197 " [ X: " +
String.format(
"%+.2f", d.x) +
198 ", Y: " +
String.format(
"%+.2f", d.y) +
199 ", Z: " +
String.format(
"%+.2f", d.z) +
" ]";
207 if(mGlTexture != null)
208 GLES10.glDeleteTextures(1, mGlTexture);
static const ImVec4 white
GLboolean GLboolean GLboolean b
void drawAxes(Rect rect, float axisSize, float axisWidth)
void drawTriangle(float[] verArray, Color color)
::std_msgs::String_< std::allocator< void > > String
synchronized String getLabel()
Float3 calcMotionData(Float3 md, float norm)
void drawCircle(Float3 x, Float3 y, float axisWidth, Color color)
static void setViewport(Rect r)
synchronized void close()
void drawLine(float[] verArray, float axisWidth, Color color)
synchronized void draw(Rect rect)
Rect adjustRatio(Rect in)
boolean is(Extension extension)
StreamProfile getProfile()