2016-04-19 13 views
0

この小さなコードで、私はアバターに向かって「モンスター」を回転させることができましたが、アバターが「モンスター」はアバターから離れています。 (PICの下)2点間を回転して立って立っているときの向きを逆にして(写真)

注:

if (diff.x < 0) 
{ 
    m_RotationAngle = -atan(diff.y/diff.x); 
    //also tried following but gave and error: 
    //m_RotationAngle = tan(diff.y/diff.x); 
} 
else 
{ 
    m_RotationAngle = atan(diff.y/diff.x); 
} 

しかし、これは与えた:白い数字は、私はそれを修正しようとしたm_RotationAngle

DOUBLE2 mousePos = GAME_ENGINE->GetMousePosition(); 

double xDiff = m_ActPtr->GetPosition().x - mousePos.x; 
double yDiff = m_ActPtr->GetPosition().y - mousePos.y; 
m_RotationAngle = atan(yDiff, xDiff); 
m_ActPtr->SetAngle(m_RotationAngle); 

Avatar standing behind monstersAvatar standing infront of monsters

の値です次の出力:

enter image description here

答えて

1

あなたは、おそらく(これも一つのパラメータのみを必要とする)正しい象限を決定するための引数の符号を使用してyDiff /あるXdiffのアークタンジェントを計算atan2(yDiff, xDiff);、代わりのatanを探しています。

結果が[-π; +π]ラジアン、度ではありません。

関連する問題