diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index abef6f4..d8b7bba 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -2,5 +2,6 @@ encoding//src/main/java/org/ntlab/radishforandroidstudio/framework/model3D/ModelFactory.java=UTF-8 encoding//src/main/java/org/ntlab/radishforandroidstudio/framework/model3D/Quaternion3D.java=UTF-8 encoding//src/main/java/org/ntlab/radishforandroidstudio/framework/model3D/Universe.java=UTF-8 +encoding//src/main/java/org/ntlab/radishforandroidstudio/framework/physics/PhysicsUtility.java=UTF-8 encoding//src/main/java/org/ntlab/radishforandroidstudio/java3d/AxisAngle4d.java=UTF-8 encoding//src/main/java/org/ntlab/radishforandroidstudio/java3d/Box.java=UTF-8 diff --git a/src/main/java/cactusServer/entities/Object.java b/src/main/java/cactusServer/entities/Object.java index 1d27457..0b9d975 100644 --- a/src/main/java/cactusServer/entities/Object.java +++ b/src/main/java/cactusServer/entities/Object.java @@ -41,8 +41,8 @@ setAngle(angle); setAttribute(attribute); setModel(modelID); - prim = new Box(); - object = new Object3D("",prim); + setPrim(new Box()); + setObject(new Object3D("",prim)); setPlaceable(object); } diff --git a/src/main/java/cactusServer/models/CollisionManager.java b/src/main/java/cactusServer/models/CollisionManager.java new file mode 100644 index 0000000..8765087 --- /dev/null +++ b/src/main/java/cactusServer/models/CollisionManager.java @@ -0,0 +1,20 @@ +package cactusServer.models; + +import org.ntlab.radishforandroidstudio.framework.model3D.CollisionResult; + +public class CollisionManager { + private static CollisionManager theInstance; + private CollisionResult result; + public static CollisionManager getCollision() { + if (theInstance == null) { + theInstance = new CollisionManager(); + } + return theInstance; + } + public CollisionResult getResult() { + return result; + } + public void setResult(CollisionResult result) { + this.result = result; + } +} 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 f52627c..0043f2d 100644 --- a/src/main/java/org/ntlab/radishforandroidstudio/framework/physics/PhysicsUtility.java +++ b/src/main/java/org/ntlab/radishforandroidstudio/framework/physics/PhysicsUtility.java @@ -10,39 +10,41 @@ import org.ntlab.radishforandroidstudio.java3d.Transform3D; 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); /** - * 物体に加わる重力を求める - * @param body 対象物体 - * @return bodyに加わる重力 + * 迚ゥ菴薙↓蜉�繧上k驥榊鴨繧呈アゅa繧� + * + * @param body + * 蟇セ雎。迚ゥ菴� + * @return body縺ォ蜉�繧上k驥榊鴨 */ public static Force3D getGravity(Solid3D body) { - return new Force3D(gravityDirection.x * -body.mass * GRAVITY, gravityDirection.y * -body.mass * GRAVITY, gravityDirection.z * -body.mass * GRAVITY); + return new Force3D(gravityDirection.x * -body.mass * GRAVITY, gravityDirection.y * -body.mass * GRAVITY, + gravityDirection.z * -body.mass * GRAVITY); } /** * @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) { + // 繝「繝シ繝。繝ウ繝医�ョ險育ョ� + static Vector3d calcMoment(Force3D f, Position3D gravityCenter, Position3D applicationPoint) { Vector3d v1 = applicationPoint.getVector3d(); Vector3d v2 = gravityCenter.getVector3d(); v1.sub(v2); @@ -55,35 +57,41 @@ } /** - * 物体の反発係数から衝突時に加わる力を求める - * @param interval 衝突している時間 - * @param nor 物体がぶつかった面の宝仙ベクトル - * @param solid 物体 - * @return 衝突時に加わる力 + * 迚ゥ菴薙�ョ蜿咲匱菫よ焚縺九i陦晉ェ∵凾縺ォ蜉�繧上k蜉帙r豎ゅa繧� + * + * @param interval + * 陦晉ェ√@縺ヲ縺�繧区凾髢� + * @param nor + * 迚ゥ菴薙′縺カ縺、縺九▲縺滄擇縺ョ螳昜サ吶�吶け繝医Ν + * @param solid + * 迚ゥ菴� + * @return 陦晉ェ∵凾縺ォ蜉�繧上k蜉� */ public static Force3D calcForce(long interval, Vector3d nor, Solid3D solid) { double f1 = 0.0; - Vector3d vf = new Vector3d(solid.getVelocity().getX(), solid - .getVelocity().getY(), solid.getVelocity().getZ()); - f1 = solid.mass * (vf.length() + solid.e * vf.length()) - / ((double) interval / 1000.0); + Vector3d vf = new Vector3d(solid.getVelocity().getX(), solid.getVelocity().getY(), solid.getVelocity().getZ()); + f1 = solid.mass * (vf.length() + solid.e * vf.length()) / ((double) interval / 1000.0); nor.scale(f1); Force3D f = new Force3D(nor.x, nor.y, nor.z); return f; } /** - * 物体と地面との衝突判定 - * @param obj 物体 - * @param ground 地面 - * @return 衝突情報(nullのとき衝突なし) + * 迚ゥ菴薙→蝨ー髱「縺ィ縺ョ陦晉ェ∝愛螳� + * + * @param obj + * 迚ゥ菴� + * @param ground + * 蝨ー髱「 + * @return 陦晉ェ∵ュ蝣ア�シ�null縺ョ縺ィ縺崎。晉ェ√↑縺暦シ� */ public static CollisionResult doesIntersect(Solid3D obj, Ground ground) { - if (ground == null) return null; + if (ground == null) + return null; CollisionResult cr = null; BoundingSurface boundingSurface = ground.getBoundingSurface(); - // BoundingSphereを使って大雑把に衝突判定を行う + // BoundingSphere繧剃スソ縺」縺ヲ螟ァ髮第滑縺ォ陦晉ェ∝愛螳壹r陦後≧ ArrayList boundingSurfaceList = null; if (obj.bs != null) { BoundingSphere bs = (BoundingSphere) (obj.bs.clone()); @@ -96,26 +104,28 @@ bs.transform(t3d); obj.pos.getTransform(t3d); bs.transform(t3d); - // 粗い衝突判定を行う(最上位のBoundingSurfaceとBoundingSphereの間で) + // 邊励>陦晉ェ∝愛螳壹r陦後≧�シ域怙荳贋ス阪�ョBoundingSurface縺ィBoundingSphere縺ョ髢薙〒�シ� boundingSurfaceList = boundingSurface.intersect(bs); bs = null; t3d = null; } if (obj.bs == null) { - // BoundingSphere がまだ作られていななかった場合、 - // 詳細な衝突判定のために、最上位の全 BoundingSurface を取得する - if (boundingSurfaceList == null) boundingSurfaceList = new ArrayList(); + // BoundingSphere 縺後∪縺�菴懊i繧後※縺�縺ェ縺ェ縺九▲縺溷�エ蜷医�� + // 隧ウ邏ー縺ェ陦晉ェ∝愛螳壹�ョ縺溘a縺ォ縲∵怙荳贋ス阪�ョ蜈ィ BoundingSurface 繧貞叙蠕励☆繧� + if (boundingSurfaceList == null) + boundingSurfaceList = new ArrayList(); boundingSurfaceList.add(boundingSurface); } - + if (boundingSurfaceList.size() > 0) { - // 粗い衝突判定で衝突していた場合、OBBの集合を用いてより詳しい衝突判定を行う - // (BoundingSphere がまだ作られていない場合、OBB の作成と同時に BoundingSphere を作成される) + // 邊励>陦晉ェ∝愛螳壹〒陦晉ェ√@縺ヲ縺�縺溷�エ蜷医�^BB縺ョ髮�蜷医r逕ィ縺�縺ヲ繧医j隧ウ縺励>陦晉ェ∝愛螳壹r陦後≧ + // �シ�BoundingSphere 縺後∪縺�菴懊i繧後※縺�縺ェ縺�蝣エ蜷医�^BB 縺ョ菴懈�舌→蜷梧凾縺ォ BoundingSphere + // 繧剃ス懈�舌&繧後k�シ� BoundingBoxVisitor obbVisitor = new BoundingBoxVisitor(); obj.accept(obbVisitor); for (int i = 0; i < obbVisitor.getObbList().size(); i++) { - // OBBと衝突判定をする場合は、地面を多角形のまま扱う + // OBB縺ィ陦晉ェ∝愛螳壹r縺吶k蝣エ蜷医�ッ縲∝慍髱「繧貞、夊ァ貞ス「縺ョ縺セ縺セ謇ア縺� for (int j = 0; j < boundingSurfaceList.size(); j++) { cr = boundingSurfaceList.get(j).intersect(obbVisitor.getObbList().get(i)); if (cr != null) { @@ -123,7 +133,7 @@ } } } - obbVisitor = null; + obbVisitor = null; } return null; } @@ -131,19 +141,18 @@ /** * 物体同士の衝突判定 * @param obj1 物体1 - * @param part1 判定する物体1の部分の名称 + * @param part1 判定する物体1の部品の名称 * @param obj2 物体2 - * @param part2 判定する物体2の部分の名称 - * @return 衝突情報(nullのとき衝突なし) + * @param part2 判定する物体2の部品の名称 + * @return 衝突情報 nullのとき衝突なし */ - public static CollisionResult checkCollision(Object3D obj1, String part1, - Object3D obj2, String part2) { + public static CollisionResult checkCollision(Object3D obj1, String part1, Object3D obj2, String part2) { CollisionResult cr = null; - // BoundingSphereを使って大雑把に衝突判定を行う + // BoundingSphere繧剃スソ縺」縺ヲ螟ァ髮第滑縺ォ陦晉ェ∝愛螳壹r陦後≧ 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); @@ -155,7 +164,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); @@ -165,8 +174,8 @@ bs2.transform(t3d); obj2.pos.getTransform(t3d); bs2.transform(t3d); - - // BoundingSphere 同士の衝突判定 + + // BoundingSphere 蜷悟」ォ縺ョ陦晉ェ∝愛螳� if (bs1.intersect(bs2)) { f = true; } @@ -198,8 +207,7 @@ // return v; return cr; } else { - cr = visitor1.getObbList().get(i).intersect( - visitor2.getObbList().get(j)); + cr = visitor1.getObbList().get(i).intersect(visitor2.getObbList().get(j)); if (cr != null) { cr.normal.scale(-1.0); // Vector3d v = new Vector3d(0,0,0);