입자 시스템 애플릿을 작성했습니다. 현재 저는 각 파티클을 별도로 만들고 있습니다. 내가 20,000 입자 (나는 괜찮은 노트북을 가지고 있지만)와 함께 ~ 40FPS를 얻을 수있는, 성능이 괜찮습니다입니다입자를 효율적으로 그리기
BufferedImage backbuffer;
Graphics2D g2d;
public void init(){
backbuffer = new BufferedImage(WIDTH,HEIGHT,BufferedImage.TYPE_INT_RGB);
g2d = backbuffer.createGraphics();
setSize(WIDTH, HEIGHT);
//creates the particles
for (int i = 0; i < AMOUNTPARTICLES; i++) {
prtl[i] = new particleO();
prtl[i].setX(rand.nextInt(STARTX));
prtl[i].setY(rand.nextInt(STARTY));
prtl[i].setVel(rand.nextInt(MAXSPEED)+1);
prtl[i].setFAngle(Math.toRadians(rand.nextInt(ANGLESPREAD)));
}
//other code
}
public void update(Graphics g) {
g2d.setTransform(identity);
//set background
g2d.setPaint(BGCOLOUR);
g2d.fillRect(0,0,getSize().width,getSize().height);
drawp();
paint(g);
}
public void drawp() {
for (int n = 0; n < AMOUNTPARTICLES; n++) {
if (prtl[n].getAlive()==true){
g2d.setTransform(identity);
g2d.translate(prtl[n].getX(), prtl[n].getY());
g2d.setColor(prtl[n].getColor());
g2d.fill(prtl[n].getShape());
}
}
}
(여기에 코드입니다). 내가 (아래 참조) 충돌 감지 기능을 추가 한 후, 나는이 화면에 입자 그리기 더 나은 방법을 꽤 검색 한
public void particleUpdate(){
for (int i = 0; i < AMOUNTPARTICLES; i++) {
//other update code (posx, posy, angle etc etc)
for (int j = 0; j < AMOUNTPARTICLES; j++) {
if (i!=j && prtl[j].getAlive()==true){
if(hasCollided(i, j)){
prtl[i].setcolor(Color.BLACK);
prtl[j].setcolor(Color.BLACK);
}
}
}
public boolean hasCollided(int prt1, int prt2){
double dx = prtl[prt1].getX() - prtl[prt2].getX();
double dy = prtl[prt1].getY() - prtl[prt2].getY();
int edges = prtl[prt1].getRadius() + prtl[prt2].getRadius();
double distance = Math.sqrt((dx*dx) + (dy*dy));
return (distance <= edges);
}
그 수는 2000 미만으로 하락하지만 예 중 저를 혼동 적용 할 수 없었습니다.
계산이 너무 많습니다 (너무 많음). 그러나 나는 그것을하는 다른 방법을 생각할 수 없었다, 제안은 환영 받는다.
http://stackoverflow.com/questions/13046033/an-efficient-way-to-simulate-many-particle-collisions –
어느 것이 가장 도움이되었는지 결정한 후에는 대답을 받아 들여야합니다. – PearsonArtPhoto