Add color rotation matrix to Parameters

This commit is contained in:
Eryn Wells 2018-10-09 11:57:35 -07:00
parent 0844fbc010
commit d3190dd7e7
3 changed files with 13 additions and 3 deletions

View file

@ -13,6 +13,7 @@ import simd
public typealias Float2 = packed_float2
public typealias Float3 = float3
public typealias Float4 = float4
public typealias Matrix2x2 = float2x2
public typealias Matrix3x3 = float3x3
public typealias Matrix4x4 = float4x4
@ -42,6 +43,15 @@ extension Float4 {
}
}
extension Matrix2x2 {
static func rotation(theta: Float) -> Matrix2x2 {
return self.init(rows: [
Float2(cos(theta), -sin(theta)),
Float2(sin(theta), cos(theta)),
])
}
}
extension Matrix4x4 {
/// Create a 4x4 orthographic projection matrix with the provided 6-tuple.
/// @see https://en.wikipedia.org/wiki/Orthographic_projection

View file

@ -49,6 +49,8 @@ public struct Parameters {
public var color2 = Float4()
public var color3 = Float4()
public var colorRotation = Matrix2x2(1.0)
public var colorStyle: ColorStyle {
get {
return ColorStyle(rawValue: _colorStyle)!
@ -234,9 +236,6 @@ public class Field {
var r = ball.radius
ptr = write(value: &r, to: ptr)
ptr = ptr.advanced(by: 4) // Skip 4 bytes to maintain alignment.
// if idx == 0 {
// print("Populated ball \(idx): x:\(ball.position.x), y:\(ball.position.y), r:\(r)")
// }
idx += 1
}
}

View file

@ -44,6 +44,7 @@ typedef struct {
float target;
float feather;
float4 colors[4];
float2x2 colorRotation;
} Parameters;
typedef float3 Ball;