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.

29 lines
814 B

4 years ago
4 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
  1. package wow.doge.mygame.math;
  2. import cats.Show
  3. import math.{abs, pow, sqrt}
  4. case class ImVector3f(x: Float, y: Float, z: Float)
  5. object ImVector3f {
  6. val ZERO = ImVector3f(0, 0, 0)
  7. val UNIT_X = ImVector3f(1, 0, 0)
  8. val UNIT_Y = ImVector3f(0, 1, 0)
  9. val UNIT_Z = ImVector3f(0, 0, 1)
  10. def dst(v1: ImVector3f, v2: ImVector3f) =
  11. sqrt(
  12. pow((v1.x - v2.x).toDouble, 2) + pow((v1.y - v2.y).toDouble, 2) + pow(
  13. (v1.z - v2.z).toDouble,
  14. 2
  15. )
  16. )
  17. def manhattanDst(v1: ImVector3f, v2: ImVector3f) =
  18. abs(v1.x - v2.x) + abs(v1.y - v2.y) + abs(v1.z - v2.z)
  19. implicit val showForImVector3f = new Show[ImVector3f] {
  20. def format(f: Float) = f.formatted("%.2f")
  21. override def show(t: ImVector3f): String =
  22. s"ImVector3f(${format(t.x)},${format(t.y)},${format(t.z)})"
  23. }
  24. }