<commit_before>/* global AFRAME */
var parabolicCurve = require('./lib/ParabolicCurve');
var RayCurve = require('./lib/RayCurve');

if (typeof AFRAME === 'undefined') {
  throw new Error('Component attempted to register before AFRAME was available.');
}

var buttons = ['trackpad', 'trigger', 'grip', 'menu', 'thumbstick', 'A', 'B', 'X', 'Y', 'surface', 'point', 'pointing', 'pistol', 'thumb'];
var events = ['down', 'up', 'open', 'close', 'start', 'end', 'touchstart', 'touchend'];

/* global THREE AFRAME  */
AFRAME.registerComponent('teleport-controls', {
  schema: {
    type: {default: 'parabolic', oneOf: ['parabolic', 'line']},
    button: {default: 'pointing', oneOf: buttons},
    startEvent: {default: 'start', oneOf: events},
    endEvent: {default: 'end', oneOf: events},
    collisionEntity: { type: 'selector' },
    objects: {default: ''},
    hitEntity: {type: 'selector'},
    playerEntity: { type: 'selector' },
    defaultPlaneSize: {default: 5000},
    hitCylinderColor: {type: 'color', default: '#99ff99'},
    hitCylinderRadius: {default: 0.25, min: 0},
    hitCylinderHeight: {default: 0.3, min: 0},
    maxLength: {default: 10, min: 0, if: {type: ['line']}},
    curveNumberPoints: {default: 30, min: 2, if: {type: ['parabolic']}},
    curveLineWidth: {default: 0.025},
    curveHitColor: {type: 'color', default: '#99ff99'},
    curveMissColor: {type: 'color', default: '#ff0000'},
    curveShootingSpeed: {default: 5, min: 0, if: {type: ['parabolic']}},
    landingNormal: {type: 'vec3', default: '0 1 0'},
    landingMaxAngle: {default: '45', min: 0, max: 360}
  },

  init: function () {
    this.active = false;
    this.obj = this.el.object3D;
    this.hitPoint = new THREE.Vector3();
    this.hit = false;
    this.prevHeightDiff = 0;
    this.referenceNormal = new THREE.Vector3();
    this.curveMissColor = new THREE.Color();
    this.curveHitColor = new THREE.Color();
    this.raycaster = new THREE.Raycaster();
    this.refreshObjects = this.refreshObjects.bind(this);

    this.defaultPlane = this.createDefaultPlane();

    this.teleportEntity = document.createElement('a-entity');
    this.teleportEntity.className = 'teleport-ray';
    this.teleportEntity.setAttribute('visible', false);
    this.el.sceneEl.appendChild(this.teleportEntity);

    this.el.addEventListener(this.data.button + this.data.startEvent, this.onButtonDown.bind(this));
    this.el.addEventListener(this.data.button + this.data.endEvent, this.onButtonUp.bind(this));
  },

  onButtonDown: function (evt) {
    this.active = true;
  },

  onButtonUp: function (evt) {
    if (!this.active) { return; }

    // Jump!

    // Hide the hit point and the curve
    this.active = false;
    this.hitEntity.setAttribute('visible', false);
    this.teleportEntity.setAttribute('visible', false);

    if (!this.hit) {
      // Button released but not hit point
      return;
    }

    // @todo Create this aux vectors outside
    var cameraEl = this.el.sceneEl.camera.el;
    var camPosition = new THREE.Vector3().copy(cameraEl.getAttribute('position'));
    // account for camera world position e.g. when not direct descendant of scene
    var camWorldPosition = new THREE.Vector3().copy(cameraEl.object3D.getWorldPosition());
    // account for user height that the camera is supposed to be enforcing
    // (TODO: which should be how high they are off the ground right now, really)
    // (this.prevHeightDiff was trying to represent that value, but didn't handle world position)
    var yoffset = cameraEl.components.camera.data.userHeight;
    var newCamPositionY = camPosition.y + yoffset - camWorldPosition.y + this.hitPoint.y;
    var newCamPosition = new THREE.Vector3(this.hitPoint.x + camPosition.x - camWorldPosition.x, newCamPositionY, this.hitPoint.z + camPosition.z - camWorldPosition.z);
    var playerEl = this.data.playerEntity;
    if (playerEl) {
      // move the player, not the camera and controllers all separately<commit_msg>per @ngokevin, HMD position in tracking space === camera Y position, so fix yoffset<commit_after>/* global AFRAME */
var parabolicCurve = require('./lib/ParabolicCurve');
var RayCurve = require('./lib/RayCurve');

if (typeof AFRAME === 'undefined') {
  throw new Error('Component attempted to register before AFRAME was available.');
}

var buttons = ['trackpad', 'trigger', 'grip', 'menu', 'thumbstick', 'A', 'B', 'X', 'Y', 'surface', 'point', 'pointing', 'pistol', 'thumb'];
var events = ['down', 'up', 'open', 'close', 'start', 'end', 'touchstart', 'touchend'];

/* global THREE AFRAME  */
AFRAME.registerComponent('teleport-controls', {
  schema: {
    type: {default: 'parabolic', oneOf: ['parabolic', 'line']},
    button: {default: 'pointing', oneOf: buttons},
    startEvent: {default: 'start', oneOf: events},
    endEvent: {default: 'end', oneOf: events},
    collisionEntity: { type: 'selector' },
    objects: {default: ''},
    hitEntity: {type: 'selector'},
    playerEntity: { type: 'selector' },
    defaultPlaneSize: {default: 5000},
    hitCylinderColor: {type: 'color', default: '#99ff99'},
    hitCylinderRadius: {default: 0.25, min: 0},
    hitCylinderHeight: {default: 0.3, min: 0},
    maxLength: {default: 10, min: 0, if: {type: ['line']}},
    curveNumberPoints: {default: 30, min: 2, if: {type: ['parabolic']}},
    curveLineWidth: {default: 0.025},
    curveHitColor: {type: 'color', default: '#99ff99'},
    curveMissColor: {type: 'color', default: '#ff0000'},
    curveShootingSpeed: {default: 5, min: 0, if: {type: ['parabolic']}},
    landingNormal: {type: 'vec3', default: '0 1 0'},
    landingMaxAngle: {default: '45', min: 0, max: 360}
  },

  init: function () {
    this.active = false;
    this.obj = this.el.object3D;
    this.hitPoint = new THREE.Vector3();
    this.hit = false;
    this.prevHeightDiff = 0;
    this.referenceNormal = new THREE.Vector3();
    this.curveMissColor = new THREE.Color();
    this.curveHitColor = new THREE.Color();
    this.raycaster = new THREE.Raycaster();
    this.refreshObjects = this.refreshObjects.bind(this);

    this.defaultPlane = this.createDefaultPlane();

    this.teleportEntity = document.createElement('a-entity');
    this.teleportEntity.className = 'teleport-ray';
    this.teleportEntity.setAttribute('visible', false);
    this.el.sceneEl.appendChild(this.teleportEntity);

    this.el.addEventListener(this.data.button + this.data.startEvent, this.onButtonDown.bind(this));
    this.el.addEventListener(this.data.button + this.data.endEvent, this.onButtonUp.bind(this));
  },

  onButtonDown: function (evt) {
    this.active = true;
  },

  onButtonUp: function (evt) {
    if (!this.active) { return; }

    // Jump!

    // Hide the hit point and the curve
    this.active = false;
    this.hitEntity.setAttribute('visible', false);
    this.teleportEntity.setAttribute('visible', false);

    if (!this.hit) {
      // Button released but not hit point
      return;
    }

    // @todo Create this aux vectors outside
    var cameraEl = this.el.sceneEl.camera.el;
    var camPosition = new THREE.Vector3().copy(cameraEl.getAttribute('position'));
    // account for camera world position e.g. when not direct descendant of scene
    var camWorldPosition = new THREE.Vector3().copy(cameraEl.object3D.getWorldPosition());
    // account for user height that the camera is supposed to be enforcing
    // (TODO: which should be how high they are off the ground right now, really)
    // (this.prevHeightDiff was trying to represent that value, but didn't handle world position)
    var yoffset = camPosition.y; // cameraEl.components.camera.data.userHeight;
    var newCamPositionY = camPosition.y + yoffset - camWorldPosition.y + this.hitPoint.y;
    var newCamPosition = new THREE.Vector3(this.hitPoint.x + camPosition.x - camWorldPosition.x, newCamPositionY, this.hitPoint.z + camPosition.z - camWorldPosition.z);
    var playerEl = this.data.playerEntity;
    if (playerEl) {
      // move the player, not the camera and controllers all separately
{'fraction_non_alphanumeric': 0.1522119470132467, 'fraction_numerical': 0.01324668832791802, 'mean_word_length': 3.8769043266301035, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1281003', 'n_tokens_mistral': 2597, 'n_tokens_neox': 2478, 'n_words': 676}