2011-12-25 14 views
7

में वाई या एक्स अक्ष में सिलेंडर कैसे आकर्षित करें मैं सिर्फ opengl में एक सिलेंडर खींचना चाहता हूं। मुझे बहुत सारे नमून मिलते हैं लेकिन उनमें से सभी जेड अक्ष में सिलेंडर खींचते हैं। मैं उन्हें एक्स या वाई अक्ष में होना चाहता हूं। मैं यह कैसे कर सकता हूँ। नीचे दिए गए कोड कोड जेड दिशा में सिलेंडर आकर्षित है और मुझे नहीं यहओपनजी

GLUquadricObj *quadratic; 
    quadratic = gluNewQuadric(); 
    gluCylinder(quadratic,0.1f,0.1f,3.0f,32,32); 

उत्तर

6

आप glRotate(angle, x, y, z) उपयोग कर सकते हैं बारी बारी से करने के लिए अपने समन्वय प्रणाली:

GLUquadricObj *quadratic; 
quadratic = gluNewQuadric(); 
glRotatef(90.0f, 0.0f, 1.0f, 0.0f); 
gluCylinder(quadratic,0.1f,0.1f,3.0f,32,32); 

http://www.opengl.org/sdk/docs/man/xhtml/glRotate.xml

+1

@cerq: micha अच्छा लिंक प्रदान किया। इसका इस्तेमाल करें! – DaddyM

4

हर पर प्रस्तुत करना उपयोग glPushMatrixglRotatef सिलेंडर आकर्षित और glPopMatrix साथ अपने ड्राइंग खत्म करना चाहते हैं।

पूर्व .: glRotatef(yRotationAngle, 0.0f, 1.0f, 0.0f); // Rotate your object around the y axis on yRotationAngle radians

पूर्व .: OnRender() समारोह उदाहरण

void OnRender() { 
    glClearColor(1.0f, 0.0f, 0.0f, 1.0f); // Clear the background 
    glClear(GL_COLOR_BUFFER_BIT); //Clear the colour buffer 
    glLoadIdentity(); // Load the Identity Matrix to reset our drawing locations 

    glRotatef(yRotationAngle, 0.0f, 1.0f, 0.0f); // Rotate our object around the y axis on yRotationAngle radians 

    // here *render* your cylinder (create and delete it in the other place. Not while rendering) 
    gluCylinder(quadratic,0.1f,0.1f,3.0f,32,32); 

    glFlush(); // Flush the OpenGL buffers to the window 
}