• R/O
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得windowscocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

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


Commit MetaInfo

Revision295 (tree)
Zeit2022-03-20 22:50:57
Autorxops-mikan

Log Message

角度(ラジアン)の正規化処理を関数化

Ändern Zusammenfassung

Diff

--- trunk/ai.cpp (revision 294)
+++ trunk/ai.cpp (revision 295)
@@ -400,8 +400,7 @@
400400
401401 //方向を計算
402402 tr = FaceCaution_rx - rx;
403- for(; tr > (float)M_PI; tr -= (float)M_PI*2){}
404- for(; tr < (float)M_PI*-1; tr += (float)M_PI*2){}
403+ tr = AngleNormalization(tr);
405404
406405 //旋回
407406 if( tr > DegreeToRadian(2.5f) ){
@@ -447,8 +446,7 @@
447446 if( GetRand(80) == 0 ){
448447 float tr;
449448 tr = target_rx - rx;
450- for(; tr > (float)M_PI; tr -= (float)M_PI*2){}
451- for(; tr < (float)M_PI*-1; tr += (float)M_PI*2){}
449+ tr = AngleNormalization(tr);
452450
453451 if( tr > 0.0f ){
454452 ObjDriver->SetModeFlag(AI_CTRL_TURNRIGHT);
@@ -478,8 +476,7 @@
478476 MoveNavi->GetTargetPos(NULL, NULL, &target_rx, NULL, NULL);
479477
480478 tr = target_rx - rx;
481- for(; tr > (float)M_PI; tr -= (float)M_PI*2){}
482- for(; tr < (float)M_PI*-1; tr += (float)M_PI*2){}
479+ tr = AngleNormalization(tr);
483480
484481 ObjDriver->DelModeFlag(AI_CTRL_TURNRIGHT);
485482 ObjDriver->DelModeFlag(AI_CTRL_TURNLEFT);
--- trunk/collision.cpp (revision 294)
+++ trunk/collision.cpp (revision 295)
@@ -1609,8 +1609,7 @@
16091609
16101610 if( out_rx != NULL ){
16111611 angleX = atan2f(z, x) - rx;
1612- for(; angleX > (float)M_PI; angleX -= (float)M_PI*2){}
1613- for(; angleX < (float)M_PI*-1; angleX += (float)M_PI*2){}
1612+ angleX = AngleNormalization(angleX);
16141613
16151614 *out_rx = angleX;
16161615 }
--- trunk/gamemain.cpp (revision 294)
+++ trunk/gamemain.cpp (revision 295)
@@ -2589,8 +2589,7 @@
25892589 float camera_ry2 = camera_ry;
25902590
25912591 //camera_ry2を -PI〜PI の間に正規化
2592- for(; camera_ry2>(float)M_PI; camera_ry2 -= (float)M_PI*2){}
2593- for(; camera_ry2<(float)M_PI*-1; camera_ry2 += (float)M_PI*2){}
2592+ camera_ry2 = AngleNormalization(camera_ry2);
25942593
25952594 float ry = camera_ry2*0.95f + DegreeToRadian(-89.0f)*0.05f; // 19/20 + 1/20
25962595 float r = 3.12f;
--- trunk/main.cpp (revision 294)
+++ trunk/main.cpp (revision 295)
@@ -264,4 +264,15 @@
264264 OutputLog.WriteLog(LOG_CHECK, "Exit", "Exit program entry point");
265265 #endif
266266 return 0;
267+}
268+
269+//! @brief 角度(ラジアン)正規化
270+//! @param r 角度
271+//! @return 正規化後の角度
272+//! @note -PI〜PI の間に正規化します。
273+float AngleNormalization(float r)
274+{
275+ for(; r > (float)M_PI; r -= (float)M_PI*2){}
276+ for(; r < (float)M_PI*-1; r += (float)M_PI*2){}
277+ return r;
267278 }
\ No newline at end of file
--- trunk/main.h (revision 294)
+++ trunk/main.h (revision 295)
@@ -156,4 +156,6 @@
156156 extern class StateMachine GameState;
157157 extern class Config GameConfig;
158158
159+float AngleNormalization(float r);
160+
159161 #endif
\ No newline at end of file
--- trunk/object.cpp (revision 294)
+++ trunk/object.cpp (revision 295)
@@ -1129,8 +1129,7 @@
11291129
11301130 //最後に攻撃を受けた方向を計算
11311131 tr = Hit_rx - rotation_x;
1132- for(; tr > (float)M_PI; tr -= (float)M_PI*2){}
1133- for(; tr < (float)M_PI*-1; tr += (float)M_PI*2){}
1132+ tr = AngleNormalization(tr);
11341133
11351134 //体の角度
11361135 if( ((float)M_PI/2*-1 < tr)&&(tr < (float)M_PI/2) ){
@@ -1336,8 +1335,7 @@
13361335
13371336 //最後に攻撃を受けた方向を計算
13381337 tr = Hit_rx - rotation_x;
1339- for(; tr > (float)M_PI; tr -= (float)M_PI*2){}
1340- for(; tr < (float)M_PI*-1; tr += (float)M_PI*2){}
1338+ tr = AngleNormalization(tr);
13411339
13421340 //体の角度
13431341 if( ((float)M_PI/2*-1 < tr)&&(tr < (float)M_PI/2) ){
@@ -3220,8 +3218,7 @@
32203218 else{
32213219 move_rx2 = move_rx;
32223220 }
3223- for(; move_rx2 > (float)M_PI; move_rx2 -= (float)M_PI*2){}
3224- for(; move_rx2 < (float)M_PI*-1; move_rx2 += (float)M_PI*2){}
3221+ move_rx2 = AngleNormalization(move_rx2);
32253222
32263223 //徐々にその向きに
32273224 legrotation_x = legrotation_x*0.85f + (rotation_x + move_rx2*-1)*0.15f; // 3/4 + 1/4
--- trunk/sound-ezds.cpp (revision 294)
+++ trunk/sound-ezds.cpp (revision 295)
@@ -255,8 +255,7 @@
255255 float vx = x - camera_x;
256256 float vz = z - camera_z;
257257 float rx = (atan2f(vz, vx) - camera_rx) * -1;
258- for(; rx > (float)M_PI; rx -= (float)M_PI*2){}
259- for(; rx < (float)M_PI*-1; rx += (float)M_PI*2){}
258+ rx = AngleNormalization(rx);
260259 pan = (int)((float)10 / M_PI * rx);
261260 */
262261