Package composition.java

Source Code of composition.java.MovingTranslator

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package composition.java;

import composition.effects.EffectData;
import composition.effects.Effectable;
import factories.Points;
import graphics.common.Point;
import graphics.common.Velocity;
import java.awt.Graphics2D;

/**
*
* @author Freezerburn
*/
public class MovingTranslator implements Compositor, Effectable {
   
    private Point mOrigin, mDest;
    private Velocity mSpeed;
    private double mTime;
    private Point mPrevMove, mMoved, mPredictedMove;

    public MovingTranslator( Point origin, Point dest, double time ) {
        mOrigin = origin;
        mDest = dest;
        mTime = time;
        mPrevMove = Points.get( mOrigin );
        mMoved = Points.get( mOrigin );
        mPredictedMove = Points.get( mOrigin );
    }

    @Override
    public void apply( Graphics2D g, double delta ) {
        double distX = (mOrigin.getRealX() - mDest.getRealX()) * (delta / mTime);
        double distY = (mOrigin.getRealX() - mDest.getRealY()) * (delta / mTime);
        mPrevMove.set( mMoved );
        mMoved.modify( distX, distY, 0.0 );
        mPredictedMove.modify( distX * 2, distY * 2, 0.0 );
        g.getTransform().translate( mMoved.getRealX(), mMoved.getRealY() );
    }

    @Override
    public void reverse() {
        Point temp = mOrigin;
        mOrigin = mDest;
        mDest = temp;
        temp = null;
    }

    @Override
    public void revert( Graphics2D g ) {
        g.getTransform().translate( -mMoved.getRealX(), -mMoved.getRealY() );
    }

    @Override
    public boolean isFinished() {
        throw new UnsupportedOperationException( "Not supported yet." );
    }

    @Override
    public EffectData getData() {
        return new EffectData() {
            @Override
            public boolean isPosSupported() { return true; }
            @Override
            public Point getStartPos() { return mPrevMove; }
            @Override
            public Point getCurPos() { return mMoved; }
            @Override
            public Point getEndPos() { return mPredictedMove; }
        };
    }
}
TOP

Related Classes of composition.java.MovingTranslator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.