Skip to content
This repository has been archived by the owner on Dec 23, 2018. It is now read-only.

Commit

Permalink
Revert "Add viewport hack to support scaling"
Browse files Browse the repository at this point in the history
Better to not do it at all than do
do it in a hack way.
This reverts commit a8fa63d.
  • Loading branch information
adamlwgriffiths committed Apr 6, 2012
1 parent a8fa63d commit a641563
Showing 1 changed file with 15 additions and 34 deletions.
49 changes: 15 additions & 34 deletions pygly/cocos2d/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@author: adam
TODO: apply layer rotation to the model view
TODO: replace viewport scaling to instead modify the view matrix
TODO: apply layer scaling to the model view
'''

import numpy
Expand Down Expand Up @@ -53,69 +53,50 @@ def draw(self, *args, **kwargs):
# the position and anchor is in pixels
# our viewport is 0->1
# so we must convert from pixels to %
anchor = numpy.array(
[
self.anchor_x,
self.anchor_y
],
dtype = numpy.float32
)

# convert the bottom left and top right
# to a vector
# make them relative to the anchor point
# bottom left
bl = numpy.array(
[
matrix.c,
matrix.g
self.anchor_x - matrix.c,
self.anchor_y - matrix.g
],
dtype = numpy.float32
)
# top right
# assume our size == window size
tr = numpy.array(
[
director.window.width,
director.window.height
director.window.width - anchor_x
director.window.height - anchor_y
],
dtype = numpy.float32
)

# make them relative to the anchor point
bl -= anchor
tr -= anchor

# scale the vectors by the layer's scale
# matrix.a = X scale
# matrix.f = Y scale
bl *= [ matrix.a, matrix.f ]
tr *= [ matrix.a, matrix.f ]

# convert the anchor to a % value
window_size = [
director.window.width,
director.window.height
]

# convert back to window co-ordinates
# instead of being relative to anchor
bl += anchor
tr += anchor

# make the vectors a % value
bl /= director.window.width
tr /= director.window.width

# convert our top right to width / height
tr -= bl
# convert the anchor to a % value
relative_anchor = (
self.anchor_x / director.window.width,
self.anchor_y / director.window.height
)

# matrix.c = X pos
# matrix.g = Y pos
self.pygly_viewport.dimensions = (
bl[ 0 ],
bl[ 1 ],
tr[ 0 ],
tr[ 1 ]
anchor[ 0 ] + bl[ 0 ],
anchor[ 1 ] + bl[ 1 ],
anchor[ 0 ] + tr[ 0 ],
anchor[ 1 ] + tr[ 1 ]
)

# enable depth testing
Expand Down

0 comments on commit a641563

Please sign in to comment.