clean up code

This commit is contained in:
Raffaele Mignone 2019-01-16 21:35:55 +01:00
parent 7d2342692e
commit 2d8254b264
Signed by: norangebit
GPG Key ID: 4B9DF72AB9508845
6 changed files with 24 additions and 37 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -62,6 +62,7 @@ class MainActivity : AppCompatActivity() {
GlobalScope.launch(Dispatchers.Main) {
loadPlanetsJob.join()
val solarSystem = createSolarSystem(renderablePlanets)
addNodeToScene(arFragment, hitResult.createAnchor(), solarSystem)
isModelAdded = true

View File

@ -20,7 +20,6 @@
package it.norangeb.solarsystem
import com.google.ar.sceneform.FrameTime
import com.google.ar.sceneform.Node
import com.google.ar.sceneform.math.Vector3
import com.google.ar.sceneform.rendering.ModelRenderable
@ -28,7 +27,7 @@ import com.google.ar.sceneform.rendering.ModelRenderable
class PlanetNode(
private val planetRenderable: ModelRenderable
) : Node() {
private val planetScale = 0.6f
private val PLANET_SCALE = 0.6f
private var planetVisual: RotationNode? = null
override fun onActivate() {
@ -37,18 +36,12 @@ class PlanetNode(
if (planetVisual == null)
initRotationNode()
}
override fun onUpdate(frameTime: FrameTime?) {
if (scene == null)
return
}
fun initRotationNode() {
planetVisual = RotationNode(false)
private fun initRotationNode() {
planetVisual = RotationNode()
planetVisual?.setParent(this)
planetVisual?.renderable = planetRenderable
planetVisual?.localScale = Vector3(planetScale, planetScale, planetScale)
planetVisual?.localScale = Vector3(PLANET_SCALE, PLANET_SCALE, PLANET_SCALE)
}
}

View File

@ -22,33 +22,21 @@ package it.norangeb.solarsystem
import android.animation.ObjectAnimator
import android.view.animation.LinearInterpolator
import com.google.ar.sceneform.FrameTime
import com.google.ar.sceneform.Node
import com.google.ar.sceneform.math.Quaternion
import com.google.ar.sceneform.math.QuaternionEvaluator
import com.google.ar.sceneform.math.Vector3
class RotationNode(private val isOrbit: Boolean = true) : Node() {
val SPEED_MULTIPLIER = 1
val ROTATION_MULTIPLIER = 1
class RotationNode : Node() {
private val DEGREE = 360000
private var orbitAnimation: ObjectAnimator? = null
var degreesPerSecond = 90.0f
private val animationDuration: Long
get() = (1000 * 360 / (degreesPerSecond * if (isOrbit)
SPEED_MULTIPLIER
else
ROTATION_MULTIPLIER))
get() = (DEGREE / degreesPerSecond)
.toLong()
override fun onUpdate(frameTime: FrameTime?) {
super.onUpdate(frameTime)
if (orbitAnimation == null)
return
}
override fun onActivate() {
startAnimation()
}
@ -58,9 +46,9 @@ class RotationNode(private val isOrbit: Boolean = true) : Node() {
}
private fun startAnimation() {
if (orbitAnimation != null) {
if (orbitAnimation != null)
return
}
orbitAnimation = createAnimator()
orbitAnimation!!.target = this
orbitAnimation!!.duration = animationDuration
@ -68,21 +56,19 @@ class RotationNode(private val isOrbit: Boolean = true) : Node() {
}
private fun stopAnimation() {
if (orbitAnimation == null) {
if (orbitAnimation == null)
return
}
orbitAnimation!!.cancel()
orbitAnimation = null
}
private fun createAnimator(): ObjectAnimator {
val orientation1 = Quaternion.axisAngle(Vector3(0.0f, 1.0f, 0.0f), 0f)
val orientation2 = Quaternion.axisAngle(Vector3(0.0f, 1.0f, 0.0f), 120f)
val orientation3 = Quaternion.axisAngle(Vector3(0.0f, 1.0f, 0.0f), 240f)
val orientation4 = Quaternion.axisAngle(Vector3(0.0f, 1.0f, 0.0f), 360f)
val orientations = arrayOf(0f, 120f, 240f, 360f)
.map { Quaternion.axisAngle(Vector3(0.0f, 1.0f, 0.0f), it) }
val orbitAnimation = ObjectAnimator()
orbitAnimation.setObjectValues(orientation1, orientation2, orientation3, orientation4)
orbitAnimation.setObjectValues(*orientations.toTypedArray())
orbitAnimation.propertyName = "localRotation"

View File

@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong

View File

@ -1,5 +1,6 @@
#Wed Jan 16 18:00:47 CET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip