Camera() doesn't expect parameters

and to the question about

translate

yes, it resets anything
what you might have done to pos vector
so i see no movement

see also a modified start position!

/*
import processing.serial.*;
 
 String val;     // Data received from the serial port
 Serial serialConnectionObject;
 int serialChannelIndexInt;
 float lat;
 float lng;
 float latcoord = 0;
 float longcoord = 0;
 boolean newData = false;
 
 */

float xCoord=1;
float yCoord=1;
float oldxCoord;
float oldyCoord;

int rectSizeX = 40 ;
int rectSizeY = 40;
int posxstart = 20; // kll
int posystart = 20; // kll

Camera worldCamera;

void setup()
{
  background(200, 200, 0);
  size(400, 400, P3D);
  /*
  InitSerialConnectionVoid(0);
   String portName = Serial.list()[serialChannelIndexInt]; //change the 0 to a 1 or 2 etc. to match your port
   println(portName);
   serialConnectionObject.bufferUntil('\n');
   */
  worldCamera = new Camera();
  stroke(200, 0, 0); // kll
  noFill();        // kll
}

void draw() { 
  //  translate(-worldCamera.pos.x, -worldCamera.pos.y); // play here, when enabled it not moves
  worldCamera.draw();
  /*
  if (newData) {
   fill(#FFFFFF, 10);
   noStroke();
   rectMode(CENTER);
   scale(2);
   rect(xCoord, yCoord, rectSizeX, rectSizeY);
   }
   */
}

class Camera {
  PVector pos;           //Camera's position   //The Camera should sit in the top left of the window
  Camera() {
    pos = new PVector(posxstart, posystart);    // kll global preset start position
  }

  void draw() {
    float px = xCoord - oldxCoord;
    float py = yCoord - oldyCoord;
    //I used the mouse to move the camera
    //The mouse's position is always relative to the screen and not the camera's position
    //E.g. if the mouse is at 1000,1000 then the mouse's position does not add 1000,1000 to keep up with the camera
    //if (mouseX < 100) pos.x-=5;
    //else if (mouseX > width - 100) pos.x+=5;
    // if (mouseY < 100) pos.y-=5;
    //else if (mouseY > height - 100) pos.y+=5;
    //I noticed on the web the program struggles to find the mouse so I made it key pressed
    if (keyPressed) {
      if (key == 'w') pos.y -= py;
      if (key == 's') pos.y += py;
      if (key == 'a') pos.x -= px;
      if (key == 'd') pos.x += px;
    }
    rect(pos.x, pos.y, rectSizeX, rectSizeY);     // kll sorry, needed to see something
  }
}
/*
void serialEvent(Serial p) {
 oldxCoord = xCoord;
 oldyCoord = yCoord;
 try {
 println("test");
 val = p.readString();
 println(val);
 JSONObject json = parseJSONObject(val);
 if (json == null) {
 newData = false;
 } else {
 println(json.toString());
 lat = json.getFloat("lat");
 lng = json.getFloat("lng");
 println(lat);
 LatLngtoXY(lat, lng);
 println(xCoord, yCoord);
 newData=true;
 }
 //latcoord = map(lat, lat-0.00045000045, lat+0.00045000045, 0, width);
 //longcoord = map(lng, lng-0.00045000063, lng+0.00045000063, 0, height);
 }
 catch(RuntimeException e) {
 e.printStackTrace();
 }
 }
 
 void LatLngtoXY(float lat, float lon) {
 float mapWidth    = width;
 float mapHeight   = height;
 
 // get x value
 xCoord = (lon+180)*(mapWidth/360);
 
 // convert from degrees to radians
 float latRad = lat*PI/180;
 // get y value
 float mercN = log(tan((PI/4)+(latRad/2)));
 yCoord     = (mapHeight/2)-(mapWidth*mercN/(2*PI));
 }
 
 void InitSerialConnectionVoid(int _serialChannelIndexInt) {
 
 serialChannelIndexInt = _serialChannelIndexInt;
 
 if (serialChannelIndexInt == Serial.list().length) { 
 return;
 }
 try {
 
 serialConnectionObject = new Serial(this, Serial.list()[serialChannelIndexInt], 115200);
 serialConnectionObject.bufferUntil('\n');
 }
 catch (RuntimeException e) {
 
 serialConnectionObject = null;
 println(e);
 println("SERIAL CONNECTION FAILED");
 InitSerialConnectionVoid(serialChannelIndexInt + 1);
 }
 }
 */

1 Like