OSDN Git Service

ちょっと整理。
[gvonavish/GVONavish.git] / GVONavish / GVONavish / GVOShip.cpp
1 #include "stdafx.h"
2 #include "GVOShip.h"
3 #include <string>
4
5
6
7
8
9 void GVOShip::updateWithSurveyCoord( const POINT& surveyCoord)
10 {
11         const GVOVector v( m_surveyCoord, surveyCoord );
12         const double velocity = v.length();
13
14         // \88Ú\93®\82µ\82Ä\82È\82¯\82ê\82Î\96³\8e\8b\82·\82é\81B
15         if ( velocity == 0.0 ) {
16                 return;
17         }
18 #ifndef NDEBUG
19         char buf[4096];
20         sprintf( buf, "velocity:%f\n", v.length() );
21         OutputDebugStringA( buf );
22 #endif
23
24         // 90\93x\82ð\92´\82¦\82½\82ç\8eQ\8dl\82É\82È\82ç\82È\82¢\97\9a\97ð\82ð\83N\83\8a\83A\82·\82é\81B
25         const double angle = m_vector.angleTo( v );
26         if ( M_PI_2 < ::fabs( angle ) ) {
27                 m_vectorHistory.clear();
28         }
29
30         VectorHistoryItem item;
31         item.m_surveyCoord = surveyCoord;
32         item.m_vector = v;
33         m_vectorHistory.push_back( item );
34
35         m_surveyCoord = surveyCoord;
36
37         updateVector();
38 }
39
40
41 void GVOShip::updateVector()
42 {
43         if ( m_vectorHistory.size() < 2 ) {
44                 if ( m_vectorHistory.empty() ) {
45                         return;
46                 }
47                 m_vector = m_vectorHistory.back().m_vector;
48                 return;
49         }
50
51         // \82Æ\82è\82 \82¦\82¸\93Á\92è\82Ì\8b\97\97£\90i\82ñ\82¾\95ª\82Ì\97\9a\97ð\82ð\8d\87\90¬\82·\82é\81B
52         // \82à\82¿\82ë\82ñ\8c\8b\89Ê\82Í\88À\92è\82µ\82È\82¢\82¯\82Ç\81B
53
54         const double k_lengthThreshold = 30;    // \83Q\81[\83\80\93à\8dÀ\95W\82Å\82Ìè\87\92l
55         GVOVector v;
56         double length = 0;
57
58         for ( VectorHistory::const_reverse_iterator it = m_vectorHistory.rbegin(); it != m_vectorHistory.rend(); ++it ) {
59                 v = GVOVector( v, it->m_vector );
60                 length += it->m_vector.length();
61                 if ( k_lengthThreshold < length ) {
62                         m_vectorHistory.erase( m_vectorHistory.begin(), std::next(it).base() );
63                         break;
64                 }
65         }
66
67         // \90^\93\8c\82©\82ç\82Ì\8ap\93x\82ð\8eæ\93¾
68         double sita = GVOVector( 1, 0 ).angleTo( v );
69
70         // 2\93x\82¸\82Â\82Ì360\93x\95ª\89ð\94\\82É\8aÛ\82ß\82é
71         sita = (sita * 180.0) / M_PI;
72         sita = ::floor( ::round( sita ) * 0.5 ) * 2.0;
73
74 #ifndef NDEBUG
75         char buf[4096];
76         sprintf( buf, "%f v:%f\n", sita, v.length() );
77         OutputDebugStringA( buf );
78 #endif
79
80         // \8cÊ\93x\82É\96ß\82·
81         //sita = (sita * M_PI) / 180.0;
82         sita = g_radianFromDegree( sita );
83         // \90¢\8aE\8dÀ\95W\8cn\82Í\8fã\82ª0\82È\82Ì\82ÅY\8e²\82ð\94½\93]\82³\82¹\82é
84         v = GVOVector( ::cos( sita ), -::sin( sita ) );
85         m_vector = v;
86 }