Skip to content

Commit

Permalink
Implement rotation around vertical axis
Browse files Browse the repository at this point in the history
  • Loading branch information
plweegie committed Jun 20, 2020
1 parent e58894e commit f3aef59
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class MagMolActivity : AppCompatActivity() {
}
transformableNode = TransformableNode(arFragment.transformationSystem).apply {
setParent(anchorNode)
worldPosition = position.adjustPosition()
}

arFragment.arSceneView.scene.addChild(anchorNode)
Expand All @@ -97,9 +98,9 @@ class MagMolActivity : AppCompatActivity() {
loading_pb?.visibility = View.GONE

Node().apply {
setParent(transformableNode)
worldPosition = position.adjustPosition()
renderable = ShapeFactory.makeSphere(0.05f, Vector3.zero(), material)
setParent(transformableNode)
}
}

Expand All @@ -117,4 +118,4 @@ class MagMolActivity : AppCompatActivity() {
}

fun Vector3.adjustPosition(): Vector3 =
Vector3.subtract(this.scaled(0.05f), Vector3(0.0f, 0.2f, 0.5f))
Vector3.subtract(this.scaled(0.05f), Vector3(0.0f, 0.2f, 0.7f))
13 changes: 4 additions & 9 deletions app/src/main/java/com/plweegie/magmolecular/ar/MagMolFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,11 @@ class MagMolFragment : ArFragment() {
override fun onUpdated(gesture: DragGesture?) {
endPosition = gesture?.position
val angle = getRotationAngle(startPosition, endPosition)
val rotationAxis = gesture?.targetNode?.parent?.parent?.worldPosition

rotationAxis?.let { axis ->
val adjustedRotationAxis = Vector3(axis.x, axis.y, axis.z)

gesture.targetNode?.parent?.parent?.worldRotation = Quaternion.multiply(
gesture.targetNode?.parent?.parent?.worldRotation,
Quaternion.axisAngle(adjustedRotationAxis, angle)
)
}
gesture?.targetNode?.parent?.localRotation = Quaternion.multiply(
gesture?.targetNode?.parent?.localRotation,
Quaternion.axisAngle(Vector3.up().scaled(4.0f), angle)
)
}

override fun onFinished(gesture: DragGesture?) {}
Expand Down

0 comments on commit f3aef59

Please sign in to comment.