Permalink
Browse files

move perspective matrices over to utils

  • Loading branch information...
J.P.P Treub
J.P.P Treub committed Jan 18, 2016
1 parent 45633ea commit 8e8fda5b3469e59c71fecfa9cfc2517710a65f30
Showing with 17 additions and 17 deletions.
  1. +1 −17 framer/Layer.coffee
  2. +16 −0 framer/Utils.coffee
@@ -253,27 +253,11 @@ class exports.Layer extends BaseClass
.multiply(@matrix)
.translate(-@originX * @width, -@originY * @height)
_perspectiveProjectionMatrix: (element) =>
p = element.perspective
m = new Matrix()
m.m34 = -1/p if p? and p isnt 0
return m
# matrix of perspective projection with perspective origin applied
_perspectiveMatrix: (element) =>
ox = element.perspectiveOriginX * element.width
oy = element.perspectiveOriginY * element.height
ppm = @_perspectiveProjectionMatrix(element)
return new Matrix()
.translate(ox, oy)
.multiply(ppm)
.translate(-ox, -oy)
# matrix of layer transforms with perspective applied
@define "matrix3d",
get: ->
parent = @superLayer or @context
ppm = @_perspectiveMatrix(parent)
ppm = Utils.perspectiveMatrix(parent)
return new Matrix()
.multiply(ppm)
.multiply(@transformMatrix)
@@ -1,5 +1,6 @@
{_} = require "./Underscore"
{Screen} = require "./Screen"
{Matrix} = require "./Matrix"
Utils = {}
@@ -811,6 +812,21 @@ Utils.boundingFrame = (layer, rootContext=true) ->
boundingFrame = Utils.frameFromPoints(contextCornerPoints)
return Utils.pixelAlignedFrame(boundingFrame)
Utils.perspectiveProjectionMatrix = (element) ->
p = element.perspective
m = new Matrix()
m.m34 = -1/p if p? and p isnt 0
return m
# matrix of perspective projection with perspective origin applied
Utils.perspectiveMatrix = (element) ->
ox = element.perspectiveOriginX * element.width
oy = element.perspectiveOriginY * element.height
ppm = Utils.perspectiveProjectionMatrix(element)
return new Matrix()
.translate(ox, oy)
.multiply(ppm)
.translate(-ox, -oy)
###################################################################
# Beta additions, use with care

0 comments on commit 8e8fda5

Please sign in to comment.