• R/O
  • SSH
  • HTTPS

コミット

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-cqtcocoa誰得pythonphprubygameguibathyscaphec翻訳計画中(planning stage)omegatframeworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

X operations(XOPS)に非常に近いFPSゲームを制作・リメイクし、成果物をオープンソースとして公開することを目的としたプロジェクトです。


コミットメタ情報

リビジョン341 (tree)
日時2022-12-10 19:48:02
作者xops-mikan

ログメッセージ

人とマップの当たり判定処理を改善

変更サマリ

差分

--- trunk/object.cpp (revision 340)
+++ trunk/object.cpp (revision 341)
@@ -1511,6 +1511,8 @@
15111511
15121512 float pos_x2, pos_y2, pos_z2;
15131513 float dist_x, dist_y, dist_z;
1514+ float box_min_x, box_min_y, box_min_z, box_max_x, box_max_y, box_max_z;
1515+ bool CheckBlockID[MAX_BLOCKS];
15141516 float speed;
15151517 float Dist;
15161518 bool FallFlag;
@@ -1537,63 +1539,56 @@
15371539 dist_y = pos_y - pos_y2;
15381540 dist_z = pos_z - pos_z2;
15391541
1542+ int bs = inblockdata->GetTotaldatas();
1543+
1544+ //人のAABBを作成
1545+ box_min_x = pos_x - HUMAN_MAPCOLLISION_CHECK_MAXDIST - COLLISION_ADDSIZE;
1546+ box_min_y = pos_y - HUMAN_MAPCOLLISION_CHECK_MAXDIST - COLLISION_ADDSIZE;
1547+ box_min_z = pos_z - HUMAN_MAPCOLLISION_CHECK_MAXDIST - COLLISION_ADDSIZE;
1548+ box_max_x = pos_x + HUMAN_MAPCOLLISION_CHECK_MAXDIST + COLLISION_ADDSIZE;
1549+ box_max_y = (pos_y + HUMAN_HEIGHT) + HUMAN_MAPCOLLISION_CHECK_MAXDIST + COLLISION_ADDSIZE;
1550+ box_max_z = pos_z + HUMAN_MAPCOLLISION_CHECK_MAXDIST + COLLISION_ADDSIZE;
1551+
1552+ //AABB判定で対象ブロックを粗削りする
1553+ for(int i=0; i<bs; i++){
1554+ CheckBlockID[i] = CollD->CheckBlockAABB(i, box_min_x, box_min_y, box_min_z, box_max_x, box_max_y, box_max_z);
1555+ }
1556+
15401557 speed = sqrtf(dist_x*dist_x + dist_z*dist_z);
15411558 if( (speed != 0.0f)||(move_y != 0.0f) ){
15421559
1543- float box_min_x, box_min_y, box_min_z, box_max_x, box_max_y, box_max_z;
1544-
15451560 //頭部で当たり判定
1546- // ※AABB判定で粗削りする
1547- box_min_x = pos_x - speed - COLLISION_ADDSIZE;
1548- box_min_y = (pos_y + HUMAN_HEIGHT-0.22f) - speed - COLLISION_ADDSIZE;
1549- box_min_z = pos_z - speed - COLLISION_ADDSIZE;
1550- box_max_x = pos_x + speed + COLLISION_ADDSIZE;
1551- box_max_y = (pos_y + HUMAN_HEIGHT-0.22f) + speed + COLLISION_ADDSIZE;
1552- box_max_z = pos_z + speed + COLLISION_ADDSIZE;
1553- if( CollD->CheckALLBlockAABB(box_min_x, box_min_y, box_min_z, box_max_x, box_max_y, box_max_z) == true ){
1554- if( CollisionBlockScratch(CollD, inblockdata, &pos_x, &pos_y, &pos_z, pos_x2, pos_y2, pos_z2, pos_x, pos_y + HUMAN_HEIGHT-0.22f, pos_z, 0x01) == true ){
1555- if( move_y > 0.0f ){ move_y = 0.0f; }
1561+ for(int i=0; i<bs; i++){
1562+ if( CheckBlockID[i] == true ){
1563+ if( CollisionBlockScratch(CollD, inblockdata, i, &pos_x, &pos_y, &pos_z, pos_x2, pos_y2, pos_z2, pos_x, pos_y + HUMAN_HEIGHT-0.22f, pos_z, 0x01) == true ){
1564+ if( move_y > 0.0f ){ move_y = 0.0f; }
1565+ }
15561566 }
15571567 }
15581568
15591569 //足元で当たり判定
1560- // ※AABB判定で粗削りする
1561- box_min_x = pos_x - speed - COLLISION_ADDSIZE;
1562- box_min_y = pos_y - speed - COLLISION_ADDSIZE;
1563- box_min_z = pos_z - speed - COLLISION_ADDSIZE;
1564- box_max_x = pos_x + speed + COLLISION_ADDSIZE;
1565- box_max_y = pos_y + speed + COLLISION_ADDSIZE;
1566- box_max_z = pos_z + speed + COLLISION_ADDSIZE;
1567- if( CollD->CheckALLBlockAABB(box_min_x, box_min_y, box_min_z, box_max_x, box_max_y, box_max_z) == true ){
1568- CollisionBlockScratch(CollD, inblockdata, &pos_x, &pos_y, &pos_z, pos_x2, pos_y2, pos_z2, pos_x, pos_y, pos_z, 0x00);
1570+ for(int i=0; i<bs; i++){
1571+ if( CheckBlockID[i] == true ){
1572+ CollisionBlockScratch(CollD, inblockdata, i, &pos_x, &pos_y, &pos_z, pos_x2, pos_y2, pos_z2, pos_x, pos_y, pos_z, 0x00);
1573+ }
15691574 }
15701575
15711576 //腰くらいで当たり判定
1572- // ※AABB判定で粗削りする
1573- box_min_x = (pos_x - speed*HUMAN_MAPCOLLISION_R) - speed - COLLISION_ADDSIZE;
1574- box_min_y = (pos_y + HUMAN_MAPCOLLISION_HEIGHT) - speed - COLLISION_ADDSIZE;
1575- box_min_z = (pos_z - speed*HUMAN_MAPCOLLISION_R) - speed - COLLISION_ADDSIZE;
1576- box_max_x = (pos_x + speed*HUMAN_MAPCOLLISION_R) + speed + COLLISION_ADDSIZE;
1577- box_max_y = (pos_y + HUMAN_MAPCOLLISION_HEIGHT) + speed + COLLISION_ADDSIZE;
1578- box_max_z = (pos_z + speed*HUMAN_MAPCOLLISION_R) + speed + COLLISION_ADDSIZE;
1579- if( CollD->CheckALLBlockAABB(box_min_x, box_min_y, box_min_z, box_max_x, box_max_y, box_max_z) == true ){
1580- CollisionBlockScratch(CollD, inblockdata, &pos_x, &pos_y, &pos_z, pos_x2, pos_y2, pos_z2, pos_x + dist_x*HUMAN_MAPCOLLISION_R, pos_y + HUMAN_MAPCOLLISION_HEIGHT, pos_z + dist_z*HUMAN_MAPCOLLISION_R, 0x02);
1581- CollisionBlockScratch(CollD, inblockdata, &pos_x, &pos_y, &pos_z, pos_x2, pos_y2, pos_z2, pos_x + dist_z*HUMAN_MAPCOLLISION_R, pos_y + HUMAN_MAPCOLLISION_HEIGHT, pos_z + dist_x*HUMAN_MAPCOLLISION_R, 0x02);
1582- CollisionBlockScratch(CollD, inblockdata, &pos_x, &pos_y, &pos_z, pos_x2, pos_y2, pos_z2, pos_x + dist_z*HUMAN_MAPCOLLISION_R*-1, pos_y + HUMAN_MAPCOLLISION_HEIGHT, pos_z + dist_x*HUMAN_MAPCOLLISION_R*-1, 0x02);
1577+ for(int i=0; i<bs; i++){
1578+ if( CheckBlockID[i] == true ){
1579+ CollisionBlockScratch(CollD, inblockdata, i, &pos_x, &pos_y, &pos_z, pos_x2, pos_y2, pos_z2, pos_x + dist_x*HUMAN_MAPCOLLISION_R, pos_y + HUMAN_MAPCOLLISION_HEIGHT, pos_z + dist_z*HUMAN_MAPCOLLISION_R, 0x02);
1580+ CollisionBlockScratch(CollD, inblockdata, i, &pos_x, &pos_y, &pos_z, pos_x2, pos_y2, pos_z2, pos_x + dist_z*HUMAN_MAPCOLLISION_R, pos_y + HUMAN_MAPCOLLISION_HEIGHT, pos_z + dist_x*HUMAN_MAPCOLLISION_R, 0x02);
1581+ CollisionBlockScratch(CollD, inblockdata, i, &pos_x, &pos_y, &pos_z, pos_x2, pos_y2, pos_z2, pos_x + dist_z*HUMAN_MAPCOLLISION_R*-1, pos_y + HUMAN_MAPCOLLISION_HEIGHT, pos_z + dist_x*HUMAN_MAPCOLLISION_R*-1, 0x02);
1582+ }
15831583 }
15841584
15851585 if( AddCollisionFlag == true ){
15861586 //腰付近の追加当たり判定
1587- // ※AABB判定で粗削りする
1588- box_min_x = pos_x - speed - COLLISION_ADDSIZE;
1589- box_min_y = pos_y - speed - COLLISION_ADDSIZE;
1590- box_min_z = pos_z - speed - COLLISION_ADDSIZE;
1591- box_max_x = pos_x + speed + COLLISION_ADDSIZE;
1592- box_max_y = (pos_y + HUMAN_HEIGHT) + speed + COLLISION_ADDSIZE;
1593- box_max_z = pos_x + speed + COLLISION_ADDSIZE;
1594- if( CollD->CheckALLBlockAABB(box_min_x, box_min_y, box_min_z, box_max_x, box_max_y, box_max_z) == true ){
1595- CollisionBlockScratch(CollD, inblockdata, &pos_x, &pos_y, &pos_z, pos_x2, pos_y2, pos_z2, pos_x, pos_y + HUMAN_MAPCOLLISION_ADD_HEIGHT_A, pos_z, 0x02);
1596- CollisionBlockScratch(CollD, inblockdata, &pos_x, &pos_y, &pos_z, pos_x2, pos_y2, pos_z2, pos_x, pos_y + HUMAN_MAPCOLLISION_ADD_HEIGHT_B, pos_z, 0x02);
1587+ for(int i=0; i<bs; i++){
1588+ if( CheckBlockID[i] == true ){
1589+ CollisionBlockScratch(CollD, inblockdata, i, &pos_x, &pos_y, &pos_z, pos_x2, pos_y2, pos_z2, pos_x, pos_y + HUMAN_MAPCOLLISION_ADD_HEIGHT_A, pos_z, 0x02);
1590+ CollisionBlockScratch(CollD, inblockdata, i, &pos_x, &pos_y, &pos_z, pos_x2, pos_y2, pos_z2, pos_x, pos_y + HUMAN_MAPCOLLISION_ADD_HEIGHT_B, pos_z, 0x02);
1591+ }
15971592 }
15981593 }
15991594
@@ -1600,60 +1595,60 @@
16001595 //斜面を登る
16011596 if( (fabsf(move_x) > 0.2f)||(fabsf(move_z) > 0.2f) ){
16021597 if( move_y_upper == 0 ){
1603- if(
1604- (CollD->CheckALLBlockInside(pos_x + dist_x*2.0f, pos_y, pos_z + dist_z*2.0f) == true)&&
1605- (CollD->CheckALLBlockInside(pos_x + dist_x*2.0f, pos_y + HUMAN_MAPCOLLISION_CLIMBHEIGHT, pos_z + dist_z*2.0f) == false)
1606- ){
1607- int id, face;
1608- blockdata bdata;
1609- bool flag = false;
1598+ for(int i=0; i<bs; i++){
1599+ if( CheckBlockID[i] == true ){
1600+ if(
1601+ (CollD->CheckBlockInside(i, pos_x + dist_x*2.0f, pos_y, pos_z + dist_z*2.0f, true, NULL) == true)&&
1602+ (CollD->CheckBlockInside(i, pos_x + dist_x*2.0f, pos_y + HUMAN_MAPCOLLISION_CLIMBHEIGHT, pos_z + dist_z*2.0f, true, NULL) == false)
1603+ ){
1604+ int face;
1605+ blockdata bdata;
1606+ bool flag = false;
16101607
1611- //足元の面の角度を取得
1612- if( CollD->CheckALLBlockIntersectDummyRay(pos_x, pos_y, pos_z, 0.0f, -1.0f, 0.0f, NULL, NULL, &Dist, 1.2f) == true ){
1613- CollD->CheckALLBlockIntersectRay(pos_x, pos_y + HUMAN_MAPCOLLISION_CLIMBADDY, pos_z, 0.0f, -1.0f, 0.0f, &id, &face, &Dist, 1.2f + HUMAN_MAPCOLLISION_CLIMBADDY);
1608+ //足元の面の角度を取得
1609+ // ※足元にブロックがあることは確定なので、DummyRayは必要ない・・・はず。
1610+ if( CollD->CheckBlockIntersectRay(i, pos_x, pos_y + HUMAN_MAPCOLLISION_CLIMBADDY, pos_z, 0.0f, -1.0f, 0.0f, &face, &Dist, 1.2f + HUMAN_MAPCOLLISION_CLIMBADDY) == true ){
16141611
1615- inblockdata->Getdata(&bdata, id);
1612+ inblockdata->Getdata(&bdata, i);
16161613
1617- //斜面に立っているならば、上昇無効
1618- if( acosf(bdata.material[face].vy) > HUMAN_MAPCOLLISION_SLOPEANGLE ){
1619- flag = true;
1614+ //斜面に立っているならば、上昇無効
1615+ if( acosf(bdata.material[face].vy) > HUMAN_MAPCOLLISION_SLOPEANGLE ){
1616+ flag = true;
1617+ }
1618+ }
1619+
1620+ if( flag == false ){
1621+ pos_y += HUMAN_MAPCOLLISION_CLIMBADDY;
1622+ move_y *= 0.2f;
1623+ }
16201624 }
16211625 }
1622-
1623- if( flag == false ){
1624- pos_y += HUMAN_MAPCOLLISION_CLIMBADDY;
1625- move_y *= 0.2f;
1626- }
16271626 }
16281627 }
16291628 }
16301629
16311630 //移動先がブロックへめり込んでいるなら移動を無効にする
1632- // ※AABB判定で粗削りする
1633- box_min_x = pos_x - 1.0f - COLLISION_ADDSIZE;
1634- box_min_y = (pos_y + 2.0f) - 1.0f - COLLISION_ADDSIZE;
1635- box_min_z = pos_z - 1.0f - COLLISION_ADDSIZE;
1636- box_max_x = pos_x + 1.0f + COLLISION_ADDSIZE;
1637- box_max_y = (pos_y + (HUMAN_HEIGHT-2.0f*2)) + 1.0f + COLLISION_ADDSIZE;
1638- box_max_z = pos_z + 1.0f + COLLISION_ADDSIZE;
1639- if( CollD->CheckALLBlockAABB(box_min_x, box_min_y, box_min_z, box_max_x, box_max_y, box_max_z) == true ){
1640- if(
1641- (CollD->CheckALLBlockInside(pos_x, pos_y + 2.0f, pos_z) == true)||
1642- (CollD->CheckALLBlockIntersectRay(pos_x, pos_y + 2.0f, pos_z, 0.0f, 1.0f, 0.0f, NULL, NULL, &Dist, (HUMAN_HEIGHT-2.0f*2)) == true)
1643- ){
1644- pos_x = pos_x2;
1645- pos_z = pos_z2;
1646- }
1647-
1648- //移動先がブロックにめり込む&移動先もめり込む ならば、移動を無効にする
1649- if( CollD->CheckALLBlockInside(pos_x, pos_y + HUMAN_HEIGHT-0.6f, pos_z) == true ){
1650- //メモ:↓この判定怪しい。十分に遠い位置であれば良く、11倍である必要はない?
1651- if( CollD->CheckALLBlockInside(pos_x + move_x*11.0f, pos_y + HUMAN_HEIGHT-0.6f, pos_z + move_z*11.0f) == true ){
1631+ for(int i=0; i<bs; i++){
1632+ if( CheckBlockID[i] == true ){
1633+ if(
1634+ (CollD->CheckBlockInside(i, pos_x, pos_y + 2.0f, pos_z, true, NULL) == true)||
1635+ (CollD->CheckBlockIntersectRay(i, pos_x, pos_y + 2.0f, pos_z, 0.0f, 1.0f, 0.0f, NULL, &Dist, (HUMAN_HEIGHT-2.0f*2)) == true)
1636+ ){
16521637 pos_x = pos_x2;
1653- pos_y = pos_y2;
16541638 pos_z = pos_z2;
1655- if( move_y > 0.0f ){ move_y = 0.0f; }
16561639 }
1640+
1641+ //移動先がブロックにめり込む&移動先もめり込む ならば、移動を無効にする
1642+ if( CollD->CheckBlockInside(i, pos_x, pos_y + HUMAN_HEIGHT-0.6f, pos_z, true, NULL) == true ){
1643+ //メモ:↓この判定怪しい。十分に遠い位置であれば良く、11倍である必要はない?
1644+ // ※AABBの判定範囲越えて遠いので、全部ブロック調べ直す。
1645+ if( CollD->CheckALLBlockInside(pos_x + move_x*11.0f, pos_y + HUMAN_HEIGHT-0.6f, pos_z + move_z*11.0f) == true ){
1646+ pos_x = pos_x2;
1647+ pos_y = pos_y2;
1648+ pos_z = pos_z2;
1649+ if( move_y > 0.0f ){ move_y = 0.0f; }
1650+ }
1651+ }
16571652 }
16581653 }
16591654 }
@@ -1663,7 +1658,7 @@
16631658 //落下処理
16641659 move_y_flag = false;
16651660 FallFlag = false;
1666- for(int i=0; i<3; i++){
1661+ for(int ycnt=0; ycnt<3; ycnt++){
16671662 int cnt = 0;
16681663 float ang = atan2f(move_z, move_x);
16691664 float x, y, z;
@@ -1679,31 +1674,63 @@
16791674 //4方向判定 No.1
16801675 x = pos_x + cosf(ang)*HUMAN_MAPCOLLISION_GROUND_R1;
16811676 z = pos_z + sinf(ang)*HUMAN_MAPCOLLISION_GROUND_R1;
1682- if( CollD->CheckALLBlockInside(x, y, z) == true ){ cnt += 1; }
1677+ for(int i=0; i<bs; i++){
1678+ if( CheckBlockID[i] == true ){
1679+ if( CollD->CheckBlockInside(i, x, y, z, true, NULL) == true ){ cnt += 1; break; }
1680+ }
1681+ }
16831682 x = pos_x - cosf(ang)*HUMAN_MAPCOLLISION_GROUND_R1;
16841683 z = pos_z - sinf(ang)*HUMAN_MAPCOLLISION_GROUND_R1;
1685- if( CollD->CheckALLBlockInside(x, y, z) == true ){ cnt += 1; }
1684+ for(int i=0; i<bs; i++){
1685+ if( CheckBlockID[i] == true ){
1686+ if( CollD->CheckBlockInside(i, x, y, z, true, NULL) == true ){ cnt += 1; break; }
1687+ }
1688+ }
16861689 x = pos_x + cosf(ang + (float)M_PI/2)*HUMAN_MAPCOLLISION_GROUND_R1;
16871690 z = pos_z + sinf(ang + (float)M_PI/2)*HUMAN_MAPCOLLISION_GROUND_R1;
1688- if( CollD->CheckALLBlockInside(x, y, z) == true ){ cnt += 1; }
1691+ for(int i=0; i<bs; i++){
1692+ if( CheckBlockID[i] == true ){
1693+ if( CollD->CheckBlockInside(i, x, y, z, true, NULL) == true ){ cnt += 1; break; }
1694+ }
1695+ }
16891696 x = pos_x + cosf(ang - (float)M_PI/2)*HUMAN_MAPCOLLISION_GROUND_R1;
16901697 z = pos_z + sinf(ang - (float)M_PI/2)*HUMAN_MAPCOLLISION_GROUND_R1;
1691- if( CollD->CheckALLBlockInside(x, y, z) == true ){ cnt += 1; }
1698+ for(int i=0; i<bs; i++){
1699+ if( CheckBlockID[i] == true ){
1700+ if( CollD->CheckBlockInside(i, x, y, z, true, NULL) == true ){ cnt += 1; break; }
1701+ }
1702+ }
16921703 if( cnt == 4 ){ FallFlag = true; break; }
16931704
16941705 //4方向判定 No.2
16951706 x = pos_x + cosf(ang)*HUMAN_MAPCOLLISION_GROUND_R2;
16961707 z = pos_z + sinf(ang)*HUMAN_MAPCOLLISION_GROUND_R2;
1697- if( CollD->CheckALLBlockInside(x, y, z) == true ){ cnt += 1; }
1708+ for(int i=0; i<bs; i++){
1709+ if( CheckBlockID[i] == true ){
1710+ if( CollD->CheckBlockInside(i, x, y, z, true, NULL) == true ){ cnt += 1; break; }
1711+ }
1712+ }
16981713 x = pos_x - cosf(ang)*HUMAN_MAPCOLLISION_GROUND_R2;
16991714 z = pos_z - sinf(ang)*HUMAN_MAPCOLLISION_GROUND_R2;
1700- if( CollD->CheckALLBlockInside(x, y, z) == true ){ cnt += 1; }
1715+ for(int i=0; i<bs; i++){
1716+ if( CheckBlockID[i] == true ){
1717+ if( CollD->CheckBlockInside(i, x, y, z, true, NULL) == true ){ cnt += 1; break; }
1718+ }
1719+ }
17011720 x = pos_x + cosf(ang + (float)M_PI/2)*HUMAN_MAPCOLLISION_GROUND_R2;
17021721 z = pos_z + sinf(ang + (float)M_PI/2)*HUMAN_MAPCOLLISION_GROUND_R2;
1703- if( CollD->CheckALLBlockInside(x, y, z) == true ){ cnt += 1; }
1722+ for(int i=0; i<bs; i++){
1723+ if( CheckBlockID[i] == true ){
1724+ if( CollD->CheckBlockInside(i, x, y, z, true, NULL) == true ){ cnt += 1; break; }
1725+ }
1726+ }
17041727 x = pos_x + cosf(ang - (float)M_PI/2)*HUMAN_MAPCOLLISION_GROUND_R2;
17051728 z = pos_z + sinf(ang - (float)M_PI/2)*HUMAN_MAPCOLLISION_GROUND_R2;
1706- if( CollD->CheckALLBlockInside(x, y, z) == true ){ cnt += 1; }
1729+ for(int i=0; i<bs; i++){
1730+ if( CheckBlockID[i] == true ){
1731+ if( CollD->CheckBlockInside(i, x, y, z, true, NULL) == true ){ cnt += 1; break; }
1732+ }
1733+ }
17071734 if( cnt == 4 ){ FallFlag = true; break; }
17081735 }
17091736 else{
@@ -1712,12 +1739,22 @@
17121739 //真下判定
17131740 x = pos_x;
17141741 z = pos_z;
1715- if( CollD->CheckALLBlockInside(x, y, z) == true ){ FallFlag = true; break; }
1742+ for(int i=0; i<bs; i++){
1743+ if( CheckBlockID[i] == true ){
1744+ if( CollD->CheckBlockInside(i, x, y, z, true, NULL) == true ){ FallFlag = true; break; }
1745+ }
1746+ }
1747+ if( FallFlag == true ){ break; }
17161748
17171749 //外側へ少し外して判定
17181750 x = pos_x + cosf(ang)*HUMAN_MAPCOLLISION_GROUND_R3;
17191751 z = pos_z + sinf(ang)*HUMAN_MAPCOLLISION_GROUND_R3;
1720- if( CollD->CheckALLBlockInside(x, y, z) == true ){ FallFlag = true; break; }
1752+ for(int i=0; i<bs; i++){
1753+ if( CheckBlockID[i] == true ){
1754+ if( CollD->CheckBlockInside(i, x, y, z, true, NULL) == true ){ FallFlag = true; break; }
1755+ }
1756+ }
1757+ if( FallFlag == true ){ break; }
17211758 }
17221759
17231760 //落下速度加算
@@ -1757,9 +1794,17 @@
17571794 }
17581795
17591796 //足元のブロックと面番号を取得
1760- if( CollD->CheckALLBlockIntersectDummyRay(pos_x, pos_y + 2.5f, pos_z, 0.0f, -1.0f, 0.0f, NULL, NULL, &Dist, (2.5f + 1.0f)) == true ){
1761- CollD->CheckALLBlockIntersectRay(pos_x, pos_y + 2.5f, pos_z, 0.0f, -1.0f, 0.0f, &id, &face, &Dist, (2.5f + 1.0f));
1797+ id = -1;
1798+ for(int i=0; i<bs; i++){
1799+ if( CheckBlockID[i] == true ){
1800+ if( CollD->CheckBlockIntersectRay(i, pos_x, pos_y + 2.5f, pos_z, 0.0f, -1.0f, 0.0f, &face, &Dist, (2.5f + 1.0f)) == true ){
1801+ id = i;
1802+ break;
1803+ }
1804+ }
1805+ }
17621806
1807+ if( id != -1 ){
17631808 //ブロックIDと面番号を返す
17641809 if( underblock_id != NULL ){ *underblock_id = id; }
17651810 if( underblock_face != NULL ){ *underblock_face = face; }
@@ -1773,11 +1818,16 @@
17731818 move_y = bdata.material[face].vy * -0.5f;
17741819 move_z = bdata.material[face].vz * 1.2f;
17751820
1776- if( CollD->CheckALLBlockInside(pos_x + move_x*3.0f, pos_y + move_y*3.0f, pos_z + move_z*3.0f) == true ){
1777- move_y = 0.0f;
1778- if( CollD->CheckALLBlockInside(pos_x + move_x*3.0f, pos_y, pos_z + move_z*3.0f) == true ){
1779- move_x = 0.0f;
1780- move_z = 0.0f;
1821+ for(int i=0; i<bs; i++){
1822+ if( CheckBlockID[i] == true ){
1823+ if( CollD->CheckBlockInside(i, pos_x + move_x*3.0f, pos_y + move_y*3.0f, pos_z + move_z*3.0f, true, NULL) == true ){
1824+ move_y = 0.0f;
1825+ if( CollD->CheckBlockInside(i, pos_x + move_x*3.0f, pos_y, pos_z + move_z*3.0f, true, NULL) == true ){
1826+ move_x = 0.0f;
1827+ move_z = 0.0f;
1828+ break;
1829+ }
1830+ }
17811831 }
17821832 }
17831833
@@ -1820,6 +1870,7 @@
18201870 //! @brief ブロックと衝突時のベクトル計算
18211871 //! @param CollD Collisionクラスのポインタ
18221872 //! @param inblockdata BlockDataInterfaceクラスのポインタ
1873+//! @param blockid ブロックID
18231874 //! @param px X座標
18241875 //! @param py Y座標
18251876 //! @param pz Z座標
@@ -1831,16 +1882,17 @@
18311882 //! @param in_vz 判定するZ座標
18321883 //! @param mode 座標補正モード(0x00:通常、0x01:Y座標上昇禁止、0x02:Y座標固定)
18331884 //! @return 成功:true 失敗:false
1834-bool human::CollisionBlockScratch(class Collision *CollD, class BlockDataInterface *inblockdata, float *px, float *py, float *pz, float px_old, float py_old, float pz_old, float in_vx, float in_vy, float in_vz, int mode)
1885+bool human::CollisionBlockScratch(class Collision *CollD, class BlockDataInterface *inblockdata, int blockid, float *px, float *py, float *pz, float px_old, float py_old, float pz_old, float in_vx, float in_vy, float in_vz, int mode)
18351886 {
18361887 if( CollD == NULL ){ return false; }
18371888 if( inblockdata == NULL ){ return false; }
1889+ if( (blockid < 0)||(inblockdata->GetTotaldatas() <= blockid) ){ return false; }
18381890 //if( (*px == px_old)&&(*py == py_old)&&(*pz == pz_old) ){ return false; }
18391891
18401892 float px2, py2, pz2;
18411893 float vx, vy, vz;
18421894 float dist;
1843- int id, face;
1895+ int face;
18441896 float face_vx, face_vy, face_vz, face_angle, face_angle_per;
18451897 float temp;
18461898
@@ -1854,22 +1906,17 @@
18541906 vz = *pz - pz_old;
18551907 dist = VectorNormalization(&vx, &vy, &vz);
18561908
1857- //追突したブロック面取得
1909+ //AABBを作る
18581910 float rmin_x, rmin_y, rmin_z, rmax_x, rmax_y, rmax_z;
1859- id = -1;
18601911 GetAABBRay(in_vx - vx, in_vy - vy, in_vz - vz, vx, vy, vz, dist, &rmin_x, &rmin_y, &rmin_z, &rmax_x, &rmax_y, &rmax_z);
1861- for(int i=0; i<inblockdata->GetTotaldatas(); i++){
1862- if( CollD->CheckBlockAABB(i, rmin_x, rmin_y, rmin_z, rmax_x, rmax_y, rmax_z) == true ){
1863- if( CollD->CheckBlockIntersectRay(i, in_vx - vx, in_vy - vy, in_vz - vz, vx, vy, vz, &face, &temp, dist) == true ){
1864- id = i;
1865- break;
1866- }
1867- }
1868- }
1869- if( id == -1 ){ return false; }
18701912
1913+ //追突したブロック面取得
1914+ face = -1;
1915+ if( CollD->CheckBlockAABB(blockid, rmin_x, rmin_y, rmin_z, rmax_x, rmax_y, rmax_z) == false ){ return false; }
1916+ if( CollD->CheckBlockIntersectRay(blockid, in_vx - vx, in_vy - vy, in_vz - vz, vx, vy, vz, &face, &temp, dist) == false ){ return false; }
1917+
18711918 //ブロックに沿って移動するベクトルと進入角度を求める
1872- if( CollD->ScratchAngleVector(id, face, vx, vy, vz, &vx, &vy, &vz, &face_angle) == false ){ return false; }
1919+ if( CollD->ScratchAngleVector(blockid, face, vx, vy, vz, &vx, &vy, &vz, &face_angle) == false ){ return false; }
18731920
18741921 //角度の割合算出
18751922 if( face_angle != 0.0f ){ face_angle_per = 1.0f - face_angle / ((float)M_PI); }
@@ -1877,7 +1924,7 @@
18771924
18781925 //ブロック面の法線ベクトル取得
18791926 blockdata bdata;
1880- inblockdata->Getdata(&bdata, id);
1927+ inblockdata->Getdata(&bdata, blockid);
18811928 face_vx = bdata.material[face].vx;
18821929 face_vy = bdata.material[face].vy;
18831930 face_vz = bdata.material[face].vz;
@@ -1889,7 +1936,8 @@
18891936 *pz = vz*temp + pz_old;
18901937
18911938 //最終的な位置がブロックの内側ならば、移動無効
1892- if( CollD->CheckALLBlockInside(*px, *py, *pz) == true ){
1939+ //if( CollD->CheckALLBlockInside(*px, *py, *pz) == true ){
1940+ if( CollD->CheckBlockInside(blockid, *px, *py, *pz, true, NULL) == true ){
18931941 *px = px2;
18941942 *py = py2;
18951943 *pz = pz2;
--- trunk/object.h (revision 340)
+++ trunk/object.h (revision 341)
@@ -179,7 +179,7 @@
179179 int CheckAndProcessDead(class Collision *CollD);
180180 void ControlProcess();
181181 void CollisionMap(class Collision *CollD, class BlockDataInterface *inblockdata, bool AddCollisionFlag, bool player, int *underblock_id, int *underblock_face);
182- bool CollisionBlockScratch(class Collision *CollD, class BlockDataInterface *inblockdata, float *px, float *py, float *pz, float px_old, float py_old, float pz_old, float in_vx, float in_vy, float in_vz, int mode);
182+ bool CollisionBlockScratch(class Collision *CollD, class BlockDataInterface *inblockdata, int blockid, float *px, float *py, float *pz, float px_old, float py_old, float pz_old, float in_vx, float in_vy, float in_vz, int mode);
183183
184184 public:
185185 human(class ParameterInfo *in_Param = NULL, float x = 0.0f, float y = 0.0f, float z = 0.0f, float rx = 0.0f, int id_param = -1, int dataid = 0, signed short int p4 = 0, int team = 0, bool flag = false);