Fixed GL math

I did almost every matrix operation backwards...
This commit is contained in:
Thomas Muller 2021-08-07 02:02:44 -04:00
parent 25e266d430
commit 9633b155bd
Signed by: thomas
GPG key ID: AF006EB730564952

View file

@ -50,10 +50,10 @@ void Render::fill_rectangle_sz(Vector2<int> size, Color color) {
}
void Render::draw_lines(std::vector<Vector2<float>> points, Color color) {
auto prev_cache = m_matrix * m_view_matrix * Vector3<float>(points[0], 1);
auto prev_cache = m_view_matrix * m_matrix * Vector3<float>(points[0], 1);
for(size_t i = 1; i < points.size(); i++) {
auto start = prev_cache;
auto end = m_matrix * m_view_matrix * Vector3<float>(points[i], 1);
auto end = m_view_matrix * m_matrix * Vector3<float>(points[i], 1);
m_pge->DrawLine(
start.x(),
@ -118,10 +118,10 @@ void Render::pop_matrix() {
void Render::translate(Vector2<float> trans) {
switch(m_matrix_mode) {
case MODEL:
m_matrix = translation_matrix(trans) * m_matrix;
m_matrix *= translation_matrix(trans);
break;
case PROJECTION:
m_view_matrix = translation_matrix(trans) * m_view_matrix;
m_view_matrix *= translation_matrix(trans);
break;
}
}
@ -129,10 +129,10 @@ void Render::translate(Vector2<float> trans) {
void Render::rotate(float theta) {
switch(m_matrix_mode) {
case MODEL:
m_matrix = rotation_matrix(theta) * m_matrix;
m_matrix *= rotation_matrix(theta);
break;
case PROJECTION:
m_view_matrix = rotation_matrix(theta) * m_view_matrix;
m_view_matrix *= rotation_matrix(theta);
break;
}
}
@ -140,10 +140,10 @@ void Render::rotate(float theta) {
void Render::scale(Vector2<float> scale) {
switch(m_matrix_mode) {
case MODEL:
m_matrix = scale_matrix(scale) * m_matrix;
m_matrix *= scale_matrix(scale);
break;
case PROJECTION:
m_view_matrix = scale_matrix(scale) * m_view_matrix;
m_view_matrix *= scale_matrix(scale);
}
}