<commit_before>var coord3d;
var cam;
var cameraController;

function setup(){
  createCanvas(windowWidth, windowHeight-50, WEBGL);

  coord3d = new Coord3D();
  cam = createCamera();
  cameraController = new CameraController(cam);
}

function draw(){
  background(45);

  coord3d.drawZAxis();
  coord3d.drawXAxis();
  coord3d.drawYAxis();
}

function keyPressed(){
  cameraController.handleKeyPressed();
  console.log("keyPressed:  " + key);
}


function keyTyped() {
  console.log("keyTyped:  " + key);
}

class CameraController {
  constructor(cam) {
    this.cam = cam;
  }

  handleKeyPressed(){
    let downcaseKey = key.toLowerCase();
    if (downcaseKey === 'd' || keyCode === RIGHT_ARROW) {
      this.cam.move(10, 0, 10);
    } else if (downcaseKey === 'a' || keyCode === LEFT_ARROW) {
      this.cam.move(-10, 0, 0);
    } else if (downcaseKey === 'w' || keyCode === UP_ARROW) {
      this.cam.move(0, 0, -10);
    } else if (downcaseKey === 's' || keyCode === DOWN_ARROW) {
      this.cam.move(0, 0, 10);
    } else if (downcaseKey === ' '){
      if (keyIsDown(SHIFT)){
        this.cam.move(0, -10, 0);
      }else{
        this.cam.move(0, 10, 0);
      }
    }
  }
}

class Coord3D {
  constructor(){
    this.red = color(200, 50, 50);
    this.green = color(50, 200, 50);
    this.blue = color(50, 50, 200);

    this.origin = createVector(0, 0, 0);
    this.axisLength = 100;
  }

  get x_axis_end() { return createVector(this.axisLength, 0, 0); }
  get y_axis_end() { return createVector(0, this.axisLength, 0); }
  get z_axis_end() { return createVector(0, 0, this.axisLength); }

  drawXAxis(){
    stroke(this.red);
    this.lineFromTo(this.origin, this.x_axis_end);<commit_msg>p5js/3d-flying-camera - Refactor camera movement to functions<commit_after>var coord3d;
var cam;
var cameraController;

function setup(){
  createCanvas(windowWidth, windowHeight-50, WEBGL);

  coord3d = new Coord3D();
  cam = createCamera();
  cameraController = new CameraController(cam);
}

function draw(){
  background(45);

  coord3d.drawZAxis();
  coord3d.drawXAxis();
  coord3d.drawYAxis();
}

function keyPressed(){
  cameraController.handleKeyPressed();
  console.log("keyPressed:  " + key);
}


function keyTyped() {
  console.log("keyTyped:  " + key);
}

class CameraController {
  constructor(cam) {
    this.cam = cam;
  }

  moveForward(){
    this.cam.move(0, 0, -10);
  }

  moveBack(){
    this.cam.move(0, 0, 10);
  }

  moveLeft(){
    this.cam.move(-10, 0, 0);
  }

  moveRight(){
    this.cam.move(0, 0, 10);
  }

  moveUp(){
    this.cam.move(0, 10, 0);
  }

  moveDown(){
    this.cam.move(0, -10, 0);
  }

  handleKeyPressed(){
    let downcaseKey = key.toLowerCase();

    if (downcaseKey === 'd' || keyCode === RIGHT_ARROW) {
      this.moveRight();
    } else if (downcaseKey === 'a' || keyCode === LEFT_ARROW) {
      this.moveLeft();
    } else if (downcaseKey === 'w' || keyCode === UP_ARROW) {
      this.moveForward();
    } else if (downcaseKey === 's' || keyCode === DOWN_ARROW) {
      this.moveBack();
    } else if (downcaseKey === ' '){
      if (keyIsDown(SHIFT)){
        this.moveUp();
      }else{
        this.moveDown();
      }
    }
  }
}

class Coord3D {
  constructor(){
    this.red = color(200, 50, 50);
    this.green = color(50, 200, 50);
    this.blue = color(50, 50, 200);

    this.origin = createVector(0, 0, 0);
    this.axisLength = 100;
  }

  get x_axis_end() { return createVector(this.axisLength, 0, 0); }
  get y_axis_end() { return createVector(0, this.axisLength, 0); }
  get z_axis_end() { return createVector(0, 0, this.axisLength); }

  drawXAxis(){
    stroke(this.red);
    this.lineFromTo(this.origin, this.x_axis_end);
{'fraction_non_alphanumeric': 0.17181571815718158, 'fraction_numerical': 0.03766937669376694, 'mean_word_length': 3.147191011235955, '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': '1202236', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1351, 'n_words': 282}