Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Transform incorrectly updates local matrix in clean() #257

Open
ghost opened this issue Apr 3, 2015 · 0 comments
Open

Transform incorrectly updates local matrix in clean() #257

ghost opened this issue Apr 3, 2015 · 0 comments
Milestone

Comments

@ghost
Copy link

ghost commented Apr 3, 2015

In clean(), the local matrix is updated as follows: (lines 218-229)

                //translate to origin
        local.matrix.makeTranslation( origin.x, origin.y, origin.z );

                //scale up relative to origin
            local.matrix.scale(local.scale);
                //rotation relative to origin
            local.matrix.multiply(_rotation_matrix);
                //apply position
            local.matrix.setPosition( local.pos );

            //undo origin translation
        local.matrix.multiply(_origin_undo_matrix);

matrix.setPosition() sets or overwrites the position in the matrix, which means there is no need to undo the origin translation in the next line. Since the undo origin translation is present, this causes some unusual effects when a Visual's parent has the origin assigned to something other than (0,0,0):
transform_bug
This is the code used:

        player = new Sprite( {
            name:"player",
            centered:true,
            pos:new Vector(100, 150),
            texture:Luxe.loadTexture("assets/player.png"),
        } );
        player.add(new PlayerMovement());
        new Sprite( {
            name:'rock',
            texture:Luxe.loadTexture("assets/rock.png"),
            centered:true,
            parent:player,
        } );

In my opinion, the expected behavior is the rock should be directly on top of the sprite, since its position is (0,0), but because of this bug, the rocks position is actually (-16, -16) (relative to the player) because the player sprite, the rock's parent, is centered (has an origin of (16, 16)).

When I comment out the undo origin translation locally, the camera and rendering are incorrect, so those probably depend on transform's current broken behavior, and will have to be fixed too.

@ruby0x1 ruby0x1 modified the milestones: LD33 Prep, 1.0.0 beta Aug 12, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant