summaryrefslogtreecommitdiff
path: root/themes/src/winter/Windfield.cpp
blob: 88fb74b424d33c77bbd4bfded1fa1049a1232f32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "Windfield.hpp"

    
template <i32 Width, i32 Height, i32 CellDimension>
void WindField<Width, Height, CellDimension>::load(f32 cellSizePixels, i32 fieldWithCells, i32 fieldHeightCells, f32 ttl, Vector2 origin) {
    this->ttl = ttl;
    this->origin = origin;
    this->end = this->origin + Vector2(Width * CellDimension, Height * CellDimension);
}

template <i32 Width, i32 Height, i32 CellDimension>
bool WindField<Width, Height, CellDimension>::addVector(i32 x, i32 y, Vector2& v) {
    field[x][y] = v;
    return false;
}

template <i32 Width, i32 Height, i32 CellDimension>
Vector2 WindField<Width, Height, CellDimension>::getWindFactor(Vector2& v) {
    if (v.x >= origin.x && v.x <= end.x
        && v.y >= origin.y && v.y <= end.y) {
        Vector2 positionInField = v - this->origin;
        i32 cellX = static_cast<i32>(Width / positionInField.x);
        i32 cellY = static_cast<i32>(Height / positionInField.y);
        return field[cellX][cellY];
    }
    
    return Vector2();
}