cube
Megjelenés
Főnév
cube (tsz. cubes)
#include <GL/glut.h>
#include <cmath>
#include <cstdlib>
#include <ctime>
float angle = 0.0f; // Rotation angle
int pivotIndex = 0; // Current pivot index
float pivotAxis[6][3] = {
{1.0f, 1.0f, 1.0f}, // Rotate around diagonal
{1.0f, 0.0f, 0.0f}, // Rotate around X-axis
{0.0f, 1.0f, 0.0f}, // Rotate around Y-axis
{0.0f, 0.0f, 1.0f}, // Rotate around Z-axis
{1.0f, -1.0f, 0.0f}, // Rotate around an inclined axis
{-1.0f, 1.0f, 1.0f} // Rotate around another diagonal
};
void drawCube() {
glBegin(GL_QUADS);
// Front Face
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
// Back Face
glColor3f(0.0f, 1.0f, 0.0f); // Green
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, -0.5f);
// Top Face
glColor3f(0.0f, 0.0f, 1.0f); // Blue
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
// Bottom Face
glColor3f(1.0f, 1.0f, 0.0f); // Yellow
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
// Right Face
glColor3f(1.0f, 0.0f, 1.0f); // Magenta
glVertex3f( 0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);
// Left Face
glColor3f(0.0f, 1.0f, 1.0f); // Cyan
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glEnd();
}
void display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.0f); // Move the cube back
glRotatef(angle, pivotAxis[pivotIndex][0], pivotAxis[pivotIndex][1], pivotAxis[pivotIndex][2]); // Rotate cube
drawCube();
glutSwapBuffers();
}
void update(int value) {
angle += 2.0f; // Increase rotation angle
if (angle > 360.0f) {
angle -= 360.0f;
}
glutPostRedisplay(); // Request display update
glutTimerFunc(16, update, 0); // Call update every ~16ms (~60 FPS)
}
void switchPivot(int value) {
pivotIndex = (pivotIndex + 1) % 6; // Cycle through the pivot points
glutTimerFunc(2000, switchPivot, 0); // Change pivot every 2 seconds
}
void initGL() {
glEnable(GL_DEPTH_TEST); // Enable depth testing
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black background
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, 1.0, 1.0, 10.0); // Set perspective projection
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(600, 600);
glutCreateWindow("3D Rotating Cube with Changing Pivot");
initGL();
glutDisplayFunc(display);
glutTimerFunc(16, update, 0); // Start animation loop
glutTimerFunc(2000, switchPivot, 0); // Start pivot change loop
glutMainLoop();
return 0;
}
- cube - Szótár.net (en-hu)
- cube - Sztaki (en-hu)
- cube - Merriam–Webster
- cube - Cambridge
- cube - WordNet
- cube - Яндекс (en-ru)
- cube - Google (en-hu)
- cube - Wikidata
- cube - Wikipédia (angol)
Kiejtés
- IPA: /kyb/
Főnév
cube hn (plural cubes)