mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-03-25 23:09:08 +00:00
Add Vector3 class
* Add Vector3 class * Add Vector3 test
This commit is contained in:
parent
d2b6a8c451
commit
9d76d08948
3 changed files with 50 additions and 0 deletions
|
|
@ -1,10 +1,14 @@
|
|||
// Copyright (c) 2016 PSForever.net to present
|
||||
package net.psforever.newcodecs
|
||||
|
||||
import scodec.Attempt
|
||||
import scodec.Attempt.{Failure, Successful}
|
||||
import scodec.Codec
|
||||
|
||||
package object newcodecs {
|
||||
|
||||
def q_double(min: Double, max: Double, bits: Int): Codec[Double] = new QuantizedDoubleCodec(min, max, bits)
|
||||
|
||||
def q_float(min : Double, max : Double, bits : Int): Codec[Float] = q_double(min, max, bits).narrow(v => Attempt.successful(v.toFloat), _.toDouble)
|
||||
|
||||
}
|
||||
|
|
|
|||
24
common/src/main/scala/net/psforever/types/Vector3.scala
Normal file
24
common/src/main/scala/net/psforever/types/Vector3.scala
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (c) 2016 PSForever.net to present
|
||||
package net.psforever.types
|
||||
|
||||
import net.psforever.newcodecs._
|
||||
import scodec.Codec
|
||||
import scodec.codecs._
|
||||
|
||||
final case class Vector3(x : Float,
|
||||
y : Float,
|
||||
z : Float)
|
||||
|
||||
object Vector3 {
|
||||
implicit val codec_pos : Codec[Vector3] = (
|
||||
("x" | newcodecs.q_float(0.0, 8192.0, 20)) ::
|
||||
("y" | newcodecs.q_float(0.0, 8192.0, 20)) ::
|
||||
("z" | newcodecs.q_float(0.0, 1024.0, 16))
|
||||
).as[Vector3]
|
||||
|
||||
implicit val codec_vel : Codec[Vector3] = (
|
||||
("x" | newcodecs.q_float(-256.0, 256.0, 14)) ::
|
||||
("y" | newcodecs.q_float(-256.0, 256.0, 14)) ::
|
||||
("z" | newcodecs.q_float(-256.0, 256.0, 14))
|
||||
).as[Vector3]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue