Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在加工过程中处理缩放、平移和相机_Javascript_Processing - Fatal编程技术网

Javascript 在加工过程中处理缩放、平移和相机

Javascript 在加工过程中处理缩放、平移和相机,javascript,processing,Javascript,Processing,我希望对我的代码做以下四件事: 用鼠标平移 使用鼠标滚轮进行缩放 通过双击鼠标按钮捕捉视图 混合使用正交和透视摄影机投影 当我尝试添加void mouseDragged(){时,会出现一个标记错误。 此外,当我尝试让鼠标滚轮缩放时,也会出现一个标记错误。我用于鼠标滚轮的代码如下: 作废鼠标滚轮(鼠标事件){ float e=event.getAmount() 下面是我目前编写的代码。我感谢您的帮助,因为我已经花了几天的时间试图解决这个问题 Table table; float wheelCoun

我希望对我的代码做以下四件事:

  • 用鼠标平移
  • 使用鼠标滚轮进行缩放
  • 通过双击鼠标按钮捕捉视图
  • 混合使用正交和透视摄影机投影
  • 当我尝试添加void mouseDragged(){时,会出现一个标记错误。 此外,当我尝试让鼠标滚轮缩放时,也会出现一个标记错误。我用于鼠标滚轮的代码如下: 作废鼠标滚轮(鼠标事件){ float e=event.getAmount()

    下面是我目前编写的代码。我感谢您的帮助,因为我已经花了几天的时间试图解决这个问题

    Table table;
    float wheelCount = 0;
    
    //Pan & Zoom Varibles
    float scale = 0.1;
    float xPan;
    float yPan;
    boolean zoomIn = false;
    boolean zoomOut = false;
    boolean panUp = false;
    boolean panDown = false ;
    boolean panLeft = false;
    boolean panRight = false;
    float panSpeed = 5;
    float zoomSpeed = 0.01;
    
    float rotx = PI/4;
    float roty = PI/4;
    
    float x,y,z;
    float w, h;
    
    boolean census1991 = false;
    boolean census2001 = false;
    boolean census2011 = false;
    
    
    void setup() {
      size(800, 600, P3D);
      
      table = loadTable ("Data.csv", "header");
    
      img = loadImage("uk-admin.jpg");
      
      textureMode(NORMAL);
      
       for (TableRow row : table.rows()) {
        int No = row.getInt("No");
        String City = row.getString("City");
        String Census1991 = row.getString("Census1991");
        String Census2001 = row.getString("Census2001");
        String Census2011 = row.getString("Census2011");
        
        println(No);
        println(City);
        println("Census 1991:", Census1991);
        println("Census 2001:", Census2001);
        println("Census 2011:", Census2011);
        println("Use the arrow keys to pan around the map");
        println("Press 'Z' to Zoom In and 'X' to Zoom Out");
        println("Left Click to Zoom In and Right Click to zoom");
        println("Use the Mouse Wheel to zoom in and out");
        println("Press '1' to view the Census from 1991");
        println("Press '2' to view the Census from 2001");
        println("Press '3' to view the Census from 2011");
        println("Press 'R' to remove Census data from the map");
        println("Scroll up in the console to view the exact population figures for each city in each Census");
       }
     }
    
    void draw() {
      background(0);
      imageMode (CENTER);
      image(map, centerX, centerY, imgW, imgH);
      translate(width*0.5, height*0.5, 10);//translate the transformation point to the centre of the screen
      translate(-xPan, -yPan);
      rotateX(-PI/4);//apply a rotation about the x axis to tilt the plane we will be drawing to
      scale(scale);//you can apply a scaling factor here to suit the size of your img
    
     
      translate(-img.width/2, 0, -img.height/2);
    
      beginShape();
      texture(img);
      vertex(0, 0, 0, 0, 0);//texture uv coordinates are the last two numbers
      vertex(img.width, 0, 0, 1, 0);
      vertex(img.width, 0, img.height, 1, 1);
      vertex(0, 0, img.height, 0, 1);
      endShape();
      
      if (zoomIn) {
        scale +=zoomSpeed;
      }
      if (zoomOut) {
        scale -=zoomSpeed;
      }
      if (panUp) {
        yPan -=panSpeed;
      }
      if (panDown) {
        yPan +=panSpeed;
      }
      if (panLeft) {
        xPan -=panSpeed;
      }
      if (panRight) {
        xPan +=panSpeed;
      }
      
      if (census1991) {
        for (TableRow row : table.rows()) { 
        float lat = row.getFloat("Latitude");
        float lon = row.getFloat("Longitude");
        float Census1991 = row.getFloat("Census1991");
        float h = Census1991;
        float maxh = pow(10, 7);
        h = map(h, 0, maxh, 10, 100);
        x = lat;
        y = lon;
        z = 0;
        
        pushMatrix();
        translate(y, -z, x);
        fill(255,60,50);
        box(10, h, 10); 
        popMatrix();
    
          }
        } else if (census2001) {
        for (TableRow row : table.rows()) {
        float lat = row.getFloat("Latitude");
        float lon = row.getFloat("Longitude");
        float Census2001 = row.getFloat("Census2001");
        float h = Census2001;
        float maxh = pow(10, 7);
        h = map(h, 0, maxh, 10, 100);
        x = lat;
        y = lon;
        z = 0;
        
        pushMatrix();
        translate(y, -z, x);
        fill(100,60,50);
        box(10, h, 10);
        popMatrix();
          }
        } else if (census2011) {
        for (TableRow row : table.rows()) {
        float lat = row.getFloat("Latitude");
        float lon = row.getFloat("Longitude");
        float Census2011 = row.getFloat("Census2011");
        float h = Census2011;
        float maxh = pow(10, 7);
        h = map(h, 0, maxh, 10, 100);
        x = lat;
        y = lon;
        z = 0;
        
        pushMatrix();
        translate(y, -z, x);
        fill(205,78,80);
        box(10, h, 10);
        popMatrix();
          }
        }
      }
      // Pan & Zoom Controls
    
    void keyPressed() {
     if (key == 'Z') {
       zoomIn= true;
       zoomOut= false;
       }
     if (key =='O') {
       zoomIn = false;
       zoomOut = true;
     }
     if (keyCode ==UP) {
       panUp = true;
       panDown= false;
     }
     if (keyCode == DOWN) {
       panDown = true;
       panUp= false;
     }
     if (keyCode == LEFT) {
       panLeft = true;
       panRight= false;
       }
     if (keyCode == RIGHT) {
       panRight = true;
       panLeft= false;
         }
    
    if (key == '1') {
       census1991 = true;
       census2001 = false;
       census2011 = false;
    
     }
     
     if (key == '2') {
       census1991 = false;
       census2001 = true;
       census2011 = false;
    
     }
     
     if (key == '3') {
       census1991 = false;
       census2001 = false;
       census2011 = true;
    
     }
     
     if (key == 'r') {
        census1991 = false;
        census2001 = false;
        census2011 = false; 
      }
    }
    //Stops Pan & Zoom when keys are released.
     void keyReleased() {
      if(key == 'Z') {
        zoomIn = false;
      }
        if (key == 'O'){
        zoomOut = false;
      }
         if (keyCode == UP) {
        panUp = false;
      }
        if (keyCode == DOWN) {
        panDown = false;
      }
        if (keyCode == LEFT) {
        panLeft = false;
      }
       if (keyCode == RIGHT) {
        panRight = false;
       }```
    

    请添加更多详细信息,特别是关于您正在尝试做什么,到目前为止您已经尝试了什么,以及相关的代码(如果有)。目前为止,这个问题对任何阅读它的人来说都非常模糊。@Sumit感谢您的建议我现在更新了我的问题,您可以看一下。这应该会让一切变得更容易。