-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// Created by eciuc on 4/3/2024. | ||
// | ||
|
||
#include "Drawables.h" | ||
|
||
|
||
void Drawables::add(sf::Vertex x) { | ||
points.append(x); | ||
} | ||
|
||
void Drawables::add_triangle_vertex(sf::Vertex x) { | ||
points.append(x); | ||
trianglepoints++; | ||
if(trianglepoints%3==0) | ||
{ | ||
int n=points.getVertexCount(); | ||
triangles.emplace_back(points[n-1],points[n-2],points[n-3]); | ||
} | ||
} | ||
|
||
void Drawables::add_circle(Point origin, float rad) { | ||
sf::CircleShape cir(rad,60); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
cir.setOrigin(rad,rad); | ||
cir.setPosition(origin.getx(),origin.gety()); | ||
cir.setOutlineColor(sf::Color::White); | ||
cir.setFillColor(sf::Color::Transparent); | ||
cir.setOutlineThickness(1); | ||
circles.push_back(cir); | ||
} | ||
|
||
void Drawables::draw(sf::RenderTarget &target, sf::RenderStates states) const { | ||
target.draw(points); | ||
for(auto& cir:circles) | ||
{ | ||
target.draw(cir); | ||
} | ||
sf::VertexArray linepoints(sf::Lines,0); | ||
for(auto tr:triangles) | ||
{ | ||
linepoints.append(tr.geta().tovertex()); | ||
linepoints.append(tr.getb().tovertex()); | ||
|
||
linepoints.append(tr.getb().tovertex()); | ||
linepoints.append(tr.getc().tovertex()); | ||
|
||
linepoints.append(tr.getc().tovertex()); | ||
linepoints.append(tr.geta().tovertex()); | ||
} | ||
target.draw(linepoints); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Created by eciuc on 4/3/2024. | ||
// | ||
|
||
#ifndef OOP_DRAWABLES_H | ||
#define OOP_DRAWABLES_H | ||
|
||
#include <SFML/Graphics.hpp> | ||
#include "Triangle.h" | ||
|
||
class Drawables : public sf::Drawable{ | ||
This comment has been minimized.
Sorry, something went wrong.
mcmarius
Contributor
|
||
|
||
static sf::VertexArray points; | ||
static std::vector<Triangle> triangles; | ||
static std::vector<sf::CircleShape> circles; | ||
static inline int trianglepoints=0; | ||
public: | ||
static void add(sf::Vertex x); | ||
static void add_triangle_vertex(sf::Vertex x); | ||
static void add_circle(Point origin,float rad); | ||
private: | ||
void draw(sf::RenderTarget& target, sf::RenderStates states) const override; | ||
}; | ||
|
||
#endif //OOP_DRAWABLES_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Created by eciuc on 4/3/2024. | ||
// | ||
|
||
#include <SFML/Graphics.hpp> | ||
#include "Point.h" | ||
|
||
|
||
Point::Point(sf::Vertex v){ | ||
this->x=v.position.x; | ||
this->y=v.position.y; | ||
} | ||
Point::Point()= default; | ||
Point::Point(int x,int y) | ||
{ | ||
this->x= static_cast<float>(x); | ||
this->y= static_cast<float>(y); | ||
} | ||
void Point::inc_color(){ | ||
color_index++; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
void Point::setx(float new_x){this->x=new_x;} | ||
void Point::sety(float new_y){this->y=new_y;} | ||
float Point::getx() const{return x;} | ||
float Point::gety() const{return y;} | ||
sf::Vertex Point::tovertex() | ||
{ | ||
sf::Vector2f temp1(x,y); | ||
sf::Vertex temp(temp1,color[color_index]); | ||
return temp; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// Created by eciuc on 4/3/2024. | ||
// | ||
|
||
#ifndef OOP_POINT_H | ||
#define OOP_POINT_H | ||
|
||
#include <SFML/Graphics.hpp> | ||
|
||
class Point { | ||
float x; | ||
float y; | ||
sf::Color color[7]={sf::Color::White,sf::Color::Yellow,sf::Color::Red | ||
This comment has been minimized.
Sorry, something went wrong.
mcmarius
Contributor
|
||
,sf::Color::Green, sf::Color::Magenta, sf::Color::Cyan | ||
, sf::Color::Blue}; | ||
int color_index=0; | ||
public: | ||
Point(sf::Vertex v); | ||
Point(); | ||
Point(int x,int y); | ||
void inc_color(); | ||
void setx(float new_x); | ||
void sety(float new_y); | ||
float getx() const; | ||
float gety() const; | ||
sf::Vertex tovertex(); | ||
friend class Triangle; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
}; | ||
|
||
#endif //OOP_POINT_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Created by eciuc on 4/3/2024. | ||
// | ||
|
||
#include "Triangle.h" | ||
#include "Drawables.h" | ||
#include <SFML/Graphics.hpp> | ||
#include <cmath> | ||
|
||
|
||
Triangle::Triangle(sf::Vertex a,sf::Vertex b,sf::Vertex c): a(a),b(b),c(c){ | ||
cmc=Point(); | ||
calc_center(); | ||
} | ||
void Triangle::calc_center(){ // transform in constructor, fac destructor , copiere operator << | ||
cmc.x= ((a.x * a.x + a.y * a.y) * (b.y - c.y) + (b.x * b.x + b.y * b.y) * (c.y - a.y) + (c.x * c.x + c.y * c.y) * (a.y - b.y)) | ||
This comment has been minimized.
Sorry, something went wrong.
mcmarius
Contributor
|
||
/ ((a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y)) * 2); | ||
cmc.y= ((a.x * a.x + a.y * a.y) * (c.x - b.x) + (b.x * b.x + b.y * b.y) * (a.x - c.x) + (c.x * c.x + c.y * c.y) * (b.x - a.x)) | ||
/ ((a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y)) * 2); | ||
radius = sqrtf((a.x - cmc.x) * (a.x - cmc.x) + (a.y - cmc.y) * (a.y - cmc.y)); | ||
Drawables::add_circle(cmc,radius); | ||
Drawables::add(cmc.tovertex()); | ||
} | ||
|
||
Point Triangle::geta() { | ||
return a; | ||
} | ||
|
||
Point Triangle::getb() { | ||
return b; | ||
} | ||
|
||
Point Triangle::getc() { | ||
return c; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// Created by eciuc on 4/3/2024. | ||
// | ||
|
||
#ifndef OOP_TRIANGLE_H | ||
#define OOP_TRIANGLE_H | ||
|
||
#include "Point.h" | ||
#include <SFML/Graphics.hpp> | ||
|
||
class Triangle{ | ||
Point a,b,c; | ||
Point cmc; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
float radius; | ||
public: | ||
Triangle(sf::Vertex a,sf::Vertex b,sf::Vertex c); | ||
void calc_center(); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
Point geta(); | ||
Point getb(); | ||
Point getc(); | ||
}; | ||
|
||
#endif //OOP_TRIANGLE_H |
pune te rog nume de variabile/atribute mai descriptive acolo unde nu sunt notații consacrate, de exemplu aici
circle
,radius