Hi @DerTroll and @Green_Baron Here is my code
//OctVoxel is a class that saved the centers of cubes
//Draw3DcoordArrowGL is used to draw three arrows ox oy oz from cube centers
void DrawOXarrow(CVector3d currentCoord, GLdouble D) {
GLdouble x1 = currentCoord.x;
GLdouble y1 = currentCoord.y;
GLdouble z1 = currentCoord.z;
GLdouble x2 = currentCoord.x + 0.5;
GLdouble y2 = currentCoord.y;
GLdouble z2 = currentCoord.z;
double x = x2 - x1;
double y = y2 - y1;
double z = z2 - z1;
double L = sqrt(x*x + y * y + z * z);
GLUquadricObj *quadObj;
glPushMatrix();
glTranslated(x1, y1, z1);
if ((x != 0.) || (y != 0.)) {
glRotated(atan2(y, x) / RADPERDEG, 0., 0., 1.);
glRotated(atan2(sqrt(x*x + y * y), z) / RADPERDEG, 0., 1., 0.);
}
else if (z < 0) {
glRotated(180, 1., 0., 0.);
}
glTranslatef(0, 0, L - 4 * D);
quadObj = gluNewQuadric();
gluQuadricDrawStyle(quadObj, GLU_FILL);
gluQuadricNormals(quadObj, GLU_SMOOTH);
gluCylinder(quadObj, 2 * D, 0.0, 4 * D, 32, 1);
gluDeleteQuadric(quadObj);
quadObj = gluNewQuadric();
gluQuadricDrawStyle(quadObj, GLU_FILL);
gluQuadricNormals(quadObj, GLU_SMOOTH);
gluDisk(quadObj, 0.0, 2 * D, 32, 1);
gluDeleteQuadric(quadObj);
glTranslatef(0, 0, -L + 4 * D);
quadObj = gluNewQuadric();
gluQuadricDrawStyle(quadObj, GLU_FILL);
gluQuadricNormals(quadObj, GLU_SMOOTH);
gluCylinder(quadObj, D, D, L - 4 * D, 32, 1);
gluDeleteQuadric(quadObj);
quadObj = gluNewQuadric();
gluQuadricDrawStyle(quadObj, GLU_FILL);
gluQuadricNormals(quadObj, GLU_SMOOTH);
gluDisk(quadObj, 0.0, D, 32, 1);
gluDeleteQuadric(quadObj);
glPopMatrix();
}
void Draw3DcoordArrowGL(int rotAngle, double Xcoord, double Ycoord, double Zcoord,
double Xdir, double Ydir, double Zdir, GLdouble D)
{
CVector3d temp;
temp.x = Xcoord;
temp.y = Ycoord;
temp.z = Zcoord;
glTranslatef(Xcoord, Ycoord, Zcoord);
glRotatef(rotAngle, Xdir, Ydir, Zdir);
DrawOXarrow(temp, D);
DrawOYarrow(temp, D - 0.02);
DrawOZarrow(temp, D + 0.02);
glTranslatef(-1.5, 0.5, 0.5);//const
}
void DrawCubeRolling() {
OctVoxel cb = newCube[numberCube];
//only for cube rolling right-up or left-up
for (int a = 0; a < cubeNum; a++)
{
if (newCube[a].getSelected())
{
glPushMatrix();
glLineWidth(1.9f);
std::cout << "+++++++++++ right ++++++++++++ " << std::endl;
if (newCube[a].getRightRolling()) {
//for Right rolling direction
glTranslatef(cb.getCoordX() - 0.5, cb.getCoordY() - 0.5, 0.0);
glRotatef(angleRotation, cb.getDirectionX(), cb.getDirectionY(), cb.getDirectionZ());
glTranslatef(-0.5, 0.5, 0.5);//const
glColor3f(0.5, 0.5, 1.0); glutSolidCube(1);
Draw3DcoordArrowGL(angleRotation, cb.getCoordX() - 0.5, cb.getCoordY() - 0.5, 0.0,
cb.getDirectionX(), cb.getDirectionY(), cb.getDirectionZ(), 0.02);
}
else {
//for up rolling direction - no need now
std::cout << "------------ up -----------" << std::endl;
}
glPopMatrix();
}
}
if (angleRotation >= 90)
{
newCube[numberCube].setSelected(false); //cb will stop
numberCube += 1; //move to next cb
numberCube %= cubeNum;
newCube[numberCube].setSelected(true);
angleRotation = 0;
}
}
//--------
When I make //Draw3DcoordArrowGL to comments in void DrawCubeRolling() {..}, the cube rolls along its edges perfectly without rolling 3 arrows.
The problem is that glutSolidCube(1) is a function from OpenGl that I could not add or change anything.