diff --git a/src/main/java/org/ntlab/radishforandroidstudio/framework/physics/PhysicsUtility.java b/src/main/java/org/ntlab/radishforandroidstudio/framework/physics/PhysicsUtility.java index 0043f2d..e98c3df 100644 --- a/src/main/java/org/ntlab/radishforandroidstudio/framework/physics/PhysicsUtility.java +++ b/src/main/java/org/ntlab/radishforandroidstudio/framework/physics/PhysicsUtility.java @@ -11,24 +11,21 @@ import org.ntlab.radishforandroidstudio.java3d.Vector3d; /** - * 迚ゥ逅�貍皮ョ励�ョ繧ウ繧「 - * - * @author 譁ー逕ー逶エ荵� + * 物理演算のコア + * @author 新田直也 * */ public class PhysicsUtility { - public static final double GRAVITY = 9.8; // 驥榊鴨縺ョ蜉�騾溷コヲ + public static final double GRAVITY = 9.8; // 重力の加速度 public static final Vector3d horizon = new Vector3d(1.0, 0.0, 0.0); public static final Vector3d vertical = new Vector3d(0.0, 1.0, 0.0); public static Vector3d gravityDirection = new Vector3d(0.0, 1.0, 0.0); /** - * 迚ゥ菴薙↓蜉�繧上k驥榊鴨繧呈アゅa繧� - * - * @param body - * 蟇セ雎。迚ゥ菴� - * @return body縺ォ蜉�繧上k驥榊鴨 + * 物体に加わる重力を求める + * @param body 対象物体 + * @return bodyに加わる重力 */ public static Force3D getGravity(Solid3D body) { return new Force3D(gravityDirection.x * -body.mass * GRAVITY, gravityDirection.y * -body.mass * GRAVITY, @@ -37,13 +34,13 @@ /** * @param v - * �シ壼腰菴阪�吶け繝医Ν縲√≠繧九>縺ッ繧シ繝ュ繝吶け繝医Ν繧貞シ墓焚縺ァ貂。縺吶%縺ィ + * :単位ベクトル、あるいはゼロベクトルを引数で渡すこと */ public static void setGravityDirection(Vector3d v) { gravityDirection = new Vector3d(v.x, v.y, v.z); } - // 繝「繝シ繝。繝ウ繝医�ョ險育ョ� + // モーメントの計算 static Vector3d calcMoment(Force3D f, Position3D gravityCenter, Position3D applicationPoint) { Vector3d v1 = applicationPoint.getVector3d(); Vector3d v2 = gravityCenter.getVector3d(); @@ -57,15 +54,11 @@ } /** - * 迚ゥ菴薙�ョ蜿咲匱菫よ焚縺九i陦晉ェ∵凾縺ォ蜉�繧上k蜉帙r豎ゅa繧� - * - * @param interval - * 陦晉ェ√@縺ヲ縺�繧区凾髢� - * @param nor - * 迚ゥ菴薙′縺カ縺、縺九▲縺滄擇縺ョ螳昜サ吶�吶け繝医Ν - * @param solid - * 迚ゥ菴� - * @return 陦晉ェ∵凾縺ォ蜉�繧上k蜉� + * 物体の反発係数から衝突時に加わる力を求める + * @param interval 衝突している時間 + * @param nor 物体がぶつかった面の宝仙ベクトル + * @param solid 物体 + * @return 衝突時に加わる力 */ public static Force3D calcForce(long interval, Vector3d nor, Solid3D solid) { double f1 = 0.0; @@ -77,13 +70,10 @@ } /** - * 迚ゥ菴薙→蝨ー髱「縺ィ縺ョ陦晉ェ∝愛螳� - * - * @param obj - * 迚ゥ菴� - * @param ground - * 蝨ー髱「 - * @return 陦晉ェ∵ュ蝣ア�シ�null縺ョ縺ィ縺崎。晉ェ√↑縺暦シ� + * 物体と地面との衝突判定 + * @param obj 物体 + * @param ground 地面 + * @return 衝突情報(nullのとき衝突なし) */ public static CollisionResult doesIntersect(Solid3D obj, Ground ground) { if (ground == null) @@ -91,7 +81,7 @@ CollisionResult cr = null; BoundingSurface boundingSurface = ground.getBoundingSurface(); - // BoundingSphere繧剃スソ縺」縺ヲ螟ァ髮第滑縺ォ陦晉ェ∝愛螳壹r陦後≧ + // BoundingSphereを使って大雑把に衝突判定を行う ArrayList boundingSurfaceList = null; if (obj.bs != null) { BoundingSphere bs = (BoundingSphere) (obj.bs.clone()); @@ -104,28 +94,27 @@ bs.transform(t3d); obj.pos.getTransform(t3d); bs.transform(t3d); - // 邊励>陦晉ェ∝愛螳壹r陦後≧�シ域怙荳贋ス阪�ョBoundingSurface縺ィBoundingSphere縺ョ髢薙〒�シ� + // 粗い衝突判定を行う(最上位のBoundingSurfaceとBoundingSphereの間で) boundingSurfaceList = boundingSurface.intersect(bs); bs = null; t3d = null; } if (obj.bs == null) { - // BoundingSphere 縺後∪縺�菴懊i繧後※縺�縺ェ縺ェ縺九▲縺溷�エ蜷医�� - // 隧ウ邏ー縺ェ陦晉ェ∝愛螳壹�ョ縺溘a縺ォ縲∵怙荳贋ス阪�ョ蜈ィ BoundingSurface 繧貞叙蠕励☆繧� + // BoundingSphere がまだ作られていななかった場合、 + // 詳細な衝突判定のために、最上位の全 BoundingSurface を取得する if (boundingSurfaceList == null) boundingSurfaceList = new ArrayList(); boundingSurfaceList.add(boundingSurface); } if (boundingSurfaceList.size() > 0) { - // 邊励>陦晉ェ∝愛螳壹〒陦晉ェ√@縺ヲ縺�縺溷�エ蜷医�^BB縺ョ髮�蜷医r逕ィ縺�縺ヲ繧医j隧ウ縺励>陦晉ェ∝愛螳壹r陦後≧ - // �シ�BoundingSphere 縺後∪縺�菴懊i繧後※縺�縺ェ縺�蝣エ蜷医�^BB 縺ョ菴懈�舌→蜷梧凾縺ォ BoundingSphere - // 繧剃ス懈�舌&繧後k�シ� + // 粗い衝突判定で衝突していた場合、OBBの集合を用いてより詳しい衝突判定を行う + // (BoundingSphere がまだ作られていない場合、OBB の作成と同時に BoundingSphere を作成される) BoundingBoxVisitor obbVisitor = new BoundingBoxVisitor(); obj.accept(obbVisitor); for (int i = 0; i < obbVisitor.getObbList().size(); i++) { - // OBB縺ィ陦晉ェ∝愛螳壹r縺吶k蝣エ蜷医�ッ縲∝慍髱「繧貞、夊ァ貞ス「縺ョ縺セ縺セ謇ア縺� + // OBBと衝突判定をする場合は、地面を多角形のまま扱う for (int j = 0; j < boundingSurfaceList.size(); j++) { cr = boundingSurfaceList.get(j).intersect(obbVisitor.getObbList().get(i)); if (cr != null) { @@ -149,10 +138,10 @@ public static CollisionResult checkCollision(Object3D obj1, String part1, Object3D obj2, String part2) { CollisionResult cr = null; - // BoundingSphere繧剃スソ縺」縺ヲ螟ァ髮第滑縺ォ陦晉ェ∝愛螳壹r陦後≧ + // BoundingSphereを使って大雑把に衝突判定を行う boolean f = false; if (obj1.bs != null && obj2.bs != null) { - // sol1 縺ョ BoundingSphere縲�繧定ィ育ョ� + // sol1 の BoundingSphere を計算 BoundingSphere bs1 = (BoundingSphere) (obj1.bs.clone()); Transform3D t3d = new Transform3D(); obj1.center.getTransform(t3d); @@ -164,7 +153,7 @@ obj1.pos.getTransform(t3d); bs1.transform(t3d); - // sol2 縺ョ BoundingSphere縲�繧定ィ育ョ� + // sol2 の BoundingSphere を計算 BoundingSphere bs2 = (BoundingSphere) (obj2.bs.clone()); obj2.center.getTransform(t3d); bs2.transform(t3d); @@ -175,7 +164,7 @@ obj2.pos.getTransform(t3d); bs2.transform(t3d); - // BoundingSphere 蜷悟」ォ縺ョ陦晉ェ∝愛螳� + // BoundingSphere 同士の衝突判定 if (bs1.intersect(bs2)) { f = true; }