PVector.rotate() doesn't seem to be implemented in processing.js

edited April 2016 in JavaScript Mode

Does anyone know how I would go about implementing this? Processing.js seems to hang whenever I use a PVector.rotate() function.

Tagged:

Answers

  • Actually, I see that it is implemented in the github 1.4.8 version. How do I get Processing's Javascript mode to use that version rather than the 1.4.1 it seems to currently be using?

  • edited July 2014 Answer ✓

    <Sketchbook Location>/modes/JavaScriptMode/template/processing.js

    Some warnings though:

    • I had some minor problems w/ it in my Processing 2.0.2.
    • Almost all Processing host sites still use v1.4.1.
    • I've failed to spot method rotate() even on v1.4.8!

    At least, we can peek at Java Mode's own rotate() implementation source code:
    https://github.com/processing/processing/blob/master/core/src/processing/core/PVector.java#L892

    public void rotate(float theta) {
      float temp = x;
      // Might need to check for rounding errors like with angleBetween function?
      x = x*PApplet.cos(theta) - y*PApplet.sin(theta);
      y = temp*PApplet.sin(theta) + y*PApplet.cos(theta);
    }
    

    I've got an online example which uses either PVector's rotate() or a "manual" approach to it:
    http://studio.processingtogether.com/sp/pad/export/ro.91nVQMnL$v06L/latest

    enemy.rotate(-HALF_PI/E_SPD);
    enemy.set(cos(theta -= HALF_PI/E_SPD)*rad, sin(theta)*rad, 0);
    
  • Thanks. I will probable go the manual way as you suggest.

  • edited April 2016

    PVector rotate(float theta)

    public PVector rotate(float theta) { float temp = x; // Might need to check for rounding errors like with angleBetween function? x = x*PApplet.cos(theta) - y*PApplet.sin(theta); y = temp*PApplet.sin(theta) + y*PApplet.cos(theta); return this; }

Sign In or Register to comment.