summaryrefslogtreecommitdiffstats
path: root/Project/Element.cpp
diff options
context:
space:
mode:
authorThales1330 <thaleslima.ufu@gmail.com>2016-09-05 18:43:50 -0300
committerThales1330 <thaleslima.ufu@gmail.com>2016-09-05 18:43:50 -0300
commitd93ef357da510f2515556ff2cb51688a4e068805 (patch)
treeda24ff514d5d507252681365d7cda6b08576af23 /Project/Element.cpp
parent47cebfc84d4ae315f4bf8ffb3d074b2b75781a1b (diff)
downloadPSP.git-d93ef357da510f2515556ff2cb51688a4e068805.tar.gz
PSP.git-d93ef357da510f2515556ff2cb51688a4e068805.tar.xz
PSP.git-d93ef357da510f2515556ff2cb51688a4e068805.zip
All elements implemented, switches implemented
Diffstat (limited to 'Project/Element.cpp')
-rw-r--r--Project/Element.cpp80
1 files changed, 72 insertions, 8 deletions
diff --git a/Project/Element.cpp b/Project/Element.cpp
index ff7d246..9f10ffc 100644
--- a/Project/Element.cpp
+++ b/Project/Element.cpp
@@ -20,11 +20,16 @@ void Element::DrawCircle(wxPoint2DDouble position, double radius, int numSegment
glEnd();
}
-void Element::DrawArc(wxPoint2DDouble position, double radius, double initAngle, double finalAngle, int numSegments, GLenum mode) const
+void Element::DrawArc(wxPoint2DDouble position,
+ double radius,
+ double initAngle,
+ double finalAngle,
+ int numSegments,
+ GLenum mode) const
{
- double initAngRad = wxDegToRad(initAngle);
- double finalAngRad = wxDegToRad(finalAngle);
- glBegin(mode);
+ double initAngRad = wxDegToRad(initAngle);
+ double finalAngRad = wxDegToRad(finalAngle);
+ glBegin(mode);
for(int i = 0; i <= numSegments; i++) {
double theta = initAngRad + (finalAngRad - initAngRad) * double(i) / double(numSegments);
glVertex2f(radius * std::cos(theta) + position.m_x, radius * std::sin(theta) + position.m_y);
@@ -34,11 +39,11 @@ void Element::DrawArc(wxPoint2DDouble position, double radius, double initAngle,
void Element::DrawTriangle(std::vector<wxPoint2DDouble> points, GLenum mode) const
{
- glBegin(mode);
- for(int i=0; i<3; i++) {
- glVertex2d(points[i].m_x, points[i].m_y);
+ glBegin(mode);
+ for(int i = 0; i < 3; i++) {
+ glVertex2d(points[i].m_x, points[i].m_y);
}
- glEnd();
+ glEnd();
}
void Element::DrawRectangle(wxPoint2DDouble position, double width, double height, GLenum mode) const
@@ -228,3 +233,62 @@ bool Element::RotatedRectanglesIntersects(wxRect2DDouble rect1,
return true;
}
+
+void Element::UpdateSwitches()
+{
+ // General method, to one switch only.
+ wxPoint2DDouble swCenter = wxPoint2DDouble((m_pointList[0].m_x + m_pointList[1].m_x) / 2.0,
+ (m_pointList[0].m_y + m_pointList[1].m_y) / 2.0);
+ m_switchRect[0] = wxRect2DDouble(swCenter.m_x - m_switchSize / 2.0, swCenter.m_y - m_switchSize / 2.0, m_switchSize,
+ m_switchSize);
+}
+
+void Element::DrawSwitches() const
+{
+ int i = 0;
+ for(auto it = m_parentList.begin(); it != m_parentList.end(); it++) {
+ Element* parent = *it;
+ if(parent) {
+ if(m_online) {
+ glColor4d(0.0, 0.4, 0.0, 1.0); // green
+ }
+ else
+ {
+ glColor4d(1.0, 0.1, 0.1, 1.0); // red
+ }
+
+ glPushMatrix();
+ glTranslated(m_switchRect[i].GetPosition().m_x + m_switchSize / 2.0,
+ m_switchRect[i].GetPosition().m_y + m_switchSize / 2.0, 0.0);
+ glRotated(parent->GetAngle(), 0.0, 0.0, 1.0);
+ glTranslated(-m_switchRect[i].GetPosition().m_x - m_switchSize / 2.0,
+ -m_switchRect[i].GetPosition().m_y - m_switchSize / 2.0, 0.0);
+
+ DrawRectangle(
+ m_switchRect[i].GetPosition() + wxPoint2DDouble(m_switchSize / 2.0, m_switchSize / 2.0),
+ m_switchSize, m_switchSize);
+
+ glPopMatrix();
+ }
+ i++;
+ }
+}
+
+bool Element::SwitchesContains(wxPoint2DDouble position) const
+{
+ for(int i = 0; i < (int)m_switchRect.size(); i++) {
+ if(m_parentList[i]) {
+ if(m_switchRect[i].Contains(position)) return true;
+ }
+ }
+ return false;
+}
+
+void Element::SetOnline(bool online)
+{
+ // Check if any parent is null.
+ for(auto it = m_parentList.begin(); it != m_parentList.end(); it++) {
+ if(!(*it)) return;
+ }
+ m_online = online;
+}