class Vec3D{ float x; float y; float z; float size; Vec3D(){ x=y=z=size=0f; } Vec3D(float x, float y, float z){ this.x=x; this.y=y; this.z=z; size=sqrt(x*x+y*y+z*z); } Vec3D(Vec3D v){ this.x=v.x; this.y=v.y; this.z=v.z; this.size=v.size; } Vec3D add(Vec3D v){ Vec3D result = new Vec3D(x+v.x,y+v.y,z+v.z); return result; } Vec3D sub(Vec3D v){ Vec3D result = new Vec3D(x-v.x,y-v.y,z-v.z); return result; } Vec3D mul(float f){ Vec3D result = new Vec3D(x*f,y*f,z*f); return result; } Vec3D scale(float sx,float sy,float sz){ Vec3D result = new Vec3D(x*sx,y*sy,z*sz); return result; } Vec3D div(float f){ Vec3D result = new Vec3D(x/f,y/f,z/f); return result; } Vec3D normalize(){ return div(size); } } Vec3D randomRotate(Vec3D v){ float rt = random(0,TWO_PI); float co = cos(rt); float si = sin(rt); return new Vec3D(v.x*co-v.y-si,v.x*si+v.y*co,v.z); }