float CSegment::GetPerpDistance(CVector2D p) { CVector2D n = v2 - v1; n.Normalize(); CVector2D c = p - v1; CVector2D v = n * n.Dot(c); v += v1; v -= p; return v.Length(); }
void CClientWeapon::SetDirection ( CVector & vecDirection ) { CVector vecRotation; GetRotationRadians ( vecRotation ); vecRotation.fZ = atan2 ( vecDirection.fY, vecDirection.fX ); CVector2D vecTemp ( vecDirection.fX, vecDirection.fY ); float length = vecTemp.Length (); vecTemp = CVector2D ( length, vecDirection.fZ ); vecTemp.Normalize (); vecRotation.fY = atan2 ( vecTemp.fX, vecTemp.fY )/* - ConvertDegreesToRadians ( 90 )*/; SetRotationRadians ( vecRotation ); }
int CLuaVector2Defs::GetNormalized ( lua_State* luaVM ) { CLuaVector2D* pVector = NULL; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pVector ); if ( !argStream.HasErrors () ) { CVector2D vector ( *pVector ); vector.Normalize (); lua_pushvector ( luaVM, vector ); return 1; } else { m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); } lua_pushboolean ( luaVM, false ); return 1; }