<commit_before>/*******************************************************************************
 * Copyright (c) 2015 UT-Battelle, LLC.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   <NAME> (<EMAIL>)
 *******************************************************************************/
package org.eclipse.eavp.viz.service.javafx.internal.scene.camera;

import javafx.embed.swt.FXCanvas;
import javafx.geometry.Point3D;
import javafx.scene.Camera;
import javafx.scene.Scene;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent;
import javafx.scene.transform.Affine;
import javafx.scene.transform.Rotate;

/**
 * A camera centered around and gazing towards the origin. The user can rotate
 * the camera about the origin by dragging the mouse and zoom through scrolling
 * the mouse wheel.
 * 
 * @author <NAME>
 *
 */
public class CenteredCameraController extends BasicCameraController {

	/**
	 * The speed at which the camera turns when using the pitch/roll/yaw
	 * functions
	 */
	final private double ROTATION_SPEED = 15;

	/**
	 * The speed at which the camera will be moved for raise/strafe/thrust
	 */
	final private double SPEED = 50;

	private boolean dragStarted;

	/**
	 * The X rotation applied to the camera.
	 */
	private Rotate x;

	/**
	 * The Y rotation applied to the camera.
	 */
	private Rotate y;

	/**
	 * The Z rotation applied to the camera.
	 */
	private Rotate z;

	/**
	 * The default constructor.
	 * 
	 * @param camera
	 *            The camera this controller will manage.
	 * @param scene
	 *            The scene the camera is viewing.
	 * @param canvas
	 *            The FXCanvas containing the scene.
	 */
	public CenteredCameraController(Camera camera, Scene scene,
			FXCanvas canvas) {
		super(camera, scene, canvas);

		// Initialize the data members
		dragStarted = false;

		// Set the x axis rotation for the affine transformation
		x = new Rotate();
		x.setAxis(Rotate.X_AXIS);
		xform.getTransforms().add(x);

		// Set the y axis rotation for the affine transformation
		y = new Rotate();
		y.setAxis(Rotate.Y_AXIS);

		// Set the y axis rotation for the affine transformation
		z = new Rotate();
		z.setAxis(Rotate.Z_AXIS);

		// Apply the rotations and the affine to the camera
		xform.getTransforms().setAll(x, y, z, affine);

	}

	/**
	 * Zoom the camera towards/away from the center point
	 * 
	 * @param distance
	 *            The amount to zoom by. Positive values zoom forward, negative
	 *            values zoom backward.
	 */
	private void zoom(double distance) {

		// Get the current z position and modify it by the distance
		double z = camera.getTranslateZ();
		double newZ = z + distance;
		camera.setTranslateZ(newZ);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.eavp.viz.service.javafx.internal.scene.camera.
	 * AbstractCameraController#handleMouseDragged(javafx.scene.input.
	 * MouseEvent)
	 */
	@Override
	public void handleMouseDragged(MouseEvent event) {

		// Replace the old mouse position
		mouseOldX = mousePosX;
		mouseOldY = mousePosY;

		// Get the current mouse position
		mousePosX = event.getSceneX();
		mousePosY = event.getSceneY();

		// If a drag action is in progress, adjust the camera angle
		if (dragStarted) {

			// Calculate the change in mouse position
			mouseDeltaX = (mousePosX - mouseOldX);
			mouseDeltaY = (mousePosY - mouseOldY);

			// If the primary button is held, then change the camera's position
			if (event.isPrimaryButtonDown()) {
				if (!event.isShiftDown()) {

					// If neither control nor shift are down, rotate about the
					// center
					if (!event.isControlDown()) {
						y.setAngle(y.getAngle() - mouseDeltaX);
						x.setAngle(x.getAngle() + mouseDeltaY);
					}

					// If control is down, zoom
					else {
						zoom(mouseDeltaY);
					}
				}

				// If shift is down, change the center
				else {
					affine.appendTranslation(mouseDeltaX, mouseDeltaY, 0);
				}
			}
		}

		// Ignore the first event of a drag action, as the mouse position will
		// not be properly initialized during it
		else {
			dragStarted = true;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.eavp.viz.service.javafx.internal.scene.camera.
	 * AbstractCameraController#handleMouseReleased(javafx.scene.input.
	 * MouseEvent)
	 */
	@Override
	public void handleMouseReleased(MouseEvent event) {

		// End the current drag action, if any
		dragStarted = false;
	}
<commit_msg>Changed centered camera zoom control<commit_after>/*******************************************************************************
 * Copyright (c) 2015 UT-Battelle, LLC.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   <NAME> (<EMAIL>)
 *******************************************************************************/
package org.eclipse.eavp.viz.service.javafx.internal.scene.camera;

import javafx.embed.swt.FXCanvas;
import javafx.geometry.Point3D;
import javafx.scene.Camera;
import javafx.scene.Scene;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent;
import javafx.scene.transform.Affine;
import javafx.scene.transform.Rotate;

/**
 * A camera centered around and gazing towards the origin. The user can rotate
 * the camera about the origin by dragging the mouse and zoom through scrolling
 * the mouse wheel.
 * 
 * @author <NAME>
 *
 */
public class CenteredCameraController extends BasicCameraController {

	/**
	 * The speed at which the camera turns when using the pitch/roll/yaw
	 * functions
	 */
	final private double ROTATION_SPEED = 15;

	/**
	 * The speed at which the camera will be moved for raise/strafe/thrust
	 */
	final private double SPEED = 50;

	/**
	 * Whether or not the camera is currently undergoing a drag action.
	 */
	private boolean dragStarted;

	/**
	 * The X rotation applied to the camera.
	 */
	private Rotate x;

	/**
	 * The Y rotation applied to the camera.
	 */
	private Rotate y;

	/**
	 * The Z rotation applied to the camera.
	 */
	private Rotate z;

	/**
	 * The default constructor.
	 * 
	 * @param camera
	 *            The camera this controller will manage.
	 * @param scene
	 *            The scene the camera is viewing.
	 * @param canvas
	 *            The FXCanvas containing the scene.
	 */
	public CenteredCameraController(Camera camera, Scene scene,
			FXCanvas canvas) {
		super(camera, scene, canvas);

		// Initialize the data members
		dragStarted = false;

		// Set the x axis rotation for the affine transformation
		x = new Rotate();
		x.setAxis(Rotate.X_AXIS);
		xform.getTransforms().add(x);

		// Set the y axis rotation for the affine transformation
		y = new Rotate();
		y.setAxis(Rotate.Y_AXIS);

		// Set the y axis rotation for the affine transformation
		z = new Rotate();
		z.setAxis(Rotate.Z_AXIS);

		// Apply the rotations and the affine to the camera
		xform.getTransforms().setAll(x, y, z, affine);

	}

	/**
	 * Zoom the camera towards/away from the center point
	 * 
	 * @param distance
	 *            The amount to zoom by. Positive values zoom forward, negative
	 *            values zoom backward.
	 */
	private void zoom(double distance) {

		// Get the current z position and modify it by the distance
		double z = camera.getTranslateZ();
		double newZ = z + distance;
		camera.setTranslateZ(newZ);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.eavp.viz.service.javafx.internal.scene.camera.
	 * AbstractCameraController#handleMouseDragged(javafx.scene.input.
	 * MouseEvent)
	 */
	@Override
	public void handleMouseDragged(MouseEvent event) {

		// Replace the old mouse position
		mouseOldX = mousePosX;
		mouseOldY = mousePosY;

		// Get the current mouse position
		mousePosX = event.getSceneX();
		mousePosY = event.getSceneY();

		// If a drag action is in progress, adjust the camera angle
		if (dragStarted) {

			// Calculate the change in mouse position
			mouseDeltaX = (mousePosX - mouseOldX);
			mouseDeltaY = (mousePosY - mouseOldY);

			// If the primary button is held, then change the camera's position
			if (event.isPrimaryButtonDown()) {
				if (!event.isShiftDown()) {

					// If neither control nor shift are down, rotate about the
					// center
					if (!event.isControlDown()) {
						y.setAngle(y.getAngle() - mouseDeltaX);
						x.setAngle(x.getAngle() + mouseDeltaY);
					}

					// If control is down, zoom
					else {
						zoom(-mouseDeltaY);
					}
				}

				// If shift is down, change the center
				else {
					affine.appendTranslation(mouseDeltaX, mouseDeltaY, 0);
				}
			}
		}

		// Ignore the first event of a drag action, as the mouse position will
		// not be properly initialized during it
		else {
			dragStarted = true;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.eavp.viz.service.javafx.internal.scene.camera.
	 * AbstractCameraController#handleMouseReleased(javafx.scene.input.
	 * MouseEvent)
	 */
	@Override
	public void handleMouseReleased(MouseEvent event) {

		// End the current drag action, if any
		dragStarted = false;
	}

{'fraction_non_alphanumeric': 0.12879991526321363, 'fraction_numerical': 0.0029657875225082087, 'mean_word_length': 3.170494699646643, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3757503', 'n_tokens_mistral': 3153, 'n_tokens_neox': 2707, 'n_words': 907}