X operations(XOPS)に非常に近いFPSゲームを制作・リメイクし、成果物をオープンソースとして公開することを目的としたプロジェクトです。
リビジョン | 189 (tree) |
---|---|
日時 | 2017-11-06 00:21:53 |
作者 | xops-mikan |
手榴弾の物理計算を改良、ソースコード内のインデント(字下げ)改善
@@ -845,7 +845,30 @@ | ||
845 | 845 | *out_vz = in_vz - 2.0f * Dot * bdata.material[face].vz; |
846 | 846 | } |
847 | 847 | |
848 | +//! @brief ブロックに対するベクトルの進入角度を求める | |
849 | +//! @return 成功:true 失敗:false | |
850 | +//! @attention 表向き:0.0〜PI/2(0.0度〜90.0度)、裏向き:-0.0〜-PI/2(-0.0度〜-90.0度) | |
851 | +bool Collision::AngleVector(int id, int face, float in_vx, float in_vy, float in_vz, float *out_angle) | |
852 | +{ | |
853 | + if( blockdata == NULL ){ return false; } | |
854 | + if( (id < 0)||(blockdata->GetTotaldatas() <= id) ){ return false; } | |
855 | + if( (face < 0)||(6 < face) ){ return false; } | |
848 | 856 | |
857 | + struct blockdata bdata; | |
858 | + blockdata->Getdata(&bdata, id); | |
859 | + | |
860 | + float maxDist = sqrt(in_vx*in_vx + in_vy*in_vy + in_vz*in_vz); | |
861 | + if( maxDist == 0.0f ){ return false; } | |
862 | + | |
863 | + //内積 | |
864 | + float Dot = in_vx/maxDist * bdata.material[face].vx + in_vy/maxDist * bdata.material[face].vy + in_vz/maxDist * bdata.material[face].vz; | |
865 | + | |
866 | + //角度を求める | |
867 | + *out_angle = asin(Dot) * -1; | |
868 | + | |
869 | + return true; | |
870 | +} | |
871 | + | |
849 | 872 | //! @brief AABBによる当たり判定 |
850 | 873 | //! @param box1_min_x 物体Aの最少 X座標 |
851 | 874 | //! @param box1_min_y 物体Aの最少 Y座標 |
@@ -81,6 +81,7 @@ | ||
81 | 81 | bool CheckALLBlockIntersectDummyRay(float RayPos_x, float RayPos_y, float RayPos_z, float RayDir_x, float RayDir_y, float RayDir_z, int *id, int *face, float *Dist, float maxDist); |
82 | 82 | void ScratchVector(int id, int face, float in_vx, float in_vy, float in_vz, float *out_vx, float *out_vy, float *out_vz); |
83 | 83 | void ReflectVector(int id, int face, float in_vx, float in_vy, float in_vz, float *out_vx, float *out_vy, float *out_vz); |
84 | + bool AngleVector(int id, int face, float in_vx, float in_vy, float in_vz, float *out_angle); | |
84 | 85 | }; |
85 | 86 | |
86 | 87 | bool CollideBoxAABB(float box1_min_x, float box1_min_y, float box1_min_z, float box1_max_x, float box1_max_y, float box1_max_z, float box2_min_x, float box2_min_y, float box2_min_z, float box2_max_x, float box2_max_y, float box2_max_z); |
@@ -2539,19 +2539,6 @@ | ||
2539 | 2539 | return 0; |
2540 | 2540 | } |
2541 | 2541 | |
2542 | - /* | |
2543 | - //静止に近い状態ならば、移動処理をしない。 | |
2544 | - if( (move_x*move_x + move_y*move_y + move_z*move_z) < 0.1f*0.1f ){ | |
2545 | - cnt += 1; | |
2546 | - return 0; | |
2547 | - } | |
2548 | - */ | |
2549 | - | |
2550 | - //移動速度を計算 | |
2551 | - move_x *= 0.98f; | |
2552 | - move_y = (move_y - 0.17f) * 0.98f; | |
2553 | - move_z *= 0.98f; | |
2554 | - | |
2555 | 2542 | int id, face; |
2556 | 2543 | float Dist; |
2557 | 2544 | float maxDist = sqrt(move_x*move_x + move_y*move_y + move_z*move_z); |
@@ -2558,21 +2545,32 @@ | ||
2558 | 2545 | |
2559 | 2546 | //マップに対して当たり判定を実行 |
2560 | 2547 | if( CollD->CheckALLBlockIntersectRay(pos_x, pos_y, pos_z, move_x/maxDist, move_y/maxDist, move_z/maxDist, &id, &face, &Dist, maxDist) == true ){ |
2548 | + //衝突している場合〜 | |
2549 | + | |
2550 | + float Angle, Acceleration; | |
2561 | 2551 | float vx, vy, vz; |
2562 | 2552 | |
2563 | - //マップと衝突する座標まで移動 | |
2564 | - pos_x += move_x/maxDist * (Dist - 0.1f); | |
2565 | - pos_y += move_y/maxDist * (Dist - 0.1f); | |
2566 | - pos_z += move_z/maxDist * (Dist - 0.1f); | |
2553 | + //角度を求める | |
2554 | + CollD->AngleVector(id, face, move_x, move_y, move_z, &Angle); | |
2567 | 2555 | |
2568 | 2556 | //反射するベクトルを求める |
2569 | 2557 | CollD->ReflectVector(id, face, move_x, move_y, move_z, &vx, &vy, &vz); |
2570 | 2558 | |
2571 | - //減速 | |
2572 | - move_x = vx * GRENADE_BOUND_ACCELERATION; | |
2573 | - move_y = vy * GRENADE_BOUND_ACCELERATION; | |
2574 | - move_z = vz * GRENADE_BOUND_ACCELERATION; | |
2559 | + //減速率を求める | |
2560 | + Acceleration = Angle*-1 * 0.2546f + 0.7f; | |
2575 | 2561 | |
2562 | + //反射 and 減速 | |
2563 | + move_x = vx * Acceleration; | |
2564 | + move_y = vy * Acceleration; | |
2565 | + move_z = vz * Acceleration; | |
2566 | + | |
2567 | + // ※衝突した瞬間(フレーム)は、移動しない。 | |
2568 | + | |
2569 | + //移動速度を計算 | |
2570 | + move_x *= 0.98f; | |
2571 | + move_y = (move_y - 0.17f) * 0.98f; | |
2572 | + move_z *= 0.98f; | |
2573 | + | |
2576 | 2574 | cnt += 1; |
2577 | 2575 | return 1; |
2578 | 2576 | } |
@@ -2582,6 +2580,11 @@ | ||
2582 | 2580 | pos_y += move_y; |
2583 | 2581 | pos_z += move_z; |
2584 | 2582 | |
2583 | + //移動速度を計算 | |
2584 | + move_x *= 0.98f; | |
2585 | + move_y = (move_y - 0.17f) * 0.98f; | |
2586 | + move_z *= 0.98f; | |
2587 | + | |
2585 | 2588 | cnt += 1; |
2586 | 2589 | return 0; |
2587 | 2590 | } |
@@ -82,7 +82,6 @@ | ||
82 | 82 | #define BULLET_SPEEDSCALE 3 //!< 弾速の倍率 |
83 | 83 | #define BULLET_DESTROYFRAME 40 //!< 弾の消滅フレーム数 |
84 | 84 | #define GRENADE_DESTROYFRAME 100 //!< 手榴弾の爆発フレーム数 |
85 | -#define GRENADE_BOUND_ACCELERATION 0.565f //!< 手榴弾の反射減衰率 | |
86 | 85 | |
87 | 86 | #ifndef H_LAYERLEVEL |
88 | 87 | #define H_LAYERLEVEL 2 //!< Select include file. |
@@ -231,7 +231,7 @@ | ||
231 | 231 | //OSのバージョン取得 |
232 | 232 | OSVERSIONINFO OSver; |
233 | 233 | OSver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
234 | - GetVersionEx(&OSver); | |
234 | + GetVersionEx(&OSver); | |
235 | 235 | |
236 | 236 | //OSビット数取得 |
237 | 237 | SYSTEM_INFO SystemInfo = {0}; |