Created
January 18, 2016 05:13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package temportalist.ropes.common | |
import org.lwjgl.util.vector.Matrix3f | |
import scala.collection.mutable | |
import scala.collection.mutable.ListBuffer | |
/** | |
* Created by TheTemportalist on 1/17/2016. | |
*/ | |
object Ropes { | |
def main(args: Array[String]): Unit = { | |
println("hello world") | |
val data = mutable.Map[Float, Float]() | |
data(-5) = 1 | |
for (x <- -4 to 4) data(x) = 0 | |
data(5) = 1 | |
val dataAsArray = data.toArray | |
val rows = data.size | |
val matrixData = new Array[Array[Float]](rows) | |
val yData = new Array[Array[Float]](rows) | |
for (i <- 0 until rows) { | |
val x = dataAsArray(i)._1 | |
matrixData(i) = Array[Float](1, x, Math.pow(x, 2).toFloat) | |
yData(i) = Array[Float](dataAsArray(i)._2) | |
} | |
val matrix = this.getMatrix3f(matrixData) | |
val mulMatrix = new Matrix3f | |
Matrix3f.mul(matrix.transpose().asInstanceOf[Matrix3f], matrix, mulMatrix) | |
val inverseMulMatrix = mulMatrix.invert() | |
val outMatrix = new Matrix3f | |
Matrix3f.mul(inverseMulMatrix.asInstanceOf[Matrix3f], matrix.transpose().asInstanceOf[Matrix3f], outMatrix) | |
val coefficients = new Matrix3f | |
Matrix3f.mul(outMatrix, this.getMatrix3f(yData), coefficients) | |
} | |
def getMatrix3f(matrix: Array[Array[Float]]): Matrix3f = { | |
val matrixRet = new Matrix3f | |
matrixRet.m00 = matrix(0)(0) | |
matrixRet.m01 = matrix(0)(1) | |
matrixRet.m02 = matrix(0)(2) | |
matrixRet.m10 = matrix(1)(0) | |
matrixRet.m11 = matrix(1)(1) | |
matrixRet.m12 = matrix(1)(1) | |
matrixRet.m20 = matrix(2)(0) | |
matrixRet.m21 = matrix(2)(1) | |
matrixRet.m22 = matrix(2)(2) | |
matrixRet | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment