Skip to content

Commit 5681588

Browse files
Wilhelm Bergabhishektrip
authored andcommitted
Android native location plugin (#724)
* [wip] backport native Android Location Plugin * [wip] backporting native Android GPS * update Android GPS plugin * [wip] LocationProvider example scene * [wip] native android location provider * loop through LocationArrayEditorLocationProvider instead of repeating last position * increase desired accuracy * New scene settings. * [wip] EditorGpsLogLocationProvider * try to rotated map * update scene * fix RotateWithLocationProvider to not overwrite existing rotation values * fix logic for 'IsLocationUpdated' * increase follow factor * [wip]: split Heading into Heading and Orientation * Update scene to move map instead of player. * [wip] try to rotated map * backport Location.DeviceOrientation and Location.UserHeading to default DeviceLocationProvider * [wip] calculate UserHeading with weigthed formula * CircularBuffer tests * fix typos in CircularBuffer test * update changelog * fix DeviceOrientation in LocationProviderTest scene. Some other small fixes. * save scene
1 parent 300f0fa commit 5681588

File tree

44 files changed

+3176
-138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3176
-138
lines changed

documentation/docs/05-changelog.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
## CHANGELOG
1+
## CHANGELOG
22
### v.1.4.2
33
*??/??/2018*
44

5+
##### BREAKING CHANGES
6+
- Property `Heading` on `Location` object has been split into `UserHeading` and `DeviceOrientation`.
7+
- `UserHeading`: the direction the user is moving. This is calculated from the latest position. If the user stops moving the last heading value is kept.
8+
- `DeviceOrientation`: value obtained from the device compass. Where the device is looking to.
9+
510
##### New Features
611
- Add `Location Prefabs` section to `AbstractMap`. Enables users to spawn prefabs at points-of-interest on the map directly from the `AbstractMap` UI.
712
- Add options to spawn prefabs on points-of-interest using `Mapbox Category`, `Name`, or a list of `Address or LatLon`.
813
- Add methods on `AbstractMap` to spawn prefabs. Enables users to add layers via script.
914
- Add the `LocationPrefabs.unity` example scene. Demonstrates the basics of using the `Location Prefabs` feature.
1015
- Add `OnUpdated` event to `AbstractMap`. Enables subscribers to get a notification when the map location and/or zoom gets updated.
16+
- `DeviceLocationProviderAndroidNative`: a native location provider for Android that directly accesses location and orientation provided by the operating system not using Unity's `Input.location` which has some shortcomings, eg coordinates truncated to `float` precision.
17+
**Only available on Android 7.0 (Nougat, API Level 24) and up!**
18+
- `EditorGpsLogLocationProvider`: an Editor location provider to replay real world GPS traces logged with [GNSSLogger](https://github.com/google/gps-measurement-tools/tree/master/GNSSLogger)
19+
- New example scene showing `UserHeading` and `DeviceOrientation`
1120

1221
##### Improvements
1322
- `UnityARInterface` updated to [commit 67351b6](https://github.com/Unity-Technologies/experimental-ARInterface/commit/67351b66ff9af28380e7dd5f5b2f4ba1bf802ca8) from March 1st 2018
23+
- Additional properties on `RotateWithLocationProvider` to account for new `Location` properties `UserHeading` and `DeviceOrientation`.
1424
- Changes to terrain factory (#623)
1525
- Create a new base class
1626
- Introduce all different terrains as strategies
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace Mapbox.Utils
7+
{
8+
9+
10+
public interface ICircularBuffer<T>
11+
{
12+
int Count { get; }
13+
void Add(T item);
14+
T this[int index] { get; }
15+
}
16+
17+
18+
19+
/// <summary>
20+
/// http://geekswithblogs.net/blackrob/archive/2014/09/01/circular-buffer-in-c.aspx
21+
/// https://social.msdn.microsoft.com/Forums/vstudio/en-US/416a2175-b05d-43b1-b99a-a01c56550dbe/circular-buffer-in-net?forum=netfxbcl
22+
/// https://en.wikipedia.org/wiki/Circular_buffer
23+
/// </summary>
24+
/// <typeparam name="T"></typeparam>
25+
public class CircularBuffer<T> : ICircularBuffer<T>, IEnumerable<T>
26+
27+
{
28+
private T[] _buffer;
29+
private int _head;
30+
private int _tail;
31+
32+
33+
public CircularBuffer(int capacity)
34+
{
35+
if (capacity < 0) { throw new ArgumentOutOfRangeException("capacity", "must be positive"); }
36+
_buffer = new T[capacity];
37+
_head = 0;
38+
}
39+
40+
41+
public int Count { get; private set; }
42+
43+
44+
public void Add(T item)
45+
{
46+
_head = (_head + 1) % _buffer.Length;
47+
_buffer[_head] = item;
48+
if (Count == _buffer.Length)
49+
{
50+
_tail = (_tail + 1) % _buffer.Length;
51+
}
52+
else
53+
{
54+
++Count;
55+
}
56+
}
57+
58+
59+
/// <summary>
60+
/// <para>ATTENTION!!! order is flipped like in rolling window</para>
61+
/// <para>[0] is newest value</para>
62+
/// </summary>
63+
/// <param name="index"></param>
64+
/// <returns></returns>
65+
public T this[int index]
66+
{
67+
get
68+
{
69+
if (index < 0 || index >= _buffer.Length) { throw new ArgumentOutOfRangeException("index: " + index.ToString()); }
70+
71+
return _buffer[mod((_head - index), _buffer.Length)];
72+
}
73+
}
74+
75+
76+
private int mod(int x, int m) // x mod m works for both positive and negative x (unlike x % m).
77+
{
78+
return (x % m + m) % m;
79+
}
80+
81+
public IEnumerator<T> GetEnumerator()
82+
{
83+
if (Count == 0 || _buffer.Length == 0)
84+
{
85+
yield break;
86+
}
87+
88+
for (var i = 0; i < Count; ++i) { yield return this[i]; }
89+
}
90+
91+
IEnumerator IEnumerable.GetEnumerator()
92+
{
93+
return GetEnumerator();
94+
}
95+
96+
97+
public IEnumerable<T> GetEnumerable()
98+
{
99+
IEnumerator<T> enumerator = GetEnumerator();
100+
while (enumerator.MoveNext())
101+
{
102+
yield return enumerator.Current;
103+
}
104+
}
105+
106+
107+
}
108+
}

sdkproject/Assets/Mapbox/Core/mapbox-sdk-cs/Utils/CircularBuffer.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdkproject/Assets/Mapbox/Core/mapbox-sdk-cs/Utils/UnixTimestampUtils.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ public static DateTime From(double timestamp)
3939
return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Add(TimeSpan.FromSeconds(timestamp));
4040
}
4141

42+
/// <summary>
43+
/// Convert from Unitx timestamp to DateTime. Uses TimeSpan.FromSeconds to caluclate offset since epoch 0
44+
/// </summary>
45+
/// <param name="timestamp"></param>
46+
/// <returns></returns>
47+
public static DateTime FromMilliseconds(double timestamp)
48+
{
49+
//return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Add(TimeSpan.FromSeconds(timestamp)).ToLocalTime();
50+
return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Add(TimeSpan.FromMilliseconds(timestamp));
51+
}
52+
4253
/// <summary>
4354
/// Convert from Unitx timestamp to DateTime. Uses TimeSpan.FromTicks to caluclate offset since epoch 0
4455
/// </summary>

sdkproject/Assets/Mapbox/Core/probe-extractor-cs/Probe.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static TracePoint FromLocation(Location location)
2727
Timestamp = (long)location.Timestamp,
2828
Latitude = location.LatitudeLongitude.x,
2929
Longitude = location.LatitudeLongitude.y,
30-
Bearing = location.Heading,
30+
Bearing = location.UserHeading,
3131
HDop = location.Accuracy
3232
};
3333
}

sdkproject/Assets/Mapbox/Examples/99_LocationProviderTest.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!21 &2100000
4+
Material:
5+
serializedVersion: 6
6+
m_ObjectHideFlags: 0
7+
m_PrefabParentObject: {fileID: 0}
8+
m_PrefabInternal: {fileID: 0}
9+
m_Name: HeadingMat
10+
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
11+
m_ShaderKeywords: _ALPHATEST_ON
12+
m_LightmapFlags: 4
13+
m_EnableInstancingVariants: 0
14+
m_DoubleSidedGI: 0
15+
m_CustomRenderQueue: 2450
16+
stringTagMap:
17+
RenderType: TransparentCutout
18+
disabledShaderPasses: []
19+
m_SavedProperties:
20+
serializedVersion: 3
21+
m_TexEnvs:
22+
- _BumpMap:
23+
m_Texture: {fileID: 0}
24+
m_Scale: {x: 1, y: 1}
25+
m_Offset: {x: 0, y: 0}
26+
- _DetailAlbedoMap:
27+
m_Texture: {fileID: 0}
28+
m_Scale: {x: 1, y: 1}
29+
m_Offset: {x: 0, y: 0}
30+
- _DetailMask:
31+
m_Texture: {fileID: 0}
32+
m_Scale: {x: 1, y: 1}
33+
m_Offset: {x: 0, y: 0}
34+
- _DetailNormalMap:
35+
m_Texture: {fileID: 0}
36+
m_Scale: {x: 1, y: 1}
37+
m_Offset: {x: 0, y: 0}
38+
- _EmissionMap:
39+
m_Texture: {fileID: 0}
40+
m_Scale: {x: 1, y: 1}
41+
m_Offset: {x: 0, y: 0}
42+
- _MainTex:
43+
m_Texture: {fileID: 0}
44+
m_Scale: {x: 1, y: 1}
45+
m_Offset: {x: 0, y: 0}
46+
- _MetallicGlossMap:
47+
m_Texture: {fileID: 0}
48+
m_Scale: {x: 1, y: 1}
49+
m_Offset: {x: 0, y: 0}
50+
- _OcclusionMap:
51+
m_Texture: {fileID: 0}
52+
m_Scale: {x: 1, y: 1}
53+
m_Offset: {x: 0, y: 0}
54+
- _ParallaxMap:
55+
m_Texture: {fileID: 0}
56+
m_Scale: {x: 1, y: 1}
57+
m_Offset: {x: 0, y: 0}
58+
m_Floats:
59+
- _BumpScale: 1
60+
- _Cutoff: 0.5
61+
- _DetailNormalMapScale: 1
62+
- _DstBlend: 0
63+
- _GlossMapScale: 1
64+
- _Glossiness: 0.5
65+
- _GlossyReflections: 1
66+
- _Metallic: 0
67+
- _Mode: 1
68+
- _OcclusionStrength: 1
69+
- _Parallax: 0.02
70+
- _SmoothnessTextureChannel: 0
71+
- _SpecularHighlights: 1
72+
- _SrcBlend: 1
73+
- _UVSec: 0
74+
- _ZWrite: 1
75+
m_Colors:
76+
- _Color: {r: 0.11724138, g: 1, b: 0, a: 1}
77+
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

sdkproject/Assets/Mapbox/Examples/99_LocationProviderTest/HeadingMat.mat.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)