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.
104 lines
2.9 KiB
104 lines
2.9 KiB
package wow.doge.mygame.game.nodes
|
|
|
|
import com.jme3.scene.Node
|
|
import com.jme3.scene.CameraNode
|
|
import com.jme3.scene.Geometry
|
|
import com.jme3.renderer.Camera
|
|
import com.jme3.asset.AssetManager
|
|
import wow.doge.mygame.state.MyMaterial
|
|
import com.jme3.math.Vector3f
|
|
import com.jme3.scene.control.CameraControl.ControlDirection
|
|
import com.jme3.syntax._
|
|
import com.jme3.scene.shape.Box
|
|
import com.jme3.bullet.control.BetterCharacterControl
|
|
import com.jme3.bullet.BulletAppState
|
|
import wow.doge.mygame.game.GameApp
|
|
import wow.doge.mygame.implicits._
|
|
import wow.doge.mygame.math.ImVector3f
|
|
import com.jme3.math.FastMath
|
|
|
|
// class PlayerNode(val name: String) extends Node(name) {}
|
|
trait Player
|
|
object PlayerController {
|
|
def defaultMesh = {
|
|
lazy val b = new Box(1, 1, 1)
|
|
lazy val geom = new Geometry("playerMesh", b)
|
|
geom
|
|
}
|
|
def defaultTexture(assetManager: AssetManager) =
|
|
MyMaterial(
|
|
assetManager = assetManager,
|
|
path = os.rel / "Common" / "MatDefs" / "Misc" / "Unshaded.j3md"
|
|
)
|
|
|
|
def apply(
|
|
app: GameApp,
|
|
modelPath: os.RelPath,
|
|
cam: Camera
|
|
)(assetManager: AssetManager, bulletAppState: BulletAppState) = {
|
|
lazy val playerPos = ImVector3f.ZERO
|
|
lazy val playerPhysicsControl = new BetterCharacterControl(1.5f, 6f, 1f)
|
|
.withJumpForce(ImVector3f(0, 5f, 0))
|
|
lazy val playerNode = new Node("PlayerNode")
|
|
.withChildren(
|
|
new CameraNode("CameraNode", cam)
|
|
.withControlDir(ControlDirection.SpatialToCamera)
|
|
.withLocalTranslation(ImVector3f(0, 1.5f, 10))
|
|
.withLookAt(playerPos, ImVector3f.UNIT_Y),
|
|
assetManager
|
|
.loadModel(modelPath)
|
|
.asInstanceOf[Node]
|
|
.withRotate(0, FastMath.PI, 0)
|
|
)
|
|
.withLocalTranslation(playerPos)
|
|
.withControl(playerPhysicsControl)
|
|
|
|
{
|
|
bulletAppState.physicsSpace += playerNode
|
|
bulletAppState.physicsSpace += playerPhysicsControl
|
|
}
|
|
|
|
{
|
|
app.rootNode += playerNode
|
|
}
|
|
|
|
playerPhysicsControl
|
|
}
|
|
def apply(
|
|
mesh: Geometry = defaultMesh,
|
|
texturePath: os.RelPath =
|
|
os.rel / "Common" / "MatDefs" / "Misc" / "Unshaded.j3md",
|
|
cam: Camera
|
|
)(assetManager: AssetManager): Node = {
|
|
|
|
lazy val playerNode = new Node("PlayerNode")
|
|
lazy val camNode = new CameraNode("CameraNode", cam)
|
|
|
|
{
|
|
val mat = MyMaterial(
|
|
assetManager = assetManager,
|
|
path = texturePath
|
|
)
|
|
mesh.setMaterial(mat)
|
|
}
|
|
|
|
// lazy val camNode = new CameraNode("CameraNode", simpleApp.getCamera())
|
|
// camNode.setCamera(simpleApp.getCamera())
|
|
discard {
|
|
playerNode
|
|
.withChild(camNode)
|
|
.withChild(mesh)
|
|
// playerNode.children(Seq(camNode, geom))
|
|
}
|
|
|
|
{
|
|
camNode.setControlDir(ControlDirection.SpatialToCamera)
|
|
camNode.setLocalTranslation(
|
|
new Vector3f(0, 1.5f, 10)
|
|
)
|
|
camNode.lookAt(playerNode.getLocalTranslation(), Vector3f.UNIT_Y)
|
|
}
|
|
|
|
playerNode
|
|
}
|
|
}
|