All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cwinter.codecraft.graphics.primitives.SquarePrimitive.scala Maven / Gradle / Ivy

The newest version!
package cwinter.codecraft.graphics.primitives

import cwinter.codecraft.graphics.materials.Material
import cwinter.codecraft.graphics.model.PrimitiveModelBuilder
import cwinter.codecraft.util.maths.{Vertex, VertexXYZ}

import scala.reflect.ClassTag


private[codecraft] case class SquarePrimitive[TColor <: Vertex : ClassTag, TParams](
  material: Material[VertexXYZ, TColor, TParams],
  midpointX: Float,
  midpointY: Float,
  width: Float,
  color: TColor,
  zPos: Float
) extends PrimitiveModelBuilder[SquarePrimitive[TColor, TParams], TColor, TParams] {
  val shape = this

  protected override def computeVertexData(): Seq[(VertexXYZ, TColor)] = {
    val p1 = VertexXYZ(midpointX + width, midpointY + width, zPos)
    val p2 = VertexXYZ(midpointX - width, midpointY + width, zPos)
    val p3 = VertexXYZ(midpointX - width, midpointY - width, zPos)
    val p4 = VertexXYZ(midpointX + width, midpointY - width, zPos)

    val vertexPos =
      Seq(
        p1, p2, p3,
        p1, p3, p4
      )

    val colors = vertexPos.map(_ => color)

    vertexPos zip colors
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy