准备工作
官方已经内置了四种实体原型:point、lineSegements、cloth、tire
实例中又出现了四种实体原型:tree、spider、spiderweb、(crawl 是 spider 的一个方法,算不上实体原型)
我们先来看一下最简单的 point 的使用方法:vjs.point(pos) #3
sim.point({
x: width/2,
y: height/2
})
也可以是
sim.point(new vec2(width/2, height/2));
分析源码
objects.js #3 部分源码
VerletJS.prototype.point = function(pos) {
var composite = new this.Composite();
composite.particles.push(new Particle(pos));
this.composites.push(composite);
return composite;
}