16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-17 23:39:18 +02:00

Use the sq function to force constexpr expressions for numeric literals and enhance readability

This commit is contained in:
docentYT
2026-04-28 13:23:14 +02:00
parent 6be1b0886d
commit ca839652bf
15 changed files with 64 additions and 59 deletions

View File

@@ -97,7 +97,7 @@ void TAnimContainer::UpdateModel() {
{
auto dif = vTranslateTo - vTranslation; // wektor w kierunku docelowym
double l2 = glm::length2(dif); // długość wektora potrzebnego przemieszczenia
if (l2 >= 0.0001)
if (l2 >= sq(0.01))
{ // jeśli do przemieszczenia jest ponad 1cm
auto s = glm::normalize(dif); // jednostkowy wektor kierunku // Długość wektora nie jest równa 0, sprawdzane wcześniej więc wektor normalny będzie zawsze prawidłowy.
s = s *
@@ -113,7 +113,7 @@ void TAnimContainer::UpdateModel() {
{ // koniec animowania
vTranslation = vTranslateTo;
fTranslateSpeed = 0.0; // wyłączenie przeliczania wektora
if (glm::length2(vTranslation) <= 0.0001) // jeśli jest w punkcie początkowym
if (glm::length2(vTranslation) <= sq(0.01)) // jeśli jest w punkcie początkowym
iAnim &= ~2; // wyłączyć zmianę pozycji submodelu
if( evDone ) {
// wykonanie eventu informującego o zakończeniu

View File

@@ -631,8 +631,8 @@ std::pair<int, int> TSubModel::Load(cParser &parser, bool dynamic)
{
// jeśli pierwszy trójkąt będzie zdegenerowany, to zostanie usunięty i nie ma co sprawdzać
// length2 is better than length for comparing because it does not require sqrt function
if ((glm::length2((vertex)->position - (vertex - 1)->position) > 1000.0 * 1000.0) || (glm::length2((vertex - 1)->position - (vertex - 2)->position) > 1000.0 * 1000.0) ||
(glm::length2((vertex - 2)->position - (vertex)->position) > 1000.0 * 1000.0))
if ((glm::length2((vertex)->position - (vertex - 1)->position) > sq(1000.0)) || (glm::length2((vertex - 1)->position - (vertex - 2)->position) > sq(1000.0)) ||
(glm::length2((vertex - 2)->position - (vertex)->position) > sq(1000.0)))
{
// jeżeli są dalej niż 2km od siebie //Ra 15-01:
// obiekt wstawiany nie powinien być większy niż 300m (trójkąty terenu w E3D mogą mieć 1.5km)