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

Commit

Permalink
update to 1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
jguomoto committed Mar 26, 2015
1 parent fd7c662 commit 587a85c
Show file tree
Hide file tree
Showing 22 changed files with 82 additions and 130 deletions.
Binary file not shown.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ MonoBehaviour:
m_enableDepth: 0
m_motionTrackingAutoReset: 1
m_enableAreaLearning: 0
m_enableADFSaveLoad: 0
m_enableUXLibrary: 0
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using UnityEngine;
using System;
using UnityEngine;
using Tango;

/// <summary>
/// Get Tango events from Tango Service and log on GUI.
/// </summary>
public class EventController : TangoEventListener {
public class EventController : TangoEventListener
{
private string m_eventString;
private TangoApplication m_tangoApplication;
private TangoEvent m_previousEvent;
Expand All @@ -37,6 +38,9 @@ void Start ()
m_previousEvent = new TangoEvent();
}

/// <summary>
/// Send tango event to be parsed by the UX library.
/// </summary>
private void Update()
{
if(m_dirty)
Expand All @@ -55,32 +59,10 @@ private void Update()
/// <param name="tangoEvent">Tango event.</param>
protected override void _onEventAvailable(IntPtr callbackContext, TangoEvent tangoEvent)
{
//m_eventString = tangoEvent.event_key + ": " + tangoEvent.event_value;

m_previousEvent.timestamp = tangoEvent.timestamp;
m_previousEvent.type = tangoEvent.type;
m_previousEvent.event_key = tangoEvent.event_key;
m_previousEvent.event_value = tangoEvent.event_value;
m_dirty = true;

//Debug.Log(m_eventString);
}

/// <summary>
/// GUI function logs Tango event on screen.
/// </summary>
void OnGUI()
{
Color oldColor = GUI.color;
GUI.color = Color.black;
if (m_tangoApplication.HasRequestedPermissions())
{
// Event logging.
GUI.Label(new Rect(Common.UI_LABEL_START_X,
Common.UI_EVENT_LABEL_START_Y,
Common.UI_LABEL_SIZE_X ,
Common.UI_LABEL_SIZE_Y), Common.UI_FONT_SIZE + String.Format(Common.UX_TANGO_SYSTEM_EVENT, m_eventString) + "</size>");
GUI.color = oldColor;
}
}
}
Binary file modified AreaLearningUnity/ProjectSettings/ProjectSettings.asset
Binary file not shown.
Binary file not shown.

This file was deleted.

21 changes: 18 additions & 3 deletions MotionTrackingUnity/Assets/Scripts/PoseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,20 @@ public enum TrackingTypes
private Vector3 m_tangoPosition;
private bool m_isDirty = false;

// Matrix for Tango coordinate frame to Unity coordinate frame conversion.
// Start of service frame with respect to Unity world frame.
// We use couple of matrix transformation to convert the pose from Tango coordinate
// frame to Unity coordinate frame.
// The full equation is:
// Matrix4x4 uwTuc = m_uwTss * ssTd * m_dTuc;
//
// uwTuc: Unity camera with respect to Unity world, this is the desired matrix.
// m_uwTss: Constant matrix converting start of service frame to Unity world frame.
// ssTd: Device frame with repect to start of service frame, this matrix denotes the
// pose transform we get from pose callback.
// m_dTuc: Constant matrix converting Unity world frame frame to device frame.
//
// Please see the coordinate system section online for more information:
// https://developers.google.com/project-tango/overview/coordinate-systems
private Matrix4x4 m_uwTss;
// Unity camera frame with respect to device frame.
private Matrix4x4 m_dTuc;

// Flag for initilizing Tango.
Expand All @@ -65,12 +75,14 @@ public enum TrackingTypes
/// </summary>
private void Awake()
{
// Constant matrix converting start of service frame to Unity world frame.
m_uwTss = new Matrix4x4();
m_uwTss.SetColumn (0, new Vector4 (1.0f, 0.0f, 0.0f, 0.0f));
m_uwTss.SetColumn (1, new Vector4 (0.0f, 0.0f, 1.0f, 0.0f));
m_uwTss.SetColumn (2, new Vector4 (0.0f, 1.0f, 0.0f, 0.0f));
m_uwTss.SetColumn (3, new Vector4 (0.0f, 0.0f, 0.0f, 1.0f));

// Constant matrix converting Unity world frame frame to device frame.
m_dTuc = new Matrix4x4();
m_dTuc.SetColumn (0, new Vector4 (1.0f, 0.0f, 0.0f, 0.0f));
m_dTuc.SetColumn (1, new Vector4 (0.0f, 1.0f, 0.0f, 0.0f));
Expand Down Expand Up @@ -139,7 +151,10 @@ private void Update()
}
if (m_isDirty)
{
// Construct the start of service with respect to device matrix from the pose.
Matrix4x4 ssTd = Matrix4x4.TRS(m_tangoPosition, m_tangoRotation, Vector3.one);

// Converting from Tango coordinate frame to Unity coodinate frame.
Matrix4x4 uwTuc = m_uwTss * ssTd * m_dTuc;

// Extract new local position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ MonoBehaviour:
m_enableDepth: 0
m_motionTrackingAutoReset: 1
m_enableAreaLearning: 0
m_enableADFSaveLoad: 0
m_enableUXLibrary: 0
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using UnityEngine;
using System;
using UnityEngine;
using Tango;

/// <summary>
/// Get Tango events from Tango Service and log on GUI.
/// </summary>
public class EventController : TangoEventListener {
public class EventController : TangoEventListener
{
private string m_eventString;
private TangoApplication m_tangoApplication;
private TangoEvent m_previousEvent;
Expand All @@ -37,6 +38,9 @@ void Start ()
m_previousEvent = new TangoEvent();
}

/// <summary>
/// Send tango event to be parsed by the UX library.
/// </summary>
private void Update()
{
if(m_dirty)
Expand All @@ -55,32 +59,10 @@ private void Update()
/// <param name="tangoEvent">Tango event.</param>
protected override void _onEventAvailable(IntPtr callbackContext, TangoEvent tangoEvent)
{
//m_eventString = tangoEvent.event_key + ": " + tangoEvent.event_value;

m_previousEvent.timestamp = tangoEvent.timestamp;
m_previousEvent.type = tangoEvent.type;
m_previousEvent.event_key = tangoEvent.event_key;
m_previousEvent.event_value = tangoEvent.event_value;
m_dirty = true;

//Debug.Log(m_eventString);
}

/// <summary>
/// GUI function logs Tango event on screen.
/// </summary>
void OnGUI()
{
Color oldColor = GUI.color;
GUI.color = Color.black;
if (m_tangoApplication.HasRequestedPermissions())
{
// Event logging.
GUI.Label(new Rect(Common.UI_LABEL_START_X,
Common.UI_EVENT_LABEL_START_Y,
Common.UI_LABEL_SIZE_X ,
Common.UI_LABEL_SIZE_Y), Common.UI_FONT_SIZE + String.Format(Common.UX_TANGO_SYSTEM_EVENT, m_eventString) + "</size>");
GUI.color = oldColor;
}
}
}
Binary file modified MotionTrackingUnity/ProjectSettings/ProjectSettings.asset
Binary file not shown.
Binary file not shown.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ MonoBehaviour:
m_enableDepth: 0
m_motionTrackingAutoReset: 1
m_enableAreaLearning: 0
m_enableADFSaveLoad: 0
m_enableUXLibrary: 0
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using UnityEngine;
using System;
using UnityEngine;
using Tango;

/// <summary>
/// Get Tango events from Tango Service and log on GUI.
/// </summary>
public class EventController : TangoEventListener {
public class EventController : TangoEventListener
{
private string m_eventString;
private TangoApplication m_tangoApplication;
private TangoEvent m_previousEvent;
Expand All @@ -37,6 +38,9 @@ void Start ()
m_previousEvent = new TangoEvent();
}

/// <summary>
/// Send tango event to be parsed by the UX library.
/// </summary>
private void Update()
{
if(m_dirty)
Expand All @@ -55,32 +59,10 @@ private void Update()
/// <param name="tangoEvent">Tango event.</param>
protected override void _onEventAvailable(IntPtr callbackContext, TangoEvent tangoEvent)
{
//m_eventString = tangoEvent.event_key + ": " + tangoEvent.event_value;

m_previousEvent.timestamp = tangoEvent.timestamp;
m_previousEvent.type = tangoEvent.type;
m_previousEvent.event_key = tangoEvent.event_key;
m_previousEvent.event_value = tangoEvent.event_value;
m_dirty = true;

//Debug.Log(m_eventString);
}

/// <summary>
/// GUI function logs Tango event on screen.
/// </summary>
void OnGUI()
{
Color oldColor = GUI.color;
GUI.color = Color.black;
if (m_tangoApplication.HasRequestedPermissions())
{
// Event logging.
GUI.Label(new Rect(Common.UI_LABEL_START_X,
Common.UI_EVENT_LABEL_START_Y,
Common.UI_LABEL_SIZE_X ,
Common.UI_LABEL_SIZE_Y), Common.UI_FONT_SIZE + String.Format(Common.UX_TANGO_SYSTEM_EVENT, m_eventString) + "</size>");
GUI.color = oldColor;
}
}
}
Binary file not shown.

This file was deleted.

45 changes: 30 additions & 15 deletions PointCloudUnity/Assets/Scripts/Pointcloud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Pointcloud : DepthListener
private TangoApplication m_tangoApplication;

// Matrices for transforming pointcloud to world coordinates.
// This equation will take account of the camera sensors extrinsic.
// Full equation is:
// Matrix4x4 uwTuc = m_uwTss * m_ssTd * Matrix4x4.Inverse(m_imuTd) * m_imuTc * m_cTuc;
private Matrix4x4 m_uwTss = new Matrix4x4 ();
Expand Down Expand Up @@ -104,37 +105,49 @@ private void Update()
TangoCoordinateFramePair pair;
TangoPoseData poseData = new TangoPoseData();

// Query the extrinsics between IMU and device frame.
pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_IMU;
pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE;
PoseProvider.GetPoseAtTime(poseData, timestamp, pair);
Vector3 position = new Vector3((float)poseData.translation[0], (float)poseData.translation[1], (float)poseData.translation[2]);
Quaternion quat = new Quaternion((float)poseData.orientation[0], (float)poseData.orientation[1], (float)poseData.orientation[2], (float)poseData.orientation[3]);
Vector3 position = new Vector3((float)poseData.translation[0],
(float)poseData.translation[1],
(float)poseData.translation[2]);
Quaternion quat = new Quaternion((float)poseData.orientation[0],
(float)poseData.orientation[1],
(float)poseData.orientation[2],
(float)poseData.orientation[3]);
m_imuTd = Matrix4x4.TRS(position, quat, new Vector3 (1.0f, 1.0f, 1.0f));

// Query the extrinsics between IMU and color camera frame.
pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_IMU;
pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_CAMERA_COLOR;
PoseProvider.GetPoseAtTime(poseData, timestamp, pair);
position = new Vector3((float)poseData.translation[0], (float)poseData.translation[1], (float)poseData.translation[2]);
quat = new Quaternion((float)poseData.orientation[0], (float)poseData.orientation[1], (float)poseData.orientation[2], (float)poseData.orientation[3]);
position = new Vector3((float)poseData.translation[0],
(float)poseData.translation[1],
(float)poseData.translation[2]);
quat = new Quaternion((float)poseData.orientation[0],
(float)poseData.orientation[1],
(float)poseData.orientation[2],
(float)poseData.orientation[3]);
m_imuTc = Matrix4x4.TRS(position, quat, new Vector3 (1.0f, 1.0f, 1.0f));

// Query pose to transform point cloud to world coordinates.
// Query pose to transform point cloud to world coordinates, here we are using the timestamp
// that we get from depth.
pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_START_OF_SERVICE;
pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE;
PoseProvider.GetPoseAtTime(poseData, m_previousDepthDeltaTime, pair);
position = new Vector3((float)poseData.translation[0], (float)poseData.translation[1], (float)poseData.translation[2]);
quat = new Quaternion((float)poseData.orientation[0], (float)poseData.orientation[1], (float)poseData.orientation[2], (float)poseData.orientation[3]);
position = new Vector3((float)poseData.translation[0],
(float)poseData.translation[1],
(float)poseData.translation[2]);
quat = new Quaternion((float)poseData.orientation[0],
(float)poseData.orientation[1],
(float)poseData.orientation[2],
(float)poseData.orientation[3]);
m_ssTd = Matrix4x4.TRS(position, quat, Vector3.one);

// The transformation matrix that represents the pointcloud's pose.
Matrix4x4 uwTuc = m_uwTss * m_ssTd * Matrix4x4.Inverse(m_imuTd) * m_imuTc * m_cTuc;
print("---------------------------------------------------------------");
print("uwTuc = " + uwTuc.ToString());
print("m_uwTss = " + m_uwTss.ToString());
print("m_ssTd = " + m_ssTd.ToString());
print("m_imuTd = " + m_imuTd.ToString());
print("m_imuTc = " + m_imuTc.ToString());
print("m_cTuc = " + m_cTuc.ToString());
print("---------------------------------------------------------------");

transform.position = uwTuc.GetColumn(3);
transform.rotation = Quaternion.LookRotation(uwTuc.GetColumn(2), uwTuc.GetColumn(1));

Expand Down Expand Up @@ -183,6 +196,8 @@ protected override void _OnDepthAvailable(IntPtr callbackContext, TangoXYZij xyz
{
if( i < xyzij.xyz_count )
{
// Note that we are doing a simple axis switch to convert the point from
// depth camera coordinate frame to Unity coordinate frame.
m_vertices[i].x = allPositions[i * 3];
m_vertices[i].y = -allPositions[(i * 3) + 1];
m_vertices[i].z = allPositions[(i * 3) + 2];
Expand Down
2 changes: 2 additions & 0 deletions PointCloudUnity/Assets/Scripts/PoseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ public enum TrackingTypes
/// </summary>
private void Awake()
{
// Constant matrix converting start of service frame to Unity world frame.
m_uwTss = new Matrix4x4();
m_uwTss.SetColumn (0, new Vector4 (1.0f, 0.0f, 0.0f, 0.0f));
m_uwTss.SetColumn (1, new Vector4 (0.0f, 0.0f, 1.0f, 0.0f));
m_uwTss.SetColumn (2, new Vector4 (0.0f, 1.0f, 0.0f, 0.0f));
m_uwTss.SetColumn (3, new Vector4 (0.0f, 0.0f, 0.0f, 1.0f));

// Constant matrix converting Unity world frame frame to device frame.
m_cTuc.SetColumn (0, new Vector4 (1.0f, 0.0f, 0.0f, 0.0f));
m_cTuc.SetColumn (1, new Vector4 (0.0f, -1.0f, 0.0f, 0.0f));
m_cTuc.SetColumn (2, new Vector4 (0.0f, 0.0f, 1.0f, 0.0f));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ MonoBehaviour:
m_enableDepth: 0
m_motionTrackingAutoReset: 1
m_enableAreaLearning: 0
m_enableADFSaveLoad: 0
m_enableUXLibrary: 0
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
Expand Down
Loading

0 comments on commit 587a85c

Please sign in to comment.