forked from nova/jmonkey-test
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.2 KiB
71 lines
2.2 KiB
package wow.doge.mygame.game.controls
|
|
|
|
import com.jme3.math.Quaternion
|
|
import com.jme3.scene.Node
|
|
import com.jme3.scene.control.AbstractControl
|
|
import com.jme3.renderer.RenderManager
|
|
import com.jme3.renderer.ViewPort
|
|
import monix.reactive.Observable
|
|
import wow.doge.mygame.game.subsystems.input.PlayerCameraInput
|
|
import com.jme3.scene.Spatial
|
|
import monix.{eval => me}
|
|
import com.jme3.math.FastMath
|
|
import com.jme3.math.Vector3f
|
|
import monix.execution.Cancelable
|
|
import monix.execution.Scheduler
|
|
|
|
class CameraMovementControl(
|
|
rotationBuf: Quaternion,
|
|
obs: Observable[PlayerCameraInput],
|
|
rotateFn: Quaternion => Unit
|
|
)(implicit s: Scheduler)
|
|
extends AbstractControl {
|
|
private var _event: PlayerCameraInput = null
|
|
private var _subscriptionToken: Cancelable = null
|
|
|
|
override def controlUpdate(tpf: Float): Unit =
|
|
if (_event != null)
|
|
_event match {
|
|
case PlayerCameraInput.CameraRotateLeft =>
|
|
val rot = rotationBuf
|
|
.fromAngleAxis(1 * FastMath.DEG_TO_RAD, Vector3f.UNIT_Y)
|
|
rotateFn(rot)
|
|
case PlayerCameraInput.CameraRotateRight =>
|
|
val rot = rotationBuf
|
|
.fromAngleAxis(-1 * FastMath.DEG_TO_RAD, Vector3f.UNIT_Y)
|
|
rotateFn(rot)
|
|
case PlayerCameraInput.CameraRotateUp =>
|
|
val rot = rotationBuf
|
|
.fromAngleAxis(-1 * FastMath.DEG_TO_RAD, Vector3f.UNIT_X)
|
|
rotateFn(rot)
|
|
case PlayerCameraInput.CameraRotateDown =>
|
|
val rot = rotationBuf
|
|
.fromAngleAxis(1 * FastMath.DEG_TO_RAD, Vector3f.UNIT_X)
|
|
rotateFn(rot)
|
|
}
|
|
|
|
override def controlRender(
|
|
x$1: RenderManager,
|
|
x$2: ViewPort
|
|
): Unit = {}
|
|
override def setSpatial(spatial: Spatial): Unit = {
|
|
super.setSpatial(spatial)
|
|
if (this.spatial != null)
|
|
_subscriptionToken =
|
|
obs.doOnNext(event => me.Task { _event = event }).subscribe()
|
|
else {
|
|
_subscriptionToken.cancel()
|
|
_subscriptionToken = null
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
class FollowControl(playerNode: Node) extends AbstractControl {
|
|
override def controlUpdate(tpf: Float): Unit =
|
|
this.spatial.setLocalTranslation(playerNode.getLocalTranslation())
|
|
override def controlRender(
|
|
rm: RenderManager,
|
|
vp: ViewPort
|
|
): Unit = {}
|
|
}
|