Package org.osm2world.viewer.control.actions

Source Code of org.osm2world.viewer.control.actions.ResetCameraAction

package org.osm2world.viewer.control.actions;

import java.awt.event.ActionEvent;
import java.util.Observable;
import java.util.Observer;

import javax.swing.AbstractAction;

import org.osm2world.core.map_data.data.MapData;
import org.osm2world.core.math.VectorXZ;
import org.osm2world.core.target.common.rendering.Camera;
import org.osm2world.viewer.model.Data;
import org.osm2world.viewer.model.Defaults;
import org.osm2world.viewer.model.RenderOptions;
import org.osm2world.viewer.view.ViewerFrame;


public class ResetCameraAction extends AbstractAction implements Observer {

  ViewerFrame viewerFrame;
  Data data;
  RenderOptions renderOptions;

  public ResetCameraAction(ViewerFrame viewerFrame, Data data, RenderOptions renderOptions) {

    super("Reset Camera");
    putValue(SHORT_DESCRIPTION, "Use this if you have messed up the camera");

    this.viewerFrame = viewerFrame;
    this.data = data;
    this.renderOptions = renderOptions;
 
    setEnabled(false);
    data.addObserver(this);
   
  }
 
  @Override
  public void update(Observable o, Object arg) {
    setEnabled(data.getConversionResults() != null);
  }

  @Override
  public void actionPerformed(ActionEvent e) {

    MapData mapData = data.getConversionResults().getMapData();

    VectorXZ camLookAt = mapData.getCenter();

    renderOptions.camera = new Camera();
    renderOptions.camera.setCamera(camLookAt.x, 1000, camLookAt.z-1000,
                                       camLookAt.x, 0, camLookAt.z);
   
    renderOptions.projection = Defaults.PERSPECTIVE_PROJECTION;

  }

}
TOP

Related Classes of org.osm2world.viewer.control.actions.ResetCameraAction

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.