Testing out JmonkeyEngine to make a game in Scala with Akka Actors within a pure FP layer
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.

94 lines
2.5 KiB

4 years ago
  1. package wow.doge.mygame.game.nodes
  2. import com.jme3.scene.Node
  3. import com.jme3.scene.CameraNode
  4. import com.jme3.scene.Geometry
  5. import com.jme3.renderer.Camera
  6. import wow.doge.mygame.implicits._
  7. import com.jme3.asset.AssetManager
  8. import wow.doge.mygame.state.MyMaterial
  9. import com.jme3.math.Vector3f
  10. import com.jme3.scene.control.CameraControl.ControlDirection
  11. import com.jme3.syntax._
  12. import com.jme3.scene.shape.Box
  13. // class PlayerNode(val name: String) extends Node(name) {}
  14. object PlayerNode {
  15. def defaultMesh() = {
  16. lazy val b = new Box(1, 1, 1)
  17. lazy val geom = new Geometry("playerMesh", b)
  18. geom
  19. }
  20. def defaultTexture(assetManager: AssetManager) =
  21. MyMaterial(
  22. assetManager = assetManager,
  23. path = os.rel / "Common" / "MatDefs" / "Misc" / "Unshaded.j3md"
  24. )
  25. def apply(
  26. modelPath: os.RelPath,
  27. cam: Camera
  28. )(assetManager: AssetManager) = {
  29. lazy val playerNode = new Node("PlayerNode")
  30. lazy val camNode = new CameraNode("CameraNode", cam)
  31. // lazy val camNode = new CameraNode("CameraNode", simpleApp.getCamera())
  32. // camNode.setCamera(simpleApp.getCamera())
  33. val playerModel: Node =
  34. assetManager.loadModel(modelPath).asInstanceOf[Node]
  35. discard {
  36. playerNode
  37. .child(camNode)
  38. .child(playerModel)
  39. // playerNode.children(Seq(camNode, geom))
  40. }
  41. {
  42. camNode.setControlDir(ControlDirection.SpatialToCamera)
  43. camNode.setLocalTranslation(
  44. new Vector3f(0, 1.5f, 10)
  45. )
  46. camNode.lookAt(playerNode.getLocalTranslation(), Vector3f.UNIT_Y)
  47. }
  48. playerNode
  49. }
  50. def apply(
  51. mesh: Geometry = defaultMesh(),
  52. texturePath: os.RelPath =
  53. os.rel / "Common" / "MatDefs" / "Misc" / "Unshaded.j3md",
  54. cam: Camera
  55. )(assetManager: AssetManager): Node = {
  56. lazy val playerNode = new Node("PlayerNode")
  57. lazy val camNode = new CameraNode("CameraNode", cam)
  58. {
  59. val mat = MyMaterial(
  60. assetManager = assetManager,
  61. path = texturePath
  62. )
  63. mesh.setMaterial(mat)
  64. }
  65. // lazy val camNode = new CameraNode("CameraNode", simpleApp.getCamera())
  66. // camNode.setCamera(simpleApp.getCamera())
  67. discard {
  68. playerNode
  69. .child(camNode)
  70. .child(mesh)
  71. // playerNode.children(Seq(camNode, geom))
  72. }
  73. {
  74. camNode.setControlDir(ControlDirection.SpatialToCamera)
  75. camNode.setLocalTranslation(
  76. new Vector3f(0, 1.5f, 10)
  77. )
  78. camNode.lookAt(playerNode.getLocalTranslation(), Vector3f.UNIT_Y)
  79. }
  80. playerNode
  81. }
  82. }