summaryrefslogtreecommitdiff
path: root/engine-ocean/Game/Systems/drawsystem.cpp
blob: ad6e17b77373fb4795fc51533766818784787256 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "drawsystem.h"
#include "Game/Components/DrawComponent.h"
#include "Game/Components/TransformComponent.h"

DrawSystem::DrawSystem(std::map<std::string, std::shared_ptr<GameObject>>& gameobjects):
    m_gameobjects(gameobjects)
{


}

void DrawSystem::update(double deltaTime){}
// store all game objects and get draw components, draw

void DrawSystem::draw(){
    Global::graphics.bindShader("phong");
    //std::cout << "IN DRAW SYSTEM" << std::endl;

    for (auto &pair: m_gameobjects){
        if (pair.second->hasComponent<DrawComponent>()){

            DrawComponent *draw_comp = pair.second->getComponent<DrawComponent>();
            TransformComponent *transform_comp = pair.second->getComponent<TransformComponent>();
            if (transform_comp->hasMultipleMT()){
                if (draw_comp->objHasMaterial()){
                    for (const std::shared_ptr<ModelTransform> &mt : transform_comp->getAllMT()){
                        Global::graphics.drawShape(draw_comp->getShape(), mt, draw_comp->getMaterial());
                    }
                } else {
                    for (const std::shared_ptr<ModelTransform> &mt : transform_comp->getAllMT()){
                        Global::graphics.drawShape(draw_comp->getShape(), mt);
                    }
                }
            } else {
                // case: object is seperated by material
                if (draw_comp->objHasMultipleShapes()){
                    for (auto &shape : draw_comp->getShapesWithMaterials()){
                        if (shape->hasMaterial()){
                            Global::graphics.drawShape(shape, transform_comp->getMT(), shape->getShapeMaterial());
                        } else {
                            Global::graphics.drawShape(shape, transform_comp->getMT());
                        }
                    }

                } else {
                    if (draw_comp->objHasMaterial()){
                        Global::graphics.drawShape(draw_comp->getShape(), transform_comp->getMT(), draw_comp->getMaterial());
                    } else {
                        //std::cout << "draw shape: " << pair.first << std::endl;
                        Global::graphics.drawShape(draw_comp->getShape(), transform_comp->getMT());
                    }
                }
            }
        }
    }

}

void DrawSystem::scrollEvent(double distance){}
void DrawSystem::mousePosEvent(double xpos, double ypos){}