I have a character and want to check if there is a certain model is in front of the character (cone visibility check)
I'm not sure how do I get cosMaxAngle, I think it has something to do with field of view, if so how do I get the character field of view? (I have the character transformation matrix)
BOOL CheckVisibility()
{
D3DXVECTOR3 view = target->GetPosition() - character->GetPosition();
float distance = GetDistance(character->Position(), target->Position());
if(distance > 100.0f)
return false; //not visible, too far
D3DXVec3Normalize(&view, &view); //view = normalize(view);
D3DXVECTOR3 enemyLookDir;
D3DXMATRIX ZUnitVec;
D3DXMATRIX matRot;
D3DXMatrixTranslation(&ZUnitVec, 0.0f, 0.0f, 1.0f); // matrix holding position of vector pointing to positive z
D3DXMatrixRotationYawPitchRoll(&matRot, D3DXToRadian(character->rotationX), D3DXToRadian(character->rotationY), D3DXToRadian(character->rotationZ));
D3DXMATRIX m = ZUnitVec * matRot;
enemyLookDir = D3DXVECTOR3(m._41,m._42,m._43); // Get vector from the matrix
D3DXVec3Normalize(&enemyLookDir, &enemyLookDir);
// Cosine of the angle between the view vector and the direction the enemy is looking
float cosAngle = D3DXVec3Dot(&enemyLookDir, &view);
float cosMaxAngle = ??? // I think I should use the field of view here? how? I want the character vision cone to be limited to 90 degrees
// Check if player is inside the cone
if(cosAngle < cosMaxAngle)
return false; // Not visible
return true; // Visible
}