PDA

View Full Version : Shaders for pointcloud of icosahedrons

andrerg01
02-04-2016, 02:08 AM
Hello! So, I've started to get into some mathematical drawing and stuff and I found openGL, magnificent tool! But I still did not get the hang of shaders and stuff... I can make them work fine with "solid" continuous surfaces, but for my porpuses, I don't think it'll work.
The way I do it is:
I generate a file with a bunch of points that belong to whatever I am trying to draw, usually hypercomplex fractals, by testing one point at a time on the xyz matrix (witha delta of 0.01, or 0.001 or whatever) and save them to a file (after distinguishing which ones are on the surface)
Then i read the file and create an icosahedron fo circumradius delta on that xyz position with a random orientation (If i do not give the random orientation it gets very ugly with the lighing, with the random orientation it gives out a more rough surface)
but that does not give out the greatest results, the image often looks sketchy and is hard to recognize when a part of it is closer or further away.

(I would post an example image here, but the page keeps saying it is not a valid image file....)

Here is the code to create the icosahedrons, specifing the normal vector correctly and everything

static void makeIcosahedron(double radius, double x, double y, double z, double angX, double angY, double angZ){

Vector V1 = Vector(0,1*side/2,PHI*side/2);
Vector V2 = Vector(0,-1*side/2,PHI*side/2);
Vector V3 = Vector(PHI*side/2,0,1*side/2);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

Vector V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0,0+1*side/2,0+PHI*side/2);
V2 = Vector(0,0-1*side/2,0+PHI*side/2);
V3 = Vector(0-PHI*side/2,0 ,0+1*side/2);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0,0+1*side/2,0-PHI*side/2);
V2 = Vector(0,0-1*side/2,0-PHI*side/2);
V3 = Vector(0+PHI*side/2,0 ,0-1*side/2);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0,0+1*side/2,0-PHI*side/2);
V2 = Vector(0,0-1*side/2,0-PHI*side/2);
V3 = Vector(0-PHI*side/2,0 ,0-1*side/2);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0 + PHI*side/2,0,0+1*side/2);
V2 = Vector(0 + PHI*side/2,0,0-1*side/2);
V3 = Vector(0 + 1*side/2,0 + PHI*side/2 ,0);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0 + PHI*side/2,0,0+1*side/2);
V2 = Vector(0 + PHI*side/2,0,0-1*side/2);
V3 = Vector(0 + 1*side/2,0 - PHI*side/2 ,0);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0 - PHI*side/2,0,0+1*side/2);
V2 = Vector(0 - PHI*side/2,0,0-1*side/2);
V3 = Vector(0 - 1*side/2,0 - PHI*side/2 ,0);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0 - PHI*side/2,0,0+1*side/2);
V2 = Vector(0 - PHI*side/2,0,0-1*side/2);
V3 = Vector(0 - 1*side/2,0 + PHI*side/2 ,0);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0 + 1*side/2,0 - PHI*side/2,0);
V2 = Vector(0 - 1*side/2,0 - PHI*side/2,0);
V3 = Vector(0,0 - 1*side/2 ,0 + PHI*side/2);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0 + 1*side/2,0 - PHI*side/2,0);
V2 = Vector(0 - 1*side/2,0 - PHI*side/2,0);
V3 = Vector(0,0 - 1*side/2 ,0 - PHI*side/2);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0 + 1*side/2,0 + PHI*side/2,0);
V2 = Vector(0 - 1*side/2,0 + PHI*side/2,0);
V3 = Vector(0,0 + 1*side/2 ,0 + PHI*side/2);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0 + 1*side/2,0 + PHI*side/2,0);
V2 = Vector(0 - 1*side/2,0 + PHI*side/2,0);
V3 = Vector(0,0 + 1*side/2 ,0 - PHI*side/2);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0,0 + 1*side/2,0 + PHI*side/2);
V2 = Vector(0 + 1*side/2,0 + PHI*side/2,0);
V3 = Vector(0 + PHI*side/2,0,0 + 1*side/2);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0,0 + 1*side/2,0 + PHI*side/2);
V2 = Vector(0 - 1*side/2,0 + PHI*side/2,0);
V3 = Vector(0 - PHI*side/2,0,0 + 1*side/2);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0,0 - 1*side/2,0 + PHI*side/2);
V2 = Vector(0 - 1*side/2,0 - PHI*side/2,0);
V3 = Vector(0 - PHI*side/2,0,0 + 1*side/2);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0,0 - 1*side/2,0 + PHI*side/2);
V2 = Vector(0 + 1*side/2,0 - PHI*side/2,0);
V3 = Vector(0 + PHI*side/2,0,0 + 1*side/2);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0,0 + 1*side/2,0 - PHI*side/2);
V2 = Vector(0 + 1*side/2,0 + PHI*side/2,0);
V3 = Vector(0 + PHI*side/2,0,0 - 1*side/2);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0,0 + 1*side/2,0 - PHI*side/2);
V2 = Vector(0 - 1*side/2,0 + PHI*side/2,0);
V3 = Vector(0 - PHI*side/2,0,0 - 1*side/2);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0,0 - 1*side/2,0 - PHI*side/2);
V2 = Vector(0 - 1*side/2,0 - PHI*side/2,0);
V3 = Vector(0 - PHI*side/2,0,0 - 1*side/2);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

V1 = Vector(0,0 - 1*side/2,0 - PHI*side/2);
V2 = Vector(0 + 1*side/2,0 - PHI*side/2,0);
V3 = Vector(0 + PHI*side/2,0,0 - 1*side/2);

V1 = Vector(V1.getXCoord(),cos(angX)*V1.getYCoord() - sin(angX)*V1.getZCoord(), sin(angX)*V1.getYCoord() + cos(angX)*V1.getZCoord());
V2 = Vector(V2.getXCoord(),cos(angX)*V2.getYCoord() - sin(angX)*V2.getZCoord(), sin(angX)*V2.getYCoord() + cos(angX)*V2.getZCoord());
V3 = Vector(V3.getXCoord(),cos(angX)*V3.getYCoord() - sin(angX)*V3.getZCoord(), sin(angX)*V3.getYCoord() + cos(angX)*V3.getZCoord());

V1 = Vector(cos(angY)*V1.getXCoord() + sin(angY)*V1.getZCoord(),V1.getYCoord(), -1*sin(angY)*V1.getXCoord() + cos(angY)*V1.getZCoord());
V2 = Vector(cos(angY)*V2.getXCoord() + sin(angY)*V2.getZCoord(),V2.getYCoord(), -1*sin(angY)*V2.getXCoord() + cos(angY)*V2.getZCoord());
V3 = Vector(cos(angY)*V3.getXCoord() + sin(angY)*V3.getZCoord(),V3.getYCoord(), -1*sin(angY)*V3.getXCoord() + cos(angY)*V3.getZCoord());

V1 = Vector(cos(angZ)*V1.getXCoord() - sin(angZ)*V1.getYCoord(),sin(angZ)*V1.getXCoord() + cos(angZ)*V1.getYCoord(), V1.getZCoord());
V2 = Vector(cos(angZ)*V2.getXCoord() - sin(angZ)*V2.getYCoord(),sin(angZ)*V2.getXCoord() + cos(angZ)*V2.getYCoord(), V2.getZCoord());
V3 = Vector(cos(angZ)*V3.getXCoord() - sin(angZ)*V3.getYCoord(),sin(angZ)*V3.getXCoord() + cos(angZ)*V3.getYCoord(), V3.getZCoord());

V4 = Vector::normalToPlane((Vector(x,y,z)+V2)-(Vector(x,y,z)+V1),(Vector(x,y,z)+V3)-(Vector(x,y,z)+V1));
glNormal3d(V4.getCoord(),V4.getYCoord(),V4.getZCoo rd()); //for the light

glBegin(GL_TRIANGLES);
glVertex3d(x+V1.getXCoord(),y+V1.getYCoord(),z+V1. getZCoord());
glVertex3d(x+V2.getXCoord(),y+V2.getYCoord(),z+V2. getZCoord());
glVertex3d(x+V3.getXCoord(),y+V3.getYCoord(),z+V3. getZCoord());
glEnd();

And here is the overall code, if you are interested

#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <fstream>
#include <time.h>
#include "../../../../../Objects_and_Libraries/MyQuartenions/MyQuarterions.h"
#include "../../../../../Objects_and_Libraries/MyComplex/MyComplex.h"
#include "../../../../../Objects_and_Libraries/MyShapes/MyShapes.h"
#include "../../../../../Objects_and_Libraries/MyMaths/MyMaths.h"
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

#define useScreenShot 0
#define useFile 1

#define minX -2.0
#define maxX 2.0
#define minY -2.0
#define maxY 2.0
#define minZ -2.0
#define maxZ 2.0
#define deltaX 0.01
#define deltaY 0.01
#define deltaZ 0.01
#define nOfScreenshots 6

using namespace std;

class Point_XYZ_RGBA
{
private:
double x;
double y;
double z;

bool blows;
public:

Point_XYZ_RGBA()
{

}

Point_XYZ_RGBA(double ix, double iy, double iz, double ir, double ig, double ib, double ia,bool iblows)
{
x = ix;
y = iy;
z = iz;
blows = iblows;
}
Point_XYZ_RGBA(double ix, double iy, double iz,bool iblows)
{
x = ix;
y = iy;
z = iz;
blows = iblows;
}
Point_XYZ_RGBA(double ix, double iy, double iz)
{
x = ix;
y = iy;
z = iz;
blows = true;
}

double getX()
{
return x;
}
double getY()
{
return y;
}
double getZ()
{
return z;
}
bool getBlows()
{
return blows;
}

void setX(double ix)
{
x = ix;
}
void setY(double iy)
{
y = iy;
}
void setZ(double iz)
{
z = iz;
}
void setBlows(bool iblows)
{
blows = iblows;
}

double lenght()
{
return sqrt(x*x + y*y + z*z);
}

};

float angleX = -45.0f;
float angleY = 0.0f;
float angleZ = 15.0f;
float distanceToOrigin = 5.5f;
float angleDelta = 1.0f;
float distanceDelta = 0.1f;

const unsigned long int totalPointsX = (int)(1-useFile)*((maxX-minX)/deltaX);
const unsigned long int totalPointsY = (int)(1-useFile)*((maxY-minY)/deltaY);
const unsigned long int totalPointsZ = (int)(1-useFile)*((maxZ-minZ)/deltaZ);
unsigned long int totalPoints;
Point_XYZ_RGBA* sPoint = new Point_XYZ_RGBA[(1-useFile)*totalPointsX*totalPointsY*totalPointsZ];

//bool Point[(1-useFile))*totalPointsX][(1-useFile)*totalPointsY][(1-useFile)*totalPointsZ];

int WINDOW_WIDHT = 600;
int WINDOW_HEIGHT = 600;
int WINDOW_POSITION_X = 100;
int WINDOW_POSITION_Y = 100;
char* WINDOW_NAME = "Window";

FILE * allPoints;
FILE * allSPoints;

int maxIterations = 300;
int nIterations = 0;
double finalValue = 0;

char timeStr[100];

/*Functions Prototypes*/
void Reshape(int w, int h);
void Display();
void Initialize();
void Keyboard(unsigned char key, int x, int y);
void findMandelbulb(double x, double y, double z);
void drawMandelbulb();
void SaveTGA(void);
bool findInFile(double kx, double ky, double kz);
double finalRes(Point_XYZ_RGBA Point);
bool ifBlows(double x, double y, double z);

int main(int argc, char **argv)
{
srand(time(NULL));
if(useFile == 0)
{
unsigned int k = 0;
bool surf = false;
printf("Evaluating all the pixels without file assistence\n");
for(double x = minX; x <= maxX; x = x + deltaX)
{
for(double y = minY; y <= maxY; y = y + deltaY)
{
for(double z = minZ; z <= maxZ; z = z + deltaZ)
{
if(ifBlows(x,y,z))
{
for(double dx = -deltaX; dx <= deltaX && surf == false; dx = dx + deltaX)
{
for(double dy = -deltaY; dy <= deltaY && surf == false; dy = dy + deltaY)
{
for(double dz = -deltaZ; dz <= deltaZ && surf == false; dz = dz + deltaZ)
{
if(dx != 0 || dy != 0 || dz != 0)
{
if(ifBlows(x+dx,y+dy,z+dz) == false)
{
surf = true;
}
}
}
}
}
if(surf == true)
{
sPoint[k] = Point_XYZ_RGBA(x,y,z,true);
k++;
}
surf = false;
}
printf("Finding the points that belong to the set and are on the surface: %.2lf%% %.2lf%% %.2%%\n",100*((x-minX)/(maxX-minX)),100*((y-minY)/(maxY-minY)),100*((z-minZ)/(maxZ-minZ)));
nIterations = 0;
}
}
}

printf("All Points processed\n");

totalPoints = k+1;
printf("Drawing the shape\nNumber of Voxels: %d\n", k);
}
else
{
unsigned long int k = 0;
// clock_t t1,t2;
// t1 = clock();
allSPoints = fopen("AllSPoints.txt","w");
bool surf = false;
// t1 = clock();
for(double kx = minX; kx <= maxX; kx = kx + deltaX)
{
for(double ky = minY; ky <= maxY; ky = ky + deltaY)
{
for(double kz = minZ; kz <= maxZ; kz = kz + deltaZ)
{
if(ifBlows(kx,ky,kz) == true)
{
for(double dx = -deltaX; dx <= deltaX && surf == false; dx = dx + deltaX)
{
for(double dy = -deltaY; dy <= deltaY && surf == false; dy = dy + deltaY)
{
for(double dz = -deltaZ; dz <= deltaZ && surf == false; dz = dz + deltaZ)
{
if(dx != 0 || dy != 0 || dz != 0)
{
if(ifBlows(kx+dx,ky+dy,kz+dz) == false)
{
surf = true;
}
}
}
}
}
if(surf == true)
{
fprintf(allSPoints,"%lf\t%lf\t%lf\n",kx,ky,kz);
k++;
}
}
}
// t2 = clock();
printf("Finding the points that belong to the surface: %.2lf%%\t%.2lf%%\t%ld\n",100*((kx-minX)/(maxX-minX)),100*((ky-minY)/(maxY-minY)),k);
}
}
fclose(allSPoints);
totalPoints = k + 1;
printf("Drawing the shape\nNumber of Voxels: %d\n", k);
}

// init GLUT and create window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(WINDOW_POSITION_X, WINDOW_POSITION_Y);
glutInitWindowSize(WINDOW_WIDHT, WINDOW_HEIGHT);
glutCreateWindow(WINDOW_NAME);
Initialize();
// register callbacks
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
// glutIdleFunc(Display);
glutKeyboardFunc(Keyboard);

// enter GLUT event processing cycle
glutMainLoop();

return 0;
}

void Reshape(int w, int h)
{

// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if (h == 0)
h = 1;

float ratio = w * 1.0 / h;

// Use the Projection Matrix
glMatrixMode(GL_PROJECTION);

// Reset Matrix

// Set the viewport to be the entire window
glViewport(0, 0, w, h);

// Set the correct perspective.
gluPerspective(45.0f, ratio, 0.1f, 100.0f);

// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW);
}

void Display(void)
{
glMatrixMode(GL_MODELVIEW);

// Clear Color and Depth Buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Reset transformations
// Set the camera
gluLookAt( 0.0f, 0.0f, distanceToOrigin,//Position of Camera
0.0f, 0.0f, 0.0f, //Looking at point x y z
0.0f, 1.0f, 0.0f);//What is "up"

glRotatef(angleX, 1.0f, 0.0f, 0.0f);
glRotatef(angleY, 0.0f, 1.0f, 0.0f);
glRotatef(angleZ, 0.0f, 0.0f, 1.0f);

glBegin(GL_LINES);
glColor3f(1.0,1.0,1.0);
glVertex3d(2.0,0.0,0.0);
glVertex3d(-2.0,0.0,0.0);
glVertex3d(0.0,2.0,0.0);
glVertex3d(0.0,-2.0,0.0);
glVertex3d(0.0,0.0,2.0);
glVertex3d(0.0,0.0,-2.0);

glEnd();

drawMandelbulb();

glutSwapBuffers();
glutPostRedisplay();

}

void Initialize()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glEnable(GL_DEPTH_TEST);
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);

//Lighting Setup
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);
glEnable(GL_LIGHT3);
glEnable(GL_LIGHT4);
glEnable(GL_LIGHT5);

//Set Lighting Intensity and Color
GLfloat qaAmbientLight[] = {0.2, 0.2, 0.2, 1.0}; //R G B Alpha
GLfloat qaDiffuseLight[] = {0.5, 0.5, 0.5, 1.0}; //ususaly, Ambient + Diffuse = 1.0
GLfloat qaSpecularLight[] = {0.1, 0.1, 0.1, 0.1};
glLightfv(GL_LIGHT0, GL_AMBIENT, qaAmbientLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, qaSpecularLight);
glLightfv(GL_LIGHT1, GL_AMBIENT, qaAmbientLight);
glLightfv(GL_LIGHT1, GL_SPECULAR, qaSpecularLight);
glLightfv(GL_LIGHT2, GL_AMBIENT, qaAmbientLight);
glLightfv(GL_LIGHT2, GL_SPECULAR, qaSpecularLight);
glLightfv(GL_LIGHT3, GL_AMBIENT, qaAmbientLight);
glLightfv(GL_LIGHT3, GL_SPECULAR, qaSpecularLight);
glLightfv(GL_LIGHT4, GL_AMBIENT, qaAmbientLight);
glLightfv(GL_LIGHT4, GL_SPECULAR, qaSpecularLight);
glLightfv(GL_LIGHT5, GL_AMBIENT, qaAmbientLight);
glLightfv(GL_LIGHT5, GL_SPECULAR, qaSpecularLight);

//Set Light Position
GLfloat qaLightPosition0[] = {2.0, 0.0, 0.0, 1.0}; //X, Y, Z, 1.0 <-- set the 4th coord to 1
GLfloat qaLightPosition1[] = {0.0, 2.0, 0.0, 1.0};
GLfloat qaLightPosition2[] = {0.0, 0.0, 2.0, 1.0};
GLfloat qaLightPosition3[] = {-2.0, 0.0, 0.0, 1.0};
GLfloat qaLightPosition4[] = {0.0, -2.0, 0.0, 1.0};
GLfloat qaLightPosition5[] = {0.0, 0.0, -2.0, 1.0};
glLightfv(GL_LIGHT0, GL_POSITION, qaLightPosition0);
glLightfv(GL_LIGHT1, GL_POSITION, qaLightPosition1);
glLightfv(GL_LIGHT2, GL_POSITION, qaLightPosition2);
glLightfv(GL_LIGHT3, GL_POSITION, qaLightPosition3);
glLightfv(GL_LIGHT4, GL_POSITION, qaLightPosition4);
glLightfv(GL_LIGHT5, GL_POSITION, qaLightPosition5);

}

void Keyboard(unsigned char key, int x, int y)
{
if(key == 27)
{
exit(0);
}
else if(key == 'd')
{
angleY += angleDelta;
}
else if(key == 'a')
{
angleY -= angleDelta;
}
else if(key == 's')
{
angleX += angleDelta;
}
else if(key == 'w')
{
angleX -= angleDelta;
}
else if(key == 'e')
{
angleZ += angleDelta;
}
else if(key == 'q')
{
angleZ -= angleDelta;
}
else if(key == 'z')
{
distanceToOrigin -= distanceDelta;
}
else if(key == 'x')
{
distanceToOrigin += distanceDelta;
}
else if(key == 'r')
{
angleX = 0.0f;
angleY = 0.0f;
angleZ = 0.0f;
distanceToOrigin = 10.0;
}
}

void findMandelbulb(double x, double y, double z)
{
double cx = x;
double cy = y;
double cz = z;
double t;
double p;
double r;
while(nIterations < maxIterations && sqrt(cx*cx + cy*cy + cz*cz) < 2.0)
{
r = sqrt(cx*cx + cy*cy + cz*cz);
t = 2*atan2(cy,cx);
p = 2*asin(cz/r);
cx = pow(r,2)*cos(t)*cos(p) + x;
cy = pow(r,2)*sin(t)*cos(p) + y;
cz = pow(r,2)*-1*sin(p) + z;
nIterations++;
}
finalValue = sqrt(cx*cx + cy*cy + cz*cz);
}

void drawMandelbulb()
{
if(useFile == 0)
{
for(unsigned int k = 0; k < totalPoints; k++)
{
GLfloat qaBlack[] = {0.0, 0.0, 0.0, 1.0};
GLfloat qaColor[] = {exp(-1*pow(finalRes(sPoint[k])-1.2,2)/0.4)/2,exp(-1*pow(finalRes(sPoint[k])-1.0,2)/0.05)/2,exp(-1*pow(finalRes(sPoint[k])-0.6,2)/0.05)/5, 1.0};
GLfloat qaWhite[] = {0.1, 0.1, 0.1, 1.0};
GLfloat qaLowAmbient[] = {0.2, 0.2, 0.2, 1.0};
GLfloat qaFullAmbient[] = {1.0, 1.0, 1.0, 1.0};
glMaterialfv(GL_FRONT, GL_AMBIENT, qaColor);
glMaterialfv(GL_FRONT, GL_DIFFUSE, qaColor);
glMaterialfv(GL_FRONT, GL_SPECULAR, qaColor);
glMaterialf(GL_FRONT, GL_SHININESS, 60.0); //0 to 128
glLightfv(GL_LIGHT0, GL_AMBIENT, qaLowAmbient);
glLightfv(GL_LIGHT1, GL_AMBIENT, qaLowAmbient);
glLightfv(GL_LIGHT2, GL_AMBIENT, qaLowAmbient);
glLightfv(GL_LIGHT3, GL_AMBIENT, qaLowAmbient);
glLightfv(GL_LIGHT4, GL_AMBIENT, qaLowAmbient);
glLightfv(GL_LIGHT5, GL_AMBIENT, qaLowAmbient);

MyShapes::makeIcosahedron((deltaX + deltaY + deltaZ)/3,sPoint[k].getX(),sPoint[k].getY(),sPoint[k].getZ(),MyMaths::randDouble(0,6.28),MyMaths::randD ouble(0,6.28),MyMaths::randDouble(0,6.28));
}
}
else
{
allSPoints = fopen("AllSPoints.txt","r");
char string_0[256];
double x;
double y;
double z;
while((fgets(string_0,256,allSPoints)) != NULL)
{
fscanf(allSPoints,"%lf\t%lf\t%lf\n",&x, &y, &z);

GLfloat qaBlack[] = {0.0, 0.0, 0.0, 1.0};
GLfloat qaColor[] = {exp(-1*pow(finalRes(Point_XYZ_RGBA(x,y,z))-1.2,2)/0.4)/2,exp(-1*pow(finalRes(Point_XYZ_RGBA(x,y,z))-1.0,2)/0.05)/2,exp(-1*pow(finalRes(Point_XYZ_RGBA(x,y,z))-0.6,2)/0.05)/5, 1.0};
GLfloat qaWhite[] = {0.1, 0.1, 0.1, 1.0};
GLfloat qaLowAmbient[] = {0.2, 0.2, 0.2, 1.0};
GLfloat qaFullAmbient[] = {1.0, 1.0, 1.0, 1.0};
glMaterialfv(GL_FRONT, GL_AMBIENT, qaColor);
glMaterialfv(GL_FRONT, GL_DIFFUSE, qaColor);
glMaterialfv(GL_FRONT, GL_SPECULAR, qaColor);
glMaterialf(GL_FRONT, GL_SHININESS, 60.0); //0 to 128
glLightfv(GL_LIGHT0, GL_AMBIENT, qaLowAmbient);
glLightfv(GL_LIGHT1, GL_AMBIENT, qaLowAmbient);
glLightfv(GL_LIGHT2, GL_AMBIENT, qaLowAmbient);
glLightfv(GL_LIGHT3, GL_AMBIENT, qaLowAmbient);
glLightfv(GL_LIGHT4, GL_AMBIENT, qaLowAmbient);
glLightfv(GL_LIGHT5, GL_AMBIENT, qaLowAmbient);

MyShapes::makeIcosahedron((deltaX+deltaY+deltaZ)/3,x,y,z,MyMaths::randDouble(0,6.28),MyMaths::randD ouble(0,6.28),MyMaths::randDouble(0,6.28));

}
fclose(allSPoints);
}
if(useScreenShot == 1)
{
SaveTGA();
}
}

double finalRes(Point_XYZ_RGBA Point)
{
double cx = Point.getX();
double cy = Point.getY();
double cz = Point.getZ();
double t;
double p;
double r;
while(nIterations < maxIterations && sqrt(cx*cx + cy*cy + cz*cz) < 2.0)
{
r = (abs(sqrt(cx*cx + cy*cy + cz*cz-4))+0.01)*10;
t = 2*atan2(cy,cx);
p = 2*asin(cz/r);
cx = pow(r,2)*cos(t)*cos(p) + Point.getX();
cy = pow(r,2)*sin(t)*cos(p) + Point.getY();
cz = pow(r,2)*-1*sin(p) + Point.getZ();
nIterations++;
}
return sqrt(cx*cx + cy*cy + cz*cz);
}

bool ifBlows(double x, double y, double z)
{
{
double cx = x;
double cy = y;
double cz = z;
double t;
double p;
double r;
while(nIterations < maxIterations && sqrt(cx*cx + cy*cy + cz*cz) < 2.0)
{
r = sqrt(cx*cx + cy*cy + cz*cz);
t = 2*atan2(cy,cx);
p = 2*asin(cz/r);
cx = pow(r,2)*cos(t)*cos(p) + x;
cy = pow(r,2)*sin(t)*cos(p) + y;
cz = pow(r,2)*-1*sin(p) + z;
nIterations++;
}
if(nIterations == maxIterations)
{
nIterations = 0;
finalValue = 0;
return true;
}
else
{
nIterations = 0;
finalValue = 0;
return false;
}
}
}

void SaveTGA(void)
{

glPixelStorei(GL_PACK_ALIGNMENT,1);

char cFileName[64];

FILE *fScreenshot;

int nSize = WINDOW_WIDHT * WINDOW_HEIGHT * 3;

GLubyte *pixels = new GLubyte [nSize];

if (pixels == NULL) return;

int nShot = 0;

while (nShot < nOfScreenshots)

{

sprintf(cFileName,"screenshot_%d.tga",nShot);

fScreenshot = fopen(cFileName,"rb");

if (fScreenshot == NULL) break;

else fclose(fScreenshot);

++nShot;

if (nShot > 63)

{

printf("Screenshot limit of 64 reached. Remove some shots if you want to take more.");

return;

}

}

fScreenshot = fopen(cFileName,"wb");

GL_UNSIGNED_BYTE, pixels);

//convert to BGR format

unsigned char temp;

int i = 0;

while (i < nSize)

{

temp = pixels[i]; //grab blue

pixels[i] = pixels[i+2];//assign red to blue

pixels[i+2] = temp; //assign blue to red

}

WINDOW_HEIGHT%256,WINDOW_HEIGHT/256,24,0
};

fwrite(pixels, sizeof(GLubyte), nSize, fScreenshot);

fclose(fScreenshot);

delete [] pixels;

return;

}
/*
bool findInFile(double kx, double ky, double kz)
{
char ignore;
char fileN[256];
double iy;
double iz;
int b;

if(kx >= minX && ky >= minY && kz >= minZ)
{
sprintf(fileN,"%lf.txt",kx);
{
printf("deu ruim abrindo\n");
}
while(reader >> iy >> iz >> b)
{
//printf("%lf\t%lf\t%d\n",iy,iz,b);
if(abs(iy - ky) < deltaY/10 && abs(iz - kz) < deltaZ/10)
{
// printf("veio ate aqui\n");
if(b == 1)
{
// printf("true\n");
return true;
}
else
{
// printf("false\n");
return false;
}
}
}
printf("Nao achou\n");
return false;
}
else
{
return false;
}
// return false;
}
int s = 0;
int m = 0;
int h = 0;
int d = 0;
int w = 0;
s = (int)t;
while(s >= 60){
s = s - 60;
m++;
}while(m >= 60){
m = m - 60;
h++;
}while(h >= 24){
h = h - 24;
d++;
}while(d >= 7){
d = d - 7;
w++;
}

if(w > 0){
sprintf(timeStr,"%dw %dd %dh %dm %ds",w,d,h,m,s);
}else if(d > 0){
sprintf(timeStr,"%dd %dh %dm %ds",d,h,m,s);
}else if(h > 0){
sprintf(timeStr,"%dh %dm %ds",h,m,s);
}else if(m > 0){
sprintf(timeStr,"%dm %ds",m,s);
}else{
sprintf(timeStr,"%ds",s);
}
}
*/