السلام عليكم و رحمة الله
ارجو المساعدة في هذا الكود
كيف اغير محور الدوران بالنسبة للمثلث لاجعله حول المربع
اقتباس
/*
NeHe (nehe.gamedev.net) OpenGL tutorial seriesGLUT port.in 2001 by milix (milix_gr@hotmail.com)Most comments are from the original tutorials found in NeHe.For VC++ users, create a Win32 Console project and linkthe program with glut32.lib, glu32.lib, opengl32.lib*/#include <windows.h> // Standard Header For MSWindows Applications#include <gl/glut.h> // The GL Utility Toolkit (GLUT) Header// The Following Directive Fixes The Problem With Extra Console Window#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")// Global Variablesbool g_gamemode; // GLUT GameMode ON/OFFbool g_fullscreen; // Fullscreen Mode ON/OFF (When g_gamemode Is OFF)GLfloat g_rtri = 0.0f; // Angle For The TriangleGLfloat g_rquad = 0.0f; // Angle For The Quad// Our GL Specific Initializationsbool init(void){glShadeModel(GL_SMOOTH); // Enable Smooth ShadingglClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black BackgroundglClearDepth(1.0f); // Depth Buffer SetupglEnable(GL_DEPTH_TEST); // Enables Depth TestingglDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To DoglEnable(GL_COLOR_MATERIAL); // Enable Color TrackingglHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);return true;}// Our Rendering Is Done Herevoid render(void){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth BufferglLoadIdentity(); // Reset The Current Modelview MatrixglPushMatrix(); // Save Current Modelview MatrixglTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0glRotatef(g_rtri,0.0f,1.0f,0.0f); // Rotate The Triangle On The Y AxisglBegin(GL_TRIANGLES); // Start Drawing A TriangleglColor3f(1.0f,0.0f,0.0f); // RedglVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Front)glColor3f(0.0f,1.0f,0.0f); // GreenglVertex3f(-1.0f,-1.0f, 1.0f); // Left Of Triangle (Front)glColor3f(0.0f,0.0f,1.0f); // BlueglVertex3f( 1.0f,-1.0f, 1.0f); // Right Of Triangle (Front)glColor3f(1.0f,0.0f,0.0f); // RedglVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Right)glColor3f(0.0f,0.0f,1.0f); // BlueglVertex3f( 1.0f,-1.0f, 1.0f); // Left Of Triangle (Right)glColor3f(0.0f,1.0f,0.0f); // GreenglVertex3f( 1.0f,-1.0f, -1.0f); // Right Of Triangle (Right)glColor3f(1.0f,0.0f,0.0f); // RedglVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Back)glColor3f(0.0f,1.0f,0.0f); // GreenglVertex3f( 1.0f,-1.0f, -1.0f); // Left Of Triangle (Back)glColor3f(0.0f,0.0f,1.0f); // BlueglVertex3f(-1.0f,-1.0f, -1.0f); // Right Of Triangle (Back)glColor3f(1.0f,0.0f,0.0f); // RedglVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Left)glColor3f(0.0f,0.0f,1.0f); // BlueglVertex3f(-1.0f,-1.0f,-1.0f); // Left Of Triangle (Left)glColor3f(0.0f,1.0f,0.0f); // GreenglVertex3f(-1.0f,-1.0f, 1.0f); // Right Of Triangle (Left)glEnd(); // Done Drawing The PyramidglPopMatrix(); // Restore Modelview MatrixglTranslatef(1.5f,0.0f,-7.0f); // Move Right 1.5 Units And Into The Screen 7.0glRotatef(g_rquad,1.0f,0.0f,0.0f); // Rotate The Quad On The X AxisglBegin(GL_QUADS); // Draw A QuadglColor3f(0.0f,1.0f,0.0f); // Set The Color To BlueglVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Top)glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Top)glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top)glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top)glColor3f(1.0f,0.5f,0.0f); // Set The Color To OrangeglVertex3f( 1.0f,-1.0f, 1.0f); // Top Right Of The Quad (Bottom)glVertex3f(-1.0f,-1.0f, 1.0f); // Top Left Of The Quad (Bottom)glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom)glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom)glColor3f(1.0f,0.0f,0.0f); // Set The Color To RedglVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front)glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front)glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front)glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front)glColor3f(1.0f,1.0f,0.0f); // Set The Color To YellowglVertex3f( 1.0f,-1.0f,-1.0f); // Top Right Of The Quad (Back)glVertex3f(-1.0f,-1.0f,-1.0f); // Top Left Of The Quad (Back)glVertex3f(-1.0f, 1.0f,-1.0f); // Bottom Left Of The Quad (Back)glVertex3f( 1.0f, 1.0f,-1.0f); // Bottom Right Of The Quad (Back)glColor3f(0.0f,0.0f,1.0f); // Set The Color To BlueglVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left)glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left)glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left)glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left)glColor3f(1.0f,0.0f,1.0f); // Set The Color To VioletglVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right)glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right)glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right)glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right)glEnd(); // Done Drawing The Quadg_rtri += 0.2f; // Increase The Rotation For The Triangle (NEW)g_rquad -= 0.15f; // Decrease The Rotation For The Quad (NEW)// Swap The Buffers To Become Our Rendering VisibleglutSwapBuffers( );}// Our Reshaping Handler (Required Even In Fullscreen-Only Modes)void reshape(int w, int h){glViewport(0, 0, w, h);glMatrixMode(GL_PROJECTION); // Select The Projection MatrixglLoadIdentity(); // Reset The Projection Matrix// Calculate The Aspect Ratio And Set The Clipping Volumeif (h == 0) h = 1;gluPerspective(80, (float)w/(float)h, 1.0, 5000.0);glMatrixMode(GL_MODELVIEW); // Select The Modelview MatrixglLoadIdentity(); // Reset The Modelview Matrix}// Our Keyboard Handler (Normal Keys)void keyboard(unsigned char key, int x, int y){switch (key) {case 27: // When Escape Is Pressed...exit(0); // Exit The Programbreak; // Ready For Next Casedefault: // Now Wrap It Upbreak;}}// Our Keyboard Handler For Special Keys (Like Arrow Keys And Function Keys)void special_keys(int a_keys, int x, int y){switch (a_keys) {case GLUT_KEY_F1:// We Can Switch Between Windowed Mode And Fullscreen Mode Onlyif (!g_gamemode) {g_fullscreen = !g_fullscreen; // Toggle g_fullscreen Flagif (g_fullscreen) glutFullScreen(); // We Went In Fullscreen Modeelse glutReshapeWindow(500, 500); // We Went In Windowed Mode}break;default:break;}}// Ask The User If He Wish To Enter GameMode Or Notvoid ask_gamemode(){int answer;// Use Windows MessageBox To Ask The User For Game Or Windowed Modeanswer = MessageBox(NULL, "Do you want to enter game mode?", "Question",MB_ICONQUESTION | MB_YESNO);g_gamemode = (answer == IDYES);// If Not Game Mode Selected, Use Windowed Mode (User Can Change That With F1)g_fullscreen = false;}// Main Function For Bringing It All Together.int main(int argc, char** argv){ask_gamemode(); // Ask For Fullscreen ModeglutInit(&argc, argv); // GLUT InitializtionglutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE); // (CHANGED)if (g_gamemode) {glutGameModeString("640x480:16"); // Select The 640x480 In 16bpp Modeif (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE))glutEnterGameMode(); // Enter Full Screenelse g_gamemode = false; // Cannot Enter Game Mode, Switch To Windowed}if (!g_gamemode) {glutInitWindowSize(500, 500); // Window Size If We Start In Windowed ModeglutCreateWindow("NeHe's OpenGL Framework"); // Window Title}init(); // Our InitializationglutDisplayFunc(render); // Register The Display FunctionglutReshapeFunc(reshape); // Register The Reshape HandlerglutKeyboardFunc(keyboard); // Register The Keyboard HandlerglutSpecialFunc(special_keys); // Register Special Keys HandlerglutIdleFunc(render); // We Render In Idle TimeglutMainLoop(); // Go To GLUT Main Loopreturn 0;}