问题描述
大约一年前,我的程序运行没有任何错误。我相信 Box2d 可能已经更新或进行了更改,因为这是一个新错误,不允许我的程序运行。
我收到“您缺少 beginContact() 方法。java.lang.NoSuchMethodException: ARTLAB_FINAL.beginContact(org.jBox2d.dynamics.contacts.Contact) 您缺少 endContact() 方法。 java.lang.NoSuchMethodException: ARTLAB_FINAL.endContact(org.jBox2d.dynamics.contacts.Contact) Arrayindexoutofboundsexception: 230400"错误"
它突出显示了这一行,但我不知道为什么:color prevColor = prev.pixels[loc];
这是我的代码:
// Basic example of controlling an object with our own motion (by attaching a MouseJoint)
// Also demonstrates how to kNow which object was hit
PImage img;
// Size of each cell in the grid,ratio of window size to video size
int imageScale = 3;
// Number of columns and rows in the system
int cols,rows;
import shiffman.Box2d.*;
import org.jBox2d.common.*;
import org.jBox2d.dynamics.joints.*;
import org.jBox2d.collision.shapes.*;
import org.jBox2d.collision.shapes.Shape;
import org.jBox2d.common.*;
import org.jBox2d.dynamics.*;
import org.jBox2d.dynamics.contacts.*;
import java.util.*;
//sound
import ddf.minim.*;
Minim minim;
AudioPlayer player;
// A reference to our Box2d world
Box2DProcessing Box2d;
// Just a single Box this time
Box Box;
Spring spring;
// An ArrayList of particles that will fall on the surface
ArrayList < Particle > particles;
//Arraylist of images
PImage[] imgs = new PImage[20];
int imgsIndex = 0;
AudioPlayer[] players = new AudioPlayer[20];
// Perlin noise values
float xoff = 0;
float yoff = 1000;
//MOTION DETECTOR
import processing.video.*;
Capture video;
PImage prev;
float threshold = 25;
float motionX = 0;
float motionY = 0;
float lerpX = 0;
float lerpY = 0;
// update - Framecounter
int frameCounter = 0;
float lerpX2,lerpY2;
void setup() {
// we pass this to Minim so that it can load files from the data directory
minim = new Minim(this);
size(533,800);
String[] cameras = Capture.list();
printArray(cameras);
video = new Capture(this,cameras[0]);
video.start();
prev = createImage(640,360,RGB);
noCursor();
for (int i = 0; i < 20; i++) {
imgs[i] = loadImage("images/pngx800/" + i + ".png");
//**PLAY AUdio
players[i] = minim.loadFile("AUdio2/" + i + ".mp3");
}
//img = loadImage("graphic(3).png");
//MOTION DETECTOR
// Initialize columns and rows
cols = width / imageScale;
rows = height / imageScale;
//size(400,300);
//smooth();
// Initialize Box2d physics and create the world
Box2d = new Box2DProcessing(this);
Box2d.createWorld();
// Turn on collision listening!
Box2d.listenForCollisions();
// Make the Box
Box = new Box(width / 2,height / 2);
// Create the empty list
particles = new ArrayList < Particle > ();
Box2d.setGravity(0,0);
//sound
// update - bind the spring to the Box
spring = new Spring();
spring.bind(width / 2,height / 2,Box);
}
void captureEvent(Capture video) {
prev.copy(video,video.width,video.height,prev.width,prev.height);
prev.updatePixels();
video.read();
}
void draw() {
background(0);
video.loadPixels();
prev.loadPixels();
threshold = 50;
int cnt = 0;
float avgX = 0;
float avgY = 0;
loadPixels();
// Begin loop to walk through every pixel
for (int x = 0; x < video.width; x++) {
for (int y = 0; y < video.height; y++) {
int loc = x + y * video.width;
// What is current color
color currentColor = video.pixels[loc];
float r1 = red(currentColor);
float g1 = green(currentColor);
float b1 = blue(currentColor);
color prevColor = prev.pixels[loc];
float r2 = red(prevColor);
float g2 = green(prevColor);
float b2 = blue(prevColor);
float d = distSq(r1,g1,b1,r2,g2,b2);
if (d > threshold * threshold) {
//stroke(255);
//strokeWeight(1);
//point(x,y);
avgX += width - x;
avgY += y;
cnt++;
// update - don't need to display pixels here or after the else
//pixels[loc] = color(255);
} else {
//pixels[loc] = color(0);
}
}
}
println("avg" + ":" + avgX + ":" + avgY);
updatePixels();
// We only consider the color found if its color distance is less than 10.
// This threshold of 10 is arbitrary and you can adjust this number depending on how accurate you require the tracking to be.
if (cnt > 800) {
motionX = avgX / cnt;
motionY = avgY / cnt;
// Draw a circle at the tracked pixel
}
lerpX = lerp(lerpX,motionX,0.1);
lerpY = lerp(lerpY,motionY,0.1);
lerpX2 = map(lerpX,640,533);
lerpY2 = map(lerpY,800);
Box.body.setLinearVeLocity(new Vec2(lerpX,lerpY));
playAudio();
if (particles.size() < 2) {
//int counter = 0;
for (int i = 0; i < cols; i += 2) {
// Begin loop for rows
for (int j = 0; j < rows; j += 2) {
// Where are you,pixel-wise?
int x = i * imageScale;
int y = j * imageScale;
color c = imgs[imgsIndex].get(x,y);
particles.add(new Particle(x,y,imageScale,c));
//counter++;
//println(counter + " :: "+ x+y*width + " :: "+ i+j*width);
}
}
}
// We must always step through time!
Box2d.step();
int counter = 0;
if (cnt > 200) {
spring.update(lerpX2,lerpY2);
//} else {
// spring.update(width/2,height + 400);
}
//// Look at all particles
for (int i = particles.size() - 1; i >= 0; i--) {
Particle p = particles.get(i);
p.display();
// Particles that leave the screen,we delete them
// (note they have to be deleted from both the Box2d world and our list
if (!p.origin()) {
counter++;
}
}
if (counter > particles.size() * 0.99) {
//frameCounter++;
//if (frameCounter > 200) {
//println("here");
for (Particle p : particles) { //int i = particles.size() - 1; i>= 0) {
//p.fd.density = 1;
// println("in the loop");
p.attract();
}
// frameCounter = 0;
//}
}
//Box.display();
println("FR" + ":" + frameRate + ": " + frameCount);
//println(counter);
//println(particles.size() - counter);
if (!players[imgsIndex].isPlaying()) {
updateColors();
}
println(frameRate);
}
//**PLAY AUdio
void playAudio() {
//if (players[imgsIndex].position() == players[imgsIndex].length()) {
// //players[imgsIndex].rewind();
// players[imgsIndex].play();
// } else {
// players[imgsIndex].play();
//}
}
float distSq(float x1,float y1,float z1,float x2,float y2,float z2) {
float d = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) +(z2-z1)*(z2-z1);
return d;
}
void updateColors() {
//rewind tracks so they're ready for the next time they're played
players[imgsIndex].rewind();
//Pause the rewound track so it doesn't set off the isPlaying function
players[imgsIndex].pause();
imgsIndex++;
if (imgsIndex > 19) {
imgsIndex = 0;
}
// Play the next track
players[imgsIndex].play();
//for(Particle p : particles){
// p.killBody();
// particles.remove(p);
//}
for (int i = particles.size()-1; i >= 0; i--) {
Particle p = particles.get(i);
p.killBody();
particles.remove(i);
}
println(particles.size());
//int pixelCounter = 0;
//int counter = 0;
for (int i = 0; i < cols; i += 2) {
// Begin loop for rows
for (int j = 0; j < rows; j += 2) {
// Where are you,pixel-wise?
int x = i * imageScale;
int y = j * imageScale;
color c = imgs[imgsIndex].get(x,y);
particles.add(new Particle(x,c));
//counter++;
}
}
//}
players[imgsIndex].play();
}
enter code here
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)