Skip to content
This repository has been archived by the owner on Mar 2, 2018. It is now read-only.

Commit

Permalink
Merge pull request #28 from googlesamples/release-nash
Browse files Browse the repository at this point in the history
release-nash
  • Loading branch information
r4ravi2008 committed May 15, 2015
2 parents 3827954 + 28e9e13 commit 129691b
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 58 deletions.
Binary file modified AreaLearningJava/libs/tango_java_lib.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ALRenderer extends Renderer implements GLSurfaceView.Renderer {
private CameraFrustum mCameraFrustum;
private CameraFrustumAndAxis mCameraFrustumAndAxis;
private Grid mFloorGrid;

private boolean mIsValid = false;
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// Set background color and enable depth testing
Expand All @@ -63,6 +63,7 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
Matrix.setIdentityM(mViewMatrix, 0);
Matrix.setLookAtM(mViewMatrix, 0, 5f, 5f, 5f, 0f, 0f, 0f, 0f, 1f, 0f);
mCameraFrustumAndAxis.setModelMatrix(getModelMatCalculator().getModelMatrix());
mIsValid = true;
}

@Override
Expand Down Expand Up @@ -99,5 +100,9 @@ public Trajectory getBlueTrajectory() {
public Trajectory getGreenTrajectory() {
return mGreenTrajectory;
}

public boolean isValid(){
return mIsValid;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void onPoseAvailable(TangoPoseData pose) {
mAdf2DevicePoseDelta = (pose.timestamp - mAdf2DevicePreviousPoseTimeStamp)
* SECONDS_TO_MILLI;
mAdf2DevicePreviousPoseTimeStamp = pose.timestamp;
if (mIsRelocalized) {
if (mIsRelocalized && mRenderer.isValid()) {
updateRenderer = true;
mRenderer.getGreenTrajectory().updateTrajectory(translation);
}
Expand All @@ -292,7 +292,7 @@ public void onPoseAvailable(TangoPoseData pose) {
mStart2DevicePoseDelta = (pose.timestamp - mStart2DevicePreviousPoseTimeStamp)
* SECONDS_TO_MILLI;
mStart2DevicePreviousPoseTimeStamp = pose.timestamp;
if (!mIsRelocalized) {
if (!mIsRelocalized && mRenderer.isValid()) {
updateRenderer = true;

synchronized (mRenderer.getBlueTrajectory()) {
Expand Down Expand Up @@ -324,7 +324,7 @@ public void onPoseAvailable(TangoPoseData pose) {

// Update the trajectory, model matrix, and view matrix, then
// render the scene again
if (updateRenderer) {
if (updateRenderer && mRenderer.isValid()) {
mRenderer.getModelMatCalculator().updateModelMatrix(translation,
pose.getRotationAsFloats());
mRenderer.updateViewMatrix();
Expand Down
Binary file modified MotionTrackingJava/libs/tango_java_lib.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class MTGLRenderer extends Renderer implements GLSurfaceView.Renderer {
private CameraFrustum mCameraFrustum;
private CameraFrustumAndAxis mCameraFrustumAndAxis;
private Grid mFloorGrid;

private boolean mIsValid = false;
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {

Expand All @@ -62,6 +62,7 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
Matrix.setIdentityM(mViewMatrix, 0);
Matrix.setLookAtM(mViewMatrix, 0, 5f, 5f, 5f, 0f, 0f, 0f, 0f, 1f, 0f);
mCameraFrustumAndAxis.setModelMatrix(getModelMatCalculator().getModelMatrix());
mIsValid = true;

}

Expand Down Expand Up @@ -94,5 +95,8 @@ public CameraFrustumAndAxis getCameraFrustumAndAxis() {
public Trajectory getTrajectory() {
return mTrajectory;
}


public boolean isValid(){
return mIsValid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ public void onPoseAvailable(final TangoPoseData pose) {
// Update the OpenGL renderable objects with the new Tango Pose
// data
float[] translation = pose.getTranslationAsFloats();
if(!mRenderer.isValid()){
return;
}
mRenderer.getTrajectory().updateTrajectory(translation);
mRenderer.getModelMatCalculator().updateModelMatrix(translation,
pose.getRotationAsFloats());
Expand Down
Binary file modified PointCloudJava/libs/tango_java_lib.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class PCRenderer extends Renderer implements GLSurfaceView.Renderer {
private Grid mGrid;
private CameraFrustumAndAxis mCameraFrustumAndAxis;
private int mMaxDepthPoints;

private boolean mIsValid = false;
public PCRenderer(int maxDepthPoints) {
mMaxDepthPoints = maxDepthPoints;
}
Expand All @@ -61,6 +61,7 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
Matrix.setIdentityM(mViewMatrix, 0);
Matrix.setLookAtM(mViewMatrix, 0, 5f, 5f, 5f, 0f, 0f, 0f, 0f, 1f, 0f);
mCameraFrustumAndAxis.setModelMatrix(getModelMatCalculator().getModelMatrix());
mIsValid = true;
}

@Override
Expand All @@ -86,4 +87,8 @@ public void onDrawFrame(GL10 gl) {
public PointCloud getPointCloud() {
return mPointCloud;
}

public boolean isValid(){
return mIsValid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ protected void onCreate(Bundle savedInstanceState) {
mThirdPersonButton.setOnClickListener(this);
mTopDownButton = (Button) findViewById(R.id.top_down_button);
mTopDownButton.setOnClickListener(this);

mTango = new Tango(this);
mConfig = new TangoConfig();
mConfig = mTango.getConfig(TangoConfig.CONFIG_TYPE_CURRENT);
Expand Down Expand Up @@ -279,6 +278,9 @@ public void onPoseAvailable(final TangoPoseData pose) {
}
count++;
mPreviousPoseStatus = pose.statusCode;
if(!mRenderer.isValid()){
return;
}
mRenderer.getModelMatCalculator().updateModelMatrix(
pose.getTranslationAsFloats(), pose.getRotationAsFloats());
mRenderer.updateViewMatrix();
Expand All @@ -295,28 +297,20 @@ public void onXyzIjAvailable(final TangoXyzIjData xyzIj) {
mPointCloudFrameDelta = (mCurrentTimeStamp - mXyIjPreviousTimeStamp)
* SECS_TO_MILLISECS;
mXyIjPreviousTimeStamp = mCurrentTimeStamp;
mPointCount = xyzIj.xyzCount;
byte[] buffer = new byte[xyzIj.xyzCount * 3 * 4];
// TODO: Use getXYZBuffer() call instead of parcel file directly.
FileInputStream fileStream = new FileInputStream(xyzIj.xyzParcelFileDescriptor
.getFileDescriptor());
try {
fileStream.read(buffer, xyzIj.xyzParcelFileDescriptorOffset, buffer.length);
fileStream.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
TangoPoseData pointCloudPose = mTango.getPoseAtTime(mCurrentTimeStamp,
framePairs.get(0));

mRenderer.getPointCloud().UpdatePoints(buffer, xyzIj.xyzCount);
framePairs.get(0));
mPointCount = xyzIj.xyzCount;
if(!mRenderer.isValid()){
return;
}
mRenderer.getPointCloud().UpdatePoints(xyzIj.xyz);
mRenderer.getModelMatCalculator().updatePointCloudModelMatrix(
pointCloudPose.getTranslationAsFloats(),
pointCloudPose.getRotationAsFloats());
pointCloudPose.getTranslationAsFloats(),
pointCloudPose.getRotationAsFloats());
mRenderer.getPointCloud().setModelMatrix(
mRenderer.getModelMatCalculator().getPointCloudModelMatrixCopy());
} catch (TangoErrorException e) {
} catch (TangoErrorException e) {
Toast.makeText(getApplicationContext(), R.string.TangoError,
Toast.LENGTH_SHORT).show();
} catch (TangoInvalidException e) {
Expand Down
2 changes: 1 addition & 1 deletion QuickstartJava/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.projecttango.quickstartjava.MainActivity"
android:name="com.projecttango.experiments.quickstartjava.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Binary file modified QuickstartJava/libs/tango_java_lib.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.projecttango.quickstartjava;
package com.projecttango.experiments.quickstartjava;

import java.util.ArrayList;

Expand All @@ -27,6 +27,7 @@
import com.google.atap.tangoservice.TangoOutOfDateException;
import com.google.atap.tangoservice.TangoPoseData;
import com.google.atap.tangoservice.TangoXyzIjData;
import com.projecttango.quickstartjava.R;

import android.annotation.SuppressLint;
import android.app.Activity;
Expand All @@ -36,6 +37,7 @@
import android.widget.TextView;
import android.widget.Toast;


/**
* Main Activity for the Tango Java Quickstart. Demonstrates establishing a
* connection to the {@link Tango} service and printing the {@link TangoPose}
Expand All @@ -53,7 +55,7 @@ public class MainActivity extends Activity {
private Tango mTango;
private TangoConfig mConfig;
private boolean mIsTangoServiceConnected;

private boolean mIsProcessing = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -153,6 +155,12 @@ private void setTangoListeners() {
@SuppressLint("DefaultLocale")
@Override
public void onPoseAvailable(TangoPoseData pose) {
if (mIsProcessing) {
Log.i(TAG, "Processing UI");
return;
}
mIsProcessing = true;

// Format Translation and Rotation data
final String translationMsg = String.format(sTranslationFormat,
pose.translation[0], pose.translation[1],
Expand All @@ -175,6 +183,7 @@ public void onPoseAvailable(TangoPoseData pose) {
public void run() {
mTranslationTextView.setText(translationMsg);
mRotationTextView.setText(rotationMsg);
mIsProcessing = false;
}
});
}
Expand Down
15 changes: 15 additions & 0 deletions TangoUtils/src/com/projecttango/tangoutils/Renderer.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.*/

package com.projecttango.tangoutils;

import android.opengl.Matrix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.util.concurrent.atomic.AtomicBoolean;

import android.opengl.GLES20;
import android.opengl.Matrix;
Expand All @@ -43,7 +44,11 @@ public class PointCloud extends Renderable {

private static final int BYTES_PER_FLOAT = 4;
private static final int POINT_TO_XYZ = 3;
private FloatBuffer mVertexBuffer;

int mVertexVBO; // VertexBufferObject.
private AtomicBoolean mUpdateVBO = new AtomicBoolean();
private volatile FloatBuffer mPointCloudBuffer;

private final int mProgram;
private int mPosHandle;
private int mMVPMatrixHandle;
Expand All @@ -61,42 +66,54 @@ public PointCloud(int maxDepthPoints) {
GLES20.glAttachShader(mProgram, fragShader);
GLES20.glLinkProgram(mProgram);
Matrix.setIdentityM(getModelMatrix(), 0);
mVertexBuffer = ByteBuffer
.allocateDirect(maxDepthPoints * BYTES_PER_FLOAT * POINT_TO_XYZ)
.order(ByteOrder.nativeOrder()).asFloatBuffer();

final int buffers[] = new int[1];
GLES20.glGenBuffers(1, buffers, 0);
mVertexVBO = buffers[0];
}

public synchronized void UpdatePoints(byte[] byteArray, int pointCount) {
FloatBuffer mPointCloudFloatBuffer;
mPointCloudFloatBuffer = ByteBuffer.wrap(byteArray)
.order(ByteOrder.nativeOrder()).asFloatBuffer();
mPointCount = pointCount;
mVertexBuffer.clear();
mVertexBuffer.position(0);
mVertexBuffer.put(mPointCloudFloatBuffer);
float totalZ = 0;
for (int i = 0; i < mPointCloudFloatBuffer.capacity() - 3; i = i + 3) {
totalZ = totalZ + mPointCloudFloatBuffer.get(i + 2);
}
mAverageZ = totalZ / mPointCount;
public synchronized void UpdatePoints(FloatBuffer pointCloudFloatBuffer) {
//save the reference in order to update this in the proper thread.
mPointCloudBuffer = pointCloudFloatBuffer;

//signal the update
mUpdateVBO.set(true);
}

@Override
public synchronized void draw(float[] viewMatrix, float[] projectionMatrix) {
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVertexVBO);

if (mUpdateVBO.getAndSet(false)) {
if (mPointCloudBuffer != null) {
mPointCloudBuffer.position(0);
// Pass the info to the VBO
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mPointCloudBuffer.capacity()
* BYTES_PER_FLOAT, mPointCloudBuffer, GLES20.GL_STATIC_DRAW);
mPointCount = mPointCloudBuffer.capacity() / 3;
float totalZ = 0;
for (int i = 0; i < mPointCloudBuffer.capacity() - 3; i = i + 3) {
totalZ = totalZ + mPointCloudBuffer.get(i + 2);
}
if (mPointCount != 0)
mAverageZ = totalZ / mPointCount;
// signal the update
mUpdateVBO.set(true);
}
mPointCloudBuffer = null;
}

if (mPointCount > 0) {
mVertexBuffer.position(0);

GLES20.glUseProgram(mProgram);
updateMvpMatrix(viewMatrix, projectionMatrix);
mPosHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
GLES20.glVertexAttribPointer(mPosHandle, COORDS_PER_VERTEX,
GLES20.GL_FLOAT, false, 0, mVertexBuffer);
GLES20.glVertexAttribPointer(mPosHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0,
0);
GLES20.glEnableVertexAttribArray(mPosHandle);
mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram,
"uMVPMatrix");
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false,
getMvpMatrix(), 0);
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, getMvpMatrix(), 0);
GLES20.glDrawArrays(GLES20.GL_POINTS, 0, mPointCount);
}
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
}

public float getAverageZ() {
Expand Down
2 changes: 1 addition & 1 deletion VideoOverlaySample/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:name="com.projecttango.experiments.videooverlaysample.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Binary file modified VideoOverlaySample/libs/tango_java_lib.jar
Binary file not shown.
Loading

0 comments on commit 129691b

Please sign in to comment.