处理变焦、平移和相机处理

问题描述

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

  1. 使用鼠标平移
  2. 使用鼠标滚轮缩放
  3. 通过双击鼠标按钮快速查看
  4. 混合使用正交和透视相机投影

当我尝试添加 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,-img.height/2);

  beginShape();
  texture(img);
  vertex(0,0);//texture uv coordinates are the last two numbers
  vertex(img.width,1,0);
  vertex(img.width,img.height,1);
  vertex(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,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,x);
    fill(100,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,x);
    fill(205,78,80);
    Box(10,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;
   }```

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)