@viewar/guide
Advanced tools
Comparing version 0.10.1 to 0.11.0
{ | ||
"name": "@viewar/guide", | ||
"version": "0.10.1", | ||
"version": "0.11.0", | ||
"description": "ViewAR Guide", | ||
@@ -5,0 +5,0 @@ "main": "dist/viewar-guide.js", |
@@ -8,2 +8,3 @@ import Vector3 from '../../math/vector3' | ||
import { NO_WAYPOINT } from '../../constants'; | ||
import { projectPointOnEdge } from '../../math/math' | ||
@@ -53,2 +54,8 @@ export default ({ body, navigation, getGuideParams }) => { | ||
const normalizeYPosition = ({x, y, z}) => ({ | ||
x, | ||
y: 0, | ||
z, | ||
}); | ||
/** | ||
@@ -62,9 +69,19 @@ * Get height on line between previous waypoint and current waypoint. | ||
if (previous !== NO_WAYPOINT && current !== NO_WAYPOINT) { | ||
const distance = position.clone().subtract(previous.pose.position).length(); | ||
const orientation = getQuaternionFromVectors(current.pose.position, previous.pose.position); | ||
const { bank } = orientation.toEulerAngles(); | ||
const height = Math.tan(bank) * distance; | ||
return height; | ||
let guidePosition = projectPointOnEdge(normalizeYPosition(position), [normalizeYPosition(current.pose.position), normalizeYPosition(previous.pose.position)]); | ||
if (guidePosition) { | ||
// Linear interpolation between previous and current waypoint. | ||
const currentPosition = new Vector3(current.pose.position); | ||
const previousPosition = new Vector3(previous.pose.position); | ||
const totalDistance = currentPosition.clone().subtract(previousPosition).length(); | ||
const distance = guidePosition.clone().subtract(previousPosition).length(); | ||
const heightDiff = currentPosition.y - previousPosition.y; | ||
const height = previousPosition.y + heightDiff / totalDistance * distance; | ||
return height; | ||
} | ||
} | ||
// Return zero height for first waypoint or if guidePosition can't be projected onto the path. | ||
return 0 | ||
@@ -71,0 +88,0 @@ } |
Sorry, the diff of this file is too big to display
192225
2653