Skip to content
Snippets Groups Projects
Commit 604a8945 authored by Cseh Viktor's avatar Cseh Viktor
Browse files

mozgatas mukodik

parent 025b8df9
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
 Skeleton.cpp
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\framework.h(167,17): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(100,39): warning C4244: 'return': conversion from 'double' to 'float', possible loss of data
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(209,1): warning C4305: 'initializing': truncation from 'double' to 'float'
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(274,22): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(285,22): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(372,21): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(379,21): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(425,21): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(254,1): warning C4305: 'initializing': truncation from 'double' to 'float'
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(321,22): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(330,22): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(435,21): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(442,21): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(460,21): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(470,21): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(472,22): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(488,23): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(491,26): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(495,27): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(496,28): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(543,21): warning C4018: '<': signed/unsigned mismatch
D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(603,22): warning C4018: '<': signed/unsigned mismatch
Generating code
2 of 355 functions ( 0.6%) were compiled, the rest were copied from previous compilation.
1 of 435 functions ( 0.2%) were compiled, the rest were copied from previous compilation.
0 functions were new in current compilation
1 functions had inline decision re-evaluated but remain unchanged
Finished generating code
......
No preview for this file type
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
No preview for this file type
......@@ -59,21 +59,15 @@ const char* const fragmentSource = R"(
outColor = vec4(color, 1); // computed color is the color of the primitive
}
)";
//
// Global variables
//
const int CIRCLESEG = 25; //how many triangle the base stands from
GPUProgram gpuProgram; // vertex and fragment shaders
unsigned int vao;
float movedTocX;
float movedTocY;
//
// Global structs
//
float clickedOncX;
float clickedOncY;
struct Color {
float r, g, b;
......@@ -87,6 +81,12 @@ struct Color {
}
};
const int CIRCLESEG = 25; //how many triangle the base stands from
GPUProgram gpuProgram; // vertex and fragment shaders
int GraphPointSize = 50;
//
//Global functions
//
......@@ -106,6 +106,7 @@ float degToRad(float courrentTriangleAngle) {
class drawableBase {
protected:
unsigned int vao;
unsigned int vbo; //vertex buffer obj
std::vector<vec2> points;
Color color;
......@@ -148,14 +149,31 @@ public:
}
};
int cntr = 0; // TODO: remove this cntr
class GraphPoint : drawableBase {
vec3 p3D; //center of the point in hyperbolic splace
//center of the point in hyperbolic splace
vec3 p3D;
//radius used for the circle
float r = 20.0f;
vec2 p; // center on the base disk
//center of the point in 2D,
//NOT USED for displaying
vec2 p;
//Here stores the point the direct neighbours
std::vector<GraphPoint*> neighbours;
//This is for algorithm. If it's true,
//it wont be drawn again
bool Drawn;
//This is for the cluster search algorithm
//if this GraphPoint has benn added to a cluster,
//the algorithm won't put it again in another cluster
bool searched;
Texture texture;
public:
GraphPoint() {
......@@ -166,44 +184,71 @@ public:
Drawn = false;
}
//Returns if the point is drawn
bool getDrawn() {
return Drawn;
}
//Set the drawn state
void setDrawn(bool _d) {
Drawn = _d;
}
bool getSearched() {
return searched;
}
//Set the drawn state
void setSearched(bool _d) {
searched = _d;
}
//Add a neighbour to vector
void addNeighbour(GraphPoint *gp){
neighbours.push_back(gp);
}
//returns with the neighbour vector.
//Needed for the custer search algorithm
std::vector<GraphPoint*> getNeighbourVec() {
return neighbours;
}
//Returns the size of the neigbours vector
int getNeighboursSize() {
return neighbours.size();
}
//Returns the 2D point. I'm not sure if i use this....
vec2 getPoint() {
return p;
}
//Returns the point coordinates in hyperbolic space.
//NOT divided by Z (not ready for display)
vec3 getPoint3D() {
return p3D;
}
//Sets the point to the given coordinates
//and calculates the point in hyperbolic space
void setCoordinates(vec2 _p) {
p = _p;
p3D = Vec2ToVec3(p);
placeCircleToNewCoordinates();
}
//Converts the 2D point into point in hyperbolic space
vec3 Vec2ToVec3(vec2 p) {
return vec3(p.x, p.y, (float)sqrt(p.x * p.x + p.y * p.y + 1));
}
//Returns the gradient of the point
vec3 grad(vec3 _p) {
return vec3(2 * _p.x, 2 * _p.y, -2 * _p.z);
}
//This calculates the triangles for the circle in hyperbolic space
void placeCircleToNewCoordinates() {
points.clear();
float piece = 360.0 / CIRCLESEG;
......@@ -246,10 +291,9 @@ public:
p3D.y / p3D.z + (sinf(degToRad(courrentTriangleAngle)) / r) / p3D.z * -cosf(atanf(2 * abs(p3D.y)))));
}
//printf("x=%f, y=%f xALPHA=%f \n", p3D.x, p3D.y, sinf(atanf(2 * abs(p3D.x) + 2 * abs(p3D.y))));
}
//Never used it. Projects the 3D point to 2D
vec2 vec3tovec2(vec3 c) {
vec2 temp;
temp.x = c.x;
......@@ -257,15 +301,18 @@ public:
return temp;
}
//Recolors the point
void reColor() const {
int location = glGetUniformLocation(gpuProgram.getId(), "color");
glUniform3f(location, color.r, color.g, color.b); // 3 floats
}
//sets the color of the color of the point to given rgb values
void setColor(Color newColor) override{
color = newColor;
}
//Iterates through the neighbours and sets them to new coordinates
void gpNeighbourAlgorithm(float angle) {
try {
float deg = 360.0f / neighbours.size();
......@@ -273,8 +320,6 @@ public:
for (int i = 0; i < neighbours.size(); i++) {
if (neighbours[i]->getDrawn() == false) {
printf("kirajzolva: %d \n", ++cntr);
neighbours[i]->setCoordinates(vec2(p.x + cosf(degToRad(currAngle)), p.y + sinf(degToRad(currAngle))));
currAngle += deg;
}
......@@ -290,11 +335,12 @@ public:
}
}
}
catch (...) {
printf("Somethings wrong here");
}
catch (...) {
printf("Somethings wrong here");
}
}
//Actually draws the calculated circle/point
void draw()
{
Drawn = true;
......@@ -307,26 +353,40 @@ public:
}
};
//Can't put it to the structs, becouse GraphPoint not declared there
//
// Global structs
//
struct pairs {
GraphPoint* p1;
GraphPoint* p2;
};
struct Cluster {
std::vector<GraphPoint*> data;
int size;
Cluster* next;
};
//
// End of Global structs
//
class Line : drawableBase {
GraphPoint* p1;
GraphPoint* p2;
public:
Line(GraphPoint *_p1, GraphPoint *_p2) {
Line(GraphPoint* _p1, GraphPoint* _p2) {
setColor(Color(254, 254, 0));
p2 = _p2;
p1 = _p1;
}
void set() {
vec3 temp = p1->getPoint3D();
points.push_back(vec2(temp.x / temp.z, temp.y/ temp.z));
points.push_back(vec2(temp.x / temp.z, temp.y / temp.z));
temp = p2->getPoint3D();
points.push_back(vec2(temp.x / temp.z, temp.y / temp.z));
}
......@@ -351,16 +411,19 @@ public:
class graphManager {
GraphPoint* gps = new GraphPoint[50];
GraphPoint* gps = new GraphPoint[GraphPointSize];
std::vector<pairs> pair;
std::vector<Line> line;
//Variables for the sorting algorithms
std::vector<GraphPoint*> twoOrLess;
std::vector<Cluster> clstrs;
public:
graphManager() {
for (int i = 0; i < 50; i++) {
for (int j = i+1; j < 50; j++) {
int rndm = rand() % 100;
for (int i = 0; i < GraphPointSize; i++) {
for (int j = i + 1; j < GraphPointSize; j++) {
int rndm = rand() % 100;
if (rndm < 5) {
pairs p; p.p1 = &gps[i]; p.p2 = &gps[j];
gps[i].addNeighbour(&gps[j]);
......@@ -380,18 +443,114 @@ public:
line[i].draw();
}
for (int i = 0; i < 50; i++) {
for (int i = 0; i < GraphPointSize; i++) {
gps[i].draw();
}
}
void lessThanThreeNGB() {
for (int i = 0; i < GraphPointSize; i++) {
if (gps[i].getNeighboursSize() < 3) {
twoOrLess.push_back(&gps[i]);
}
}
}
bool findInVector(std::vector<GraphPoint*> vec, GraphPoint* p) {
for (int j = 0; j < vec.size(); j++) {
if (vec[j] == p) {
return true;
}
}
return false;
}
//returns if a Graphpoint is in any of the clusters
bool inCluster(GraphPoint* p) {
for (int i = 0; i < clstrs.size(); i++) {
std::vector<GraphPoint*> temp = clstrs[i].data;
for (int j = 0; j < temp.size(); j++) {
if (temp[j] == p) {
return true;
}
}
}
return false;
}
int cntr = 0;
void clusterFinder() {
for (int i = 0; i < GraphPointSize; i++) {
if (!findInVector(twoOrLess, &gps[i])) {
Cluster tempClstr;
std::vector<GraphPoint*> search;
search = gps[i].getNeighbourVec();
for (int j = 0; j < search.size(); j++) { //szomszedain megy vegig
if (!findInVector(twoOrLess, search[j])) { //ha a szomszed nincs benne a 2 vagy kevesebb tombben
if (!inCluster(search[i])) { // es nincs semelyik clusterben
for (int k = 0; k < search[j] -> getNeighbourVec().size(); k++) { //vegigmegy a aszomszed szomszedain
//azonossagot keres a hivo pont szomszedaival
std::vector<GraphPoint*> tempNGBVec;
tempNGBVec = search[j]->getNeighbourVec();
for (int l = 0; l < tempNGBVec.size(); l++) {
for (int m = 0; m < search.size(); m++) {
if (tempNGBVec[l] == search[m]) {
printf("belepve %d \n", ++cntr);
search[j]->setSearched(true); tempNGBVec[l]->setSearched(true); gps[i].setSearched(true);
if (tempClstr.size == 0) {
tempClstr.data.push_back(search[j]);
tempClstr.data.push_back(tempNGBVec[l]);
tempClstr.data.push_back(&gps[i]);
tempClstr.size += 3;
}
else {
tempClstr.data.push_back(search[j]);
tempClstr.data.push_back(tempNGBVec[l]);
tempClstr.size += 2;
}
}
}
}
}
}
}
}
if(tempClstr.size > 2)
clstrs.push_back(tempClstr);
}
}
}
void forceDrivenSort() {
//resulant forces storing vector
std::vector<vec2> resulants;
for (int i = 0; i < GraphPointSize; i++) {
vec2 pointResulatn;
}
}
void sortGraph() {
// Delete previous graph from buffer
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
line.clear();
//reset all the lines TODO: fix this later
for (int i = 0; i < pair.size(); i++) {
Line temp(pair[i].p1, pair[i].p2);
line.push_back(temp);
}
//
//Select the graphpoint with the most pair
//
GraphPoint biggest = gps[0];
gps[0].setDrawn(false);
for (int i = 1; i < 50; i++) {
for (int i = 1; i < GraphPointSize; i++) {
if (gps[i].getNeighboursSize() > biggest.getNeighboursSize())
biggest = gps[i];
gps[i].setDrawn(false);
......@@ -406,29 +565,49 @@ public:
//kirajzolja az elsot
biggest.setDrawn(true);
biggest.gpNeighbourAlgorithm(currAngle);
currAngle += deg;
currAngle -= deg;
//vegigiteral az osszesen
for (int i = 0; i < 50; i++) {
for (int i = 0; i < GraphPointSize; i++) {
//ha meg nics felrajzolva
if (gps[i].getDrawn() == false) {
// beallitja a koordinatat ay elsohoz kepest
gps[i].setCoordinates(vec2(biggest.getPoint3D().x + cosf(degToRad(currAngle)) /0.9f, biggest.getPoint3D().y + sinf(degToRad(currAngle))/0.9f));
gps[i].setCoordinates(vec2(biggest.getPoint3D().x + cosf(degToRad(currAngle)) , biggest.getPoint3D().y + sinf(degToRad(currAngle))));
gps[i].setDrawn(true);
gps[i].gpNeighbourAlgorithm(currAngle);
currAngle += deg;
if (gps[i].getNeighboursSize() != 0) {
gps[i].gpNeighbourAlgorithm(currAngle + deg);
}
currAngle -= deg;
}
}
// Delete previous graph from buffer
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
for (int i = 0; i < line.size(); i++) {
line[i].draw();
}
for (int i = 0; i < 50; i++) {
gps[i].draw();
draw();
//glutSwapBuffers();
glutPostRedisplay();
clusterFinder();
//Count as 1 cluster, if there are at least 3 point,
//wich contains each-other as a neigbour
printf("%d db cluster van", clstrs.size());
lessThanThreeNGB();
printf(" kevesebb mint 3 szomszedos pontok: %d \n", twoOrLess.size());
}
void MoveAllPoints() {
for (int i = 0; i < GraphPointSize; i++) {
vec2 temp = gps[i].getPoint();
vec2 p1((clickedOncX - temp.x), (clickedOncY - temp.y));
gps[i].setCoordinates(vec2((movedTocX - p1.x), (movedTocY - p1.y)));
line.clear();
for (int i = 0; i < pair.size(); i++) {
Line temp(pair[i].p1, pair[i].p2);
line.push_back(temp);
}
}
glutSwapBuffers();
draw();
glutPostRedisplay();
//glutSwapBuffers();
}
};
graphManager gm;
......@@ -462,19 +641,22 @@ void onKeyboard(unsigned char key, int pX, int pY) {
void onKeyboardUp(unsigned char key, int pX, int pY) {
}
// Move mouse with key pressed
void onMouseMotion(int pX, int pY) { // pX, pY are the pixel coordinates of the cursor in the coordinate system of the operation system
// Convert to normalized device space
float cX = 2.0f * pX / windowWidth - 1; // flip y axis
float cY = 1.0f - 2.0f * pY / windowHeight;
printf("Mouse moved to (%3.2f, %3.2f)\n", cX, cY);
movedTocX = 2.0f * pX / windowWidth - 1; // flip y axis
movedTocY = 1.0f - 2.0f * pY / windowHeight;
printf("Mouse moved to (%3.2f, %3.2f)\n", movedTocX, movedTocY);
gm.MoveAllPoints();
}
// Mouse click event
void onMouse(int button, int state, int pX, int pY) { // pX, pY are the pixel coordinates of the cursor in the coordinate system of the operation system
// Convert to normalized device space
float cX = 2.0f * pX / windowWidth - 1; // flip y axis
float cY = 1.0f - 2.0f * pY / windowHeight;
clickedOncX = 2.0f * pX / windowWidth - 1; // flip y axis
clickedOncY = 1.0f - 2.0f * pY / windowHeight;
char* buttonStat;
switch (state) {
......@@ -483,9 +665,9 @@ void onMouse(int button, int state, int pX, int pY) { // pX, pY are the pixel co
}
switch (button) {
case GLUT_LEFT_BUTTON: printf("Left button %s at (%3.2f, %3.2f)\n", buttonStat, cX, cY); break;
case GLUT_MIDDLE_BUTTON: printf("Middle button %s at (%3.2f, %3.2f)\n", buttonStat, cX, cY); break;
case GLUT_RIGHT_BUTTON: printf("Right button %s at (%3.2f, %3.2f)\n", buttonStat, cX, cY); break;
case GLUT_LEFT_BUTTON: printf("Left button %s at (%3.2f, %3.2f)\n", buttonStat, clickedOncX, clickedOncY); break;
case GLUT_MIDDLE_BUTTON: printf("Middle button %s at (%3.2f, %3.2f)\n", buttonStat, clickedOncX, clickedOncY); break;
case GLUT_RIGHT_BUTTON: printf("Right button %s at (%3.2f, %3.2f)\n", buttonStat, clickedOncX, clickedOncY); break;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment