package framework.physics; import framework.model3D.OBB; import javax.vecmath.Vector3d; public class Inertia3D { double ixx; double iyy; double izz; static final Inertia3D ZERO = new Inertia3D( 0.0, 0.0, 0.0); public Inertia3D(double x,double y,double z){ this.ixx = x; this.iyy = y; this.izz = z; } public Inertia3D(Vector3d v) { this.ixx = v.x; this.iyy = v.y; this.izz = v.z; } public Inertia3D(Solid3D obj) { BoundingBoxVisitor visitor = new BoundingBoxVisitor(); obj.accept(visitor); if (visitor.getObbList().size() == 1) { OBB obb = visitor.getObbList().get(0); Vector3d vx = new Vector3d(); vx.sub(obb.getVertex(4), obb.getVertex(0)); Vector3d vy = new Vector3d(); vy.sub(obb.getVertex(1), obb.getVertex(0)); Vector3d vz = new Vector3d(); vz.sub(obb.getVertex(2), obb.getVertex(0)); // System.out.println("vx:" + vx + ",vy:" + vy + ",vz:" + vz); this.ixx = obj.mass * (1.0/12.0 * (Math.pow(vy.length(), 2.0) + Math.pow(vz.length(), 2.0))); this.iyy = obj.mass * (1.0/12.0 * (Math.pow(vx.length(), 2.0) + Math.pow(vz.length(), 2.0))); this.izz = obj.mass * (1.0/12.0 * (Math.pow(vx.length(), 2.0) + Math.pow(vy.length(), 2.0))); } else { this.ixx = obj.mass; this.iyy = obj.mass; this.izz = obj.mass; } } public Vector3d getVector3d() { return new Vector3d(ixx, iyy, izz); } }