How to make a 3D representation of a 2D matrix with a z value on each element

I am working on the 42 school project FdF that is a computer graphics related project that uses an API for the Xlib named minilibx (linked below if you want to check out) and need to make a 3D representation of a map given as an input. The map is given as a 2D matrix and each value is its height.
After we manage to update the scale of our map, center it on the created window and display the result of our projection in isometric view we can implement some other features like adding rotation.

My problem with this feature is that when I rotate on the x or y axis 90 degrees the image seems to flip as if my “camera” was following it on the other side instead of getting the down view of the map.

I leave bellow the code and some links that might help
The project repo if you want to see some other functions : https://github.com/Artur-2k/FdF-42
To install dependencies: (Linux) sudo apt-get install gcc make xorg libxext-dev libbsd-dev -y
Minilibx: https://github.com/42Paris/minilibx-linux
Good base-level understanding of minilibx: https://harm-smits.github.io/42docs/libs/minilibx

#include "fdf.h"

void    rotate_x(t_data *data, double alpha)
{
    int tmp_y;
    int i;
    int j;
    double cos_alpha;
    double sin_alpha;

    sin_alpha = sin(alpha);
    cos_alpha = cos(alpha);
    i = 0;
    while (i < data->rows)
    {
        j = 0;
        while (j < data->cols)
        {
            tmp_y = data->matrix[i][j].proj_y;
            data->matrix[i][j].proj_y = (int)(tmp_y * cos_alpha - data->matrix[i][j].proj_z * sin_alpha);
            data->matrix[i][j].proj_z = (int)(tmp_y * sin_alpha + data->matrix[i][j].proj_z * cos_alpha);
            j++;
        }
        i++;
    }
}

void    rotate_y(t_data *data, double beta)
{
    int tmp_x;
    int i;
    int j;
    double cos_beta;
    double sin_beta;

    sin_beta = sin(beta);
    cos_beta = cos(beta);
    i = 0;
    while (i < data->rows)
    {
        j = 0;
        while (j < data->cols)
        {
            tmp_x = data->matrix[i][j].proj_x;
            data->matrix[i][j].proj_x = (int)(tmp_x * cos_beta  + data->matrix[i][j].proj_z * sin_beta);
            data->matrix[i][j].proj_z = (int)(-tmp_x * sin_beta + data->matrix[i][j].proj_z * cos_beta);
            j++;
        }
        i++;
    }
}

void    rotate_z(t_data *data, double gama)
{
    int tmp_x;
    int i;
    int j;
    double cos_gama;
    double sin_gama;

    sin_gama = sin(gama);
    cos_gama = cos(gama);
    i = 0;
    while (i < data->rows)
    {
        j = 0;
        while (j < data->cols)
        {
            tmp_x = data->matrix[i][j].proj_x;
            data->matrix[i][j].proj_x = (int)(tmp_x * cos_gama - data->matrix[i][j].proj_y * sin_gama);
            data->matrix[i][j].proj_y = (int)(tmp_x * sin_gama + data->matrix[i][j].proj_y * cos_gama);
            j++;
        }
        i++;
    }
}

void    manual_rotate(t_data *data, int key)
{
    // each respective key press changes the angle accordingly
    if (key == XK_w)
        data->alpha +=  ANGLE_CHANGE;
    else if (key == XK_s)
        data->alpha -=  ANGLE_CHANGE;
    else if (key == XK_d)
        data->beta +=  ANGLE_CHANGE;
    else if (key == XK_a)
        data->beta -=  ANGLE_CHANGE;
    else if (key == XK_q)
        data->gama +=  ANGLE_CHANGE;
    else if (key == XK_e)
        data->gama -=  ANGLE_CHANGE;


    reset_projections_set_zoom(data); // resets xyz_proj to xyz and applies scale
    // re-rotate
        /*
        #define DEG_TO_RAD(deg) (deg * M_PI / 180)
        #define NORMALIZE_ANGLE(angle) (fmod(angle, 360.0))
        */
    rotate_x(data,DEG_TO_RAD (NORMALIZE_ANGLE(data->alpha)));
    rotate_y(data,DEG_TO_RAD (NORMALIZE_ANGLE(data->beta)));
    rotate_z(data,DEG_TO_RAD (NORMALIZE_ANGLE(data->gama)));

    // update offsets
    get_bounderies(data); // makes it rotate on itself on not on the 0.0
    get_offsets(data); //center the map with the same offsets

    //* shitft the object offset + translation(if added any)
    translate(data, data->xoffset + data->xtranslate, data->yoffset + data->ytranslate);

    //* updates the image (could just 0 the memory of the image instead too)
    update_img(data);
}

New contributor

Artur Carvalho is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật