~zanneth/zge

e6f18c8efc71f2c7e36984b440d6cea501346a05 — Charles Magahern 1 year, 10 months ago 7614ce8 master
Fix build errors with modern compilers
M CMakeLists.txt => CMakeLists.txt +4 -0
@@ 35,6 35,10 @@ target_include_directories(zge
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src
)

# OpenGL
find_package(OpenGL REQUIRED)
target_link_libraries(zge ${OPENGL_LIBRARY})

# GLEW
find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIRS})

M src/zge/contrib/camera_controller.cpp => src/zge/contrib/camera_controller.cpp +8 -8
@@ 41,25 41,25 @@ void ZCameraController::_receive_event(const ZEvent &event)
        
        switch (key_event.key) {
            case ZKEY_UP:
                pos_delta = { 0.0, 1.0, 0.0 };
                pos_delta = {{ 0.0, 1.0, 0.0 }};
                break;
            case ZKEY_DOWN:
                pos_delta = { 0.0, -1.0, 0.0 };
                pos_delta = {{ 0.0, -1.0, 0.0 }};
                break;
            case ZKEY_LEFT:
                pos_delta = { -1.0, 0.0, 0.0 };
                pos_delta = {{ -1.0, 0.0, 0.0 }};
                break;
            case ZKEY_RIGHT:
                pos_delta = { 1.0, 0.0, 0.0 };
                pos_delta = {{ 1.0, 0.0, 0.0 }};
                break;
            case ZKEY_PLUS:
            case ZKEY_EQUALS:
                pos_delta = { 0.0, 0.0, -1.0 };
                look_delta = { 0.0, 0.0, -1.0 };
                pos_delta = {{ 0.0, 0.0, -1.0 }};
                look_delta = {{ 0.0, 0.0, -1.0 }};
                break;
            case ZKEY_MINUS:
                pos_delta = { 0.0, 0.0, 1.0 };
                look_delta = { 0.0, 0.0, 1.0 };
                pos_delta = {{ 0.0, 0.0, 1.0 }};
                look_delta = {{ 0.0, 0.0, 1.0 }};
                break;
            default:
                break;

M src/zge/math/matrix.cpp => src/zge/math/matrix.cpp +8 -8
@@ 178,7 178,7 @@ ZMatrix ZMatrix::rotation(float radians, float x, float y, float z)
    float cosp = 1.0f - cos;
    float sin = sinf(radians);
    
    ZMatrix m = {
    ZMatrix m = {{
        cos + cosp * v[0] * v[0],
        cosp * v[0] * v[1] + v[2] * sin,
        cosp * v[0] * v[2] - v[1] * sin,


@@ 195,7 195,7 @@ ZMatrix ZMatrix::rotation(float radians, float x, float y, float z)
        0.0f,
        0.0f,
        1.0f
    };
    }};
    
    return m;
}


@@ 209,12 209,12 @@ ZMatrix ZMatrix::frustum(float left, float right, float bottom, float top, float
    float fan = farZ + nearZ;
    float fsn = farZ - nearZ;
    
    ZMatrix mat = {
    ZMatrix mat = {{
        2.0f * nearZ / rsl, 0.0f, 0.0f, 0.0f,
        0.0f, 2.0f * nearZ / tsb, 0.0f, 0.0f,
        ral / rsl, tab / tsb, -fan / fsn, -1.0f,
        0.0f, 0.0f, (-2.0f * farZ * nearZ) / fsn, 0.0f
    };
    }};
    return mat;
}



@@ 232,12 232,12 @@ ZMatrix ZMatrix::lookat(const ZVector &eye, const ZVector &center, const ZVector
    ZVector u = (up.cross(n)).normalized();
    ZVector v = n.cross(u);
    
    ZMatrix mat = {
    ZMatrix mat = {{
        u[0], v[0], n[0], 0.0f,
        u[1], v[1], n[1], 0.0f,
        u[2], v[2], n[2], 0.0f,
        -u.dot(eye), -v.dot(eye), -n.dot(eye), 1.0f
    };
    }};
    return mat;
}



@@ 250,12 250,12 @@ ZMatrix ZMatrix::ortho(float left, float right, float bottom, float top, float n
    float fan = farZ + nearZ;
    float fsn = farZ - nearZ;
    
    ZMatrix mat = {
    ZMatrix mat = {{
        2.0f / rsl, 0.0f, 0.0f, 0.0f,
        0.0f, 2.0f / tsb, 0.0f, 0.0f,
        0.0f, 0.0f, -2.0f / fsn, 0.0f,
        -ral / rsl, -tab / tsb, -fan / fsn, 1.0f
    };
    }};
    return mat;
}


M src/zge/math/vector.cpp => src/zge/math/vector.cpp +5 -5
@@ 160,17 160,17 @@ ZVector ZVector::operator-() const

ZVector ZVector::unit_x()
{
    return { 1.0, 0.0, 0.0 };
    return {{ 1.0, 0.0, 0.0 }};
}

ZVector ZVector::unit_y()
{
    return { 0.0, 1.0, 0.0 };
    return {{ 0.0, 1.0, 0.0 }};
}

ZVector ZVector::unit_z()
{
    return { 0.0, 0.0, 1.0 };
    return {{ 0.0, 0.0, 1.0 }};
}

const float* ZVector::get_data() const


@@ 199,11 199,11 @@ ZVector ZVector::normalized() const

ZVector ZVector::integral() const
{
    ZVector integral = {
    ZVector integral = {{
        std::rint(get_x()),
        std::rint(get_y()),
        std::rint(get_z())
    };
    }};
    return integral;
}


M src/zge/text/text_node.cpp => src/zge/text/text_node.cpp +1 -1
@@ 239,7 239,7 @@ void ZTextNode::_render_glyphs(bool force)
        }
        
        // compute glyph position
        ZVector position = {last_glyph_max_x + glyph.insets.left, line_height - glyph.insets.top + offset_y};
        ZVector position = {{last_glyph_max_x + glyph.insets.left, line_height - glyph.insets.top + offset_y}};
        last_glyph_max_x = position.x() + glyph.advance.width;
        glyph_node->set_position(position);
        

M test/src/fps_node.cpp => test/src/fps_node.cpp +2 -2
@@ 24,10 24,10 @@ FPSNode::FPSNode(zge::ZEngineRef engine) :
    
    zge::ZRect viewport = _engine->get_viewport_rect();
    zge::ZRect text_node_bounds = _text_node->get_bounds();
    _text_node->set_position({
    _text_node->set_position({{
        viewport.size.width - text_node_bounds.size.width - 20.0f,
        viewport.size.height - text_node_bounds.size.height - 20.0f
    });
    }});
    
    zge::ZOrthoCameraRef camera = zge::ZOrthoCamera::create();
    camera->set_clipping_rect({0.0, 0.0, viewport.size.width, viewport.size.height});

M test/src/line_scene.cpp => test/src/line_scene.cpp +1 -1
@@ 25,7 25,7 @@ LineScene::LineScene(const ZRect &rect) :
    float half_viewport_ht = _viewport.size.height / 2.0;
    for (unsigned i = 0; i < points_to_draw; ++i) {
        float yval = half_viewport_ht + (std::sin(float(i) / 20.0) * half_viewport_ht);
        points.push_back({float(i), yval, 0.0});
        points.push_back({{float(i), yval, 0.0}});
    }
    
    ZLineRef line = ZLine::create(points);

M test/src/multiscene.cpp => test/src/multiscene.cpp +3 -3
@@ 107,7 107,7 @@ void Multiscene::_setup_picker_panel()
    
    for (ZSceneRef scene : _scenes) {
        PickerCellRef cell = std::make_shared<PickerCell>(scene, font);
        cell->set_position({0.0, cur_y});
        cell->set_position({{0.0, cur_y}});
        cell->set_size({picker->get_size().width, cellheight});
        cell->layout();
        


@@ 158,10 158,10 @@ PickerCell::PickerCell(ZSceneRef scene, ZFontRef font) :
void PickerCell::layout()
{
    ZSize2D size = get_size();
    _textnode->set_position(ZVector{
    _textnode->set_position({{
        5.0,
        std::rintf(size.height / 2.0 - _textnode->get_bounds().size.height / 1.2)
    });
    }});
}

void PickerCell::set_selected(bool selected)

M test/src/node_storm.cpp => test/src/node_storm.cpp +3 -3
@@ 50,7 50,7 @@ NodeStormScene::NodeStormScene(const ZRect &viewport) :
        MovingNodeRef node = MovingNode::create(velocity);
        node->set_color(ZColor::random_color());
        node->set_size({NODE_DIMENSIONS, NODE_DIMENSIONS});
        node->set_position({x_dist(rd), y_dist(rd)});
        node->set_position({{x_dist(rd), y_dist(rd)}});
        nodes.push_back(node);
        add_child(node);
    }


@@ 69,11 69,11 @@ void NodeStormScene::update()
        pos += velocity;
        
        if (pos.x() + size.width > _viewport.size.width || pos.x() < 0.0) {
            node->set_velocity({-velocity.get_x(), velocity.get_y(), 0.0});
            node->set_velocity({{-velocity.get_x(), velocity.get_y(), 0.0}});
        }
        
        if (pos.y() + size.height > _viewport.size.height || pos.y() < 0.0) {
            node->set_velocity({velocity.get_x(), -velocity.get_y(), 0.0});
            node->set_velocity({{velocity.get_x(), -velocity.get_y(), 0.0}});
        }
        
        node->set_position(pos);

M test/src/persp_cube_scene.cpp => test/src/persp_cube_scene.cpp +6 -6
@@ 19,15 19,15 @@ PerspectiveCubeScene::PerspectiveCubeScene(const ZRect &viewport) :
    
    // setup camera
    Z3DCameraRef camera = Z3DCameraRef(new Z3DCamera);
    camera->set_position({0.0, 0.0, 5.0});
    camera->set_look({0.0, 0.0, -999.0});
    camera->set_position({{0.0, 0.0, 5.0}});
    camera->set_look({{0.0, 0.0, -999.0}});
    camera->set_viewport_rect(_viewport);
    set_camera(camera);
    
    // add a model
    _cube1 = ZNode::create(ZCube::create());
    _cube1->set_name("cube 1");
    _cube1->set_position({-2.0, 0.0, 0.0});
    _cube1->set_position({{-2.0, 0.0, 0.0}});
    add_child(_cube1);
    
    _cube1_material = ZColorMaterialRef(new ZColorMaterial);


@@ 38,7 38,7 @@ PerspectiveCubeScene::PerspectiveCubeScene(const ZRect &viewport) :
    ZCubeRef cube_geom = ZCube::create();
    _cube2 = ZNode::create(cube_geom);
    _cube2->set_name("cube 2");
    _cube2->set_position({2.0, 0.0, 0.0});
    _cube2->set_position({{2.0, 0.0, 0.0}});
    add_child(_cube2);
    
    ZColorMaterialRef cube2_material = ZColorMaterialRef(new ZColorMaterial);


@@ 47,7 47,7 @@ PerspectiveCubeScene::PerspectiveCubeScene(const ZRect &viewport) :
    
    ZLightRef light = ZLight::create();
    light->set_color(ZColor::white);
    light->set_position({0.0, 0.0, 0.0});
    light->set_position({{0.0, 0.0, 0.0}});
    add_child(light);
}



@@ 66,7 66,7 @@ void PerspectiveCubeScene::handle_input_event(const ZEvent &event)
        tx = mouse_event.location.x - midx;
        ty = mouse_event.location.y - midy;
        
        ZVector look = {tx / midx, -ty / midy, -pos.z()};
        ZVector look = {{tx / midx, -ty / midy, -pos.z()}};
        Z3DCameraRef camera = std::dynamic_pointer_cast<Z3DCamera>(get_camera());
        camera->set_look(look);
    } else if (event.type == ZKEY_DOWN_EVENT) {

M test/src/rot_cube_scene.cpp => test/src/rot_cube_scene.cpp +5 -5
@@ 18,18 18,18 @@ RotatingCubeScene::RotatingCubeScene(const ZRect &viewport) :
    set_name("Rotating Cube");
    
    Z3DCameraRef camera = Z3DCameraRef(new Z3DCamera);
    camera->set_position({0.0, 0.0, 5.0});
    camera->set_look({0.0, 0.0, 0.0});
    camera->set_position({{0.0, 0.0, 5.0}});
    camera->set_look({{0.0, 0.0, 0.0}});
    camera->set_viewport_rect(_viewport);
    set_camera(camera);
    
    ZNodeRef cube = ZNode::create(ZCube::create());
    cube->get_geometry()->add_material(ZColorMaterial::create(ZColor::white));
    cube->set_position({0.0, 0.0, -10.0});
    cube->set_position({{0.0, 0.0, -10.0}});
    add_child(cube);
    
    ZLightRef light = std::make_shared<ZLight>(ZLIGHT_TYPE_POINT);
    light->set_position({-5.0, 0.0, 0.0});
    light->set_position({{-5.0, 0.0, 0.0}});
    light->set_color(ZColor::white);
    add_child(light);
    


@@ 37,7 37,7 @@ RotatingCubeScene::RotatingCubeScene(const ZRect &viewport) :
    ambient_light->set_color(ZColor(1.0, 1.0, 1.0, 0.2));
    add_child(ambient_light);
    
    ZRotationActionRef rotation = ZRotationAction::create(2.0 * M_PI, ZVector{1.0, 0.75, 0.5});
    ZRotationActionRef rotation = ZRotationAction::create(2.0 * M_PI, ZVector{{1.0, 0.75, 0.5}});
    rotation->set_repeat_count(ZAction::repeat_count_infinity);
    rotation->set_duration(ZTimeInterval(10.0));
    cube->add_action(rotation);

M test/src/text_scene.cpp => test/src/text_scene.cpp +2 -2
@@ 22,10 22,10 @@ TextScene::TextScene(const ZRect &viewport) :
    
    ZSpriteNodeRef square = ZSpriteNode::create();
    square->set_size(ZSize2D{100.0, 100.0});
    square->set_position({100.0, 250.0});
    square->set_position({{100.0, 250.0}});
    _scene->add_child(square);
    
    ZTextNodeRef text_node = ZTextNode::create("cool square!", Monaco::create(64));
    text_node->set_position({100.0, 100.0});
    text_node->set_position({{100.0, 100.0}});
    _scene->add_child(text_node);
}