computer graphicscau.ac.kr/~kjpark/courses/2009_1_cg/lec11.pdf · 2009-05-11 ·...
TRANSCRIPT
ContentsContents
• Particle SystemParticle System
– 물, 불, 구름 etc.
http://www karlsims com/particle dreams htmlhttp://www.karlsims.com/particle-dreams.html
• Mass-Spring System
– 옷, 헤어 etc.
• Library• Library
Particle class 리뷰Particle class 리뷰• Particle 객체
class Particle { PVector loc;객체
• 위치, 속도, 가속도, 크기
PVector loc; PVector vel; PVector acc; float mass;크기
• Timer파티클의 수명
float mass; float r; float timer;
– 파티클의 수명
• Extravoid update(){
vel.add(acc);loc add(vel);
– Constructor
– Render 메서드
loc.add(vel); timer -= 1.0;
}
• Display as dots, streaks, sphere …
boolearn dead() {if (timer <= 0.0)
return true;return true;else return false;
Particle SystemParticle System
• 파티클이 여러 개 존재하는 시스템
⇒Resizable arrays!
⇒자바 API 인 ArrayList 사용!
int MAX = 10;Particle[] parray = new Particle[MAX];
int MAX = 10;ArrayList plist = new ArrayList();Particle[] parray = new Particle[MAX];
for(int i=0; i<MAX; i++)[i] P i l ()
ArrayList plist = new ArrayList();
for(int i=0; i<MAX; i++)li dd( P i l ())parray[i] = new Particle();
for(int i=0; i<parray.length; i++){
plist.add(new Particle());
for(int i=0; i<plist.size(); i++){vs.
p y gParticle p = parray[i];p.run();p render();
pParticle p = (Particle) plist.get(i);p.run();p render();p.render();
}p.render();
}
Particle system 클래스Particle system 클래스class ParticleSystem {
ArrayList particles; PVector origin;
ParticleSystem(int num, PVector v) { yparticles = new ArrayList() ; origin = v.get() for (int i = 0; i < num; i++) {for (int i 0; i num; i ) {
particles.add(new Particle(origin)) ; } }
void run() {for (int i = particles.size()-1; i >= 0; i--) {
Particle p (Particle) particles get(i) ;Particle p = (Particle) particles.get(i) ; p.run() ; if (p.dead()) { particles.remove(i) ; }
}}}
메인 프로그램f 파티클 시스템for 파티클 시스템
ParticleSystem ps;
void setup(){i (200 200)size(200, 200);
ps = new ParticleSystem(1, new Pvector(width/2 height/2, 0));smooth();smooth();
}
void draw() {background(255);
()ps.run();ps.addParticle();
}}
Particle SystemsParticle Systems
• Particle systemsParticle systems
plus…
• Emitter type : 평면, 포인트, …
• Render type : 구 삼각형 spriteRender type : 구, 삼각형, sprite
• Force type : 중력, 바람, 터뷸런스
:Snow falling sceneSnow falling scene
– Create mode: Plane
– Emit from object
Render type 은 cloud– Render type 은 cloud
– Field• 아래로 떨어지는 힘• 좌우로 부는 힘• 랜덤 작용 힘
Multiple particle systemMultiple particle system
• 예제예제
ExerciseExercise
CollisionCollision
• Particle – plane collision?Particle plane collision?
• Particle – particle collision?
Collision detectionCollision detection
• Normal and tangential componentsNormal and tangential components
Collision responseCollision response
Mass-spring systemMass spring system
• 파티클과 파티클을 연결파티클과 파티클을 연결– Mass: 파티클S ri : 연결 li k– Spring: 연결 link
• 옷, 헤어 등 simulation
– 동영상– 동영상
particlelink
SpringSpring
• Rest stateRest state
• Update state
외 힘– 외부 힘• F = - k*u
• k 는 스프링 성질, U 는 이동거리
– 가속도가속• a = F/M
– 속도속도• v = D*(v + a) where D 는 damping
위치– 위치• p = p + v 예제) 프로세싱 examples
Mass-springMass spring
• Mass-spring 시스템은p g 시 템은– 외부에서 작용하는 힘 F 에 의하여서– Mass 부분이 움직이는데 (a, v, p 업데이트) 부분이 움직이는데 ( , , p 업데이트)
– 그 움직임이 spring 움직임 방향으로,
– spring 의 최소 거리와 최대 거리 범위안으로 제한spring 의 최소 거리와 최대 거리 범위안으로 제한되어진다
• Cf) 파티클 시스템인 경우는 자유자재로 움직임
• 따라서 외부에서 작용하는 힘 F 가따라서, 외부에서 작용하는 힘 F 가– spring 움직임 방향으로는 어떻게 영향을 미치는
지로 변환 필요!지로 변환 필요!
Traer physicsTraer physics
• http://www.cs.princeton.edu/~traer/phhttp //www.cs.princeton.edu/ traer/physics/
• Particle Systemy
• Particle
S i• Spring
• AttractionsAttractions
Traer physicsTraer physics
• 컨스트럭터컨스트럭터– new ParticleSystem( float gravityY, float drag )t drag )
– new ParticleSystem( float gx, float gy, fl t fl t d )float gz, float drag )
• 중력– void setGravity( float y )
– void setGravity( float x float y floa– void setGravity( float x, float, y, float z )
끄는 힘• 끄는 힘– void setDrag( float drag )
Traer physicsTraer physics
• 타임타임– void tick(), void tick( float t )
파티클 생성• 파티클 생성– Particle makeParticle()Particle makeParticle( float mass, float x, float y, float z )
• 스프링 생성Spring makeSpring( Particle a Particle– Spring makeSpring( Particle a, Particle b, float strength, float damping, float restLength )restLength )
Traer physicsTraer physics
• 상호작용상호작용– Attraction makeAttraction( Particle a, Particle b float strength float minimumarticle b, float strength, float minimumDistance )
id l ()• void clear()
• 전체 반복전체 반복– int numberOfParticles()
– Particle getParticle( int index )Particle getParticle( int index )
– int numberOfSprings()Spring getSpring( int index )p g g p g( )
– int numberOfAttractions()Attraction getAttraction( int index)