-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplexGraphicObject.cpp
More file actions
60 lines (49 loc) · 1.36 KB
/
ComplexGraphicObject.cpp
File metadata and controls
60 lines (49 loc) · 1.36 KB
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
//
// ComplexGraphicObject.cpp
// Template Project
//
// Created by Jean-Yves Hervé on 2023-10-05.
//
#include <stdio.h>
#include <cmath>
#include <iostream>
#include "glPlatform.h"
#include "ComplexGraphicObject.h"
using namespace std;
using namespace earshooter;
ComplexGraphicObject::ComplexGraphicObject(const WorldPoint& pt, float angle)
: Object(pt, angle),
GraphicObject(pt, angle)
{
}
ComplexGraphicObject::ComplexGraphicObject(float x, float y, float angle)
: Object(x, y, angle),
GraphicObject(x, y, angle)
{
}
void ComplexGraphicObject::addPart(shared_ptr<GraphicObject> part)
{
partList_.push_back(part);
}
void ComplexGraphicObject::draw_() const
{
// save the current coordinate system (origin, axes, scale)
glPushMatrix();
// move to the center of the disk
glTranslatef(getX(), getY(), 0.f);
glRotatef(getAngle(), 0.f, 0.f, 1.f);
for (auto obj : partList_)
obj->draw();
// restore the original coordinate system (origin, axes, scale)
glPopMatrix();
}
bool ComplexGraphicObject::isInside(const WorldPoint& pt) const
{
bool check = false;
// std::cout << "Inside Complex Graphic Object isInside: " << pt.x << "," << pt.y << " | " << getX() << "," << getY() << std::endl;
WorldPoint localPt = {(pt.x - getX()), pt.y - getY()};
// return false;
for (auto obj : partList_)
check = check || obj->isInside(localPt);
return check;
}