Beispiel #1
0
    def get_local_transform(self):
        '''returns an euclid.Matrix3 with the local transformation matrix'''
        if self.is_transform_dirty:

            matrix = euclid.Matrix3().identity()

            matrix.translate(self._x, self._y)
            matrix.translate(self.transform_anchor_x, self.transform_anchor_y)
            matrix.rotate(math.radians(-self.rotation))
            matrix.scale(self._scale, self._scale)
            matrix.translate(-self.transform_anchor_x,
                             -self.transform_anchor_y)

            self.is_transform_dirty = False

            self.transform_matrix = matrix

        return self.transform_matrix
def test_m3inv():
    """
    Test the euclid Matrix3 inversion code.

    Dov Grobgeld <*****@*****.**>
    Sunday 2011-03-13 00:13
    """
    syms = 'abcefgijk'

    def assert_m3_unity(m):
        """Assert that matrix is a unity"""
        epsilon = 1e-8
        for s in 'afk':
            assert abs(m.__getattribute__(s) - 1.0) < epsilon
        for s in 'bcegij':
            assert abs(m.__getattribute__(s)) < epsilon

    # Create a "random" matrix and calculate its inverse
    m = euclid.Matrix3().rotate(1.0).translate(3, 4).scale(1.5, 0.7)
    minv = m.inverse()
    assert_m3_unity(minv * m)
Beispiel #3
0
    def __init__(self):
        # composition stuff

        #: list of (int, child-reference) where int is the z-order, sorted by ascending z (back to front order)
        self.children = []

        #: dictionary that maps children names with children references
        self.children_names = {}

        self._parent = None

        # drawing stuff

        #: x-position of the object relative to its parent's children_anchor_x value.
        #: Default: 0
        self._x = 0

        #: y-position of the object relative to its parent's children_anchor_y value.
        #: Default: 0
        self._y = 0

        #: a float, alters the scale of this node and its children.
        #: Default: 1.0
        self._scale = 1.0

        #: a float, in degrees, alters the rotation of this node and its children.
        #: Default: 0.0
        self._rotation = 0.0

        #: eye, center and up vector for the `Camera`.
        #: gluLookAt() is used with these values.
        #: Default: FOV 60, center of the screen.
        #: IMPORTANT: The camera can perform exactly the same
        #: transformation as ``scale``, ``rotation`` and the
        #: ``x``, ``y`` attributes (with the exception that the
        #: camera can modify also the z-coordinate)
        #: In fact, they all transform the same matrix, so
        #: use either the camera or the other attributes, but not both
        #: since the camera will be overridden by the transformations done
        #: by the other attributes.
        #: You can change the camera manually or by using the `Camera3DAction`
        #: action.
        self.camera = Camera()


        #: offset from (x,0) from where rotation and scale will be applied.
        #: Default: 0
        self.transform_anchor_x = 0

        #: offset from (0,y) from where rotation and scale will be applied.
        #: Default: 0
        self.transform_anchor_y = 0

        #: whether of not the object and his childrens are visible.
        #: Default: True
        self.visible = True

        #: the grid object for the grid actions.
        #: This can be a `Grid3D` or a `TiledGrid3D` object depending
        #: on the action.
        self.grid = None

        # actions stuff
        #: list of `Action` objects that are running
        self.actions = []

        #: list of `Action` objects to be removed
        self.to_remove = []

        #: whether or not the next frame will be skipped
        self.skip_frame = False

        # schedule stuff
        self.scheduled = False          # deprecated, soon to be removed
        self.scheduled_calls = []       #: list of scheduled callbacks
        self.scheduled_interval_calls = []  #: list of scheduled interval callbacks
        self.is_running = False         #: whether of not the object is running

        # matrix stuff
        self.is_transform_dirty = False
        self.transform_matrix = euclid.Matrix3().identity()
        self.is_inverse_transform_dirty = False
        self.inverse_transform_matrix = euclid.Matrix3().identity()
Beispiel #4
0
#!/usr/bin/python
"""
Test the euclid Matrix3 inversion code.

Dov Grobgeld <*****@*****.**>
Sunday 2011-03-13 00:13 
"""

import euclid
import math

syms = 'abcefgijk'


def assert_m3_unity(m):
    """Assert that matrix is a unity"""
    epsilon = 1e-8
    for s in 'afk':
        assert (abs(m.__getattribute__(s) - 1.0) < epsilon)
    for s in 'bcegij':
        assert (abs(m.__getattribute__(s)) < epsilon)


# Create a "random" matrix and calculate its inverse
m = euclid.Matrix3().rotate(1.0).translate(3, 4).scale(1.5, 0.7)
minv = m.inverse()
assert_m3_unity(minv * m)

print "Ok!"