2011-12-25 56 views
7

Tôi chỉ muốn vẽ một hình trụ trong opengl. Tôi đã tìm thấy rất nhiều mẫu nhưng tất cả đều lấy xylanh theo trục z. Tôi muốn chúng ở trục x hoặc y. Tôi có thể làm cái này như thế nào. Đoạn code dưới đây là mã vẽ hình trụ theo hướng z và tôi không muốn nóCách vẽ xy lanh theo trục y hoặc trục x trong opengl

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

Trả lời

6

Bạn có thể sử dụng glRotate(angle, x, y, z) để xoay phối hợp của bạn hệ thống:

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 cung cấp liên kết tốt. Sử dụng nó! – DaddyM

4

Trên mỗi làm cho sử dụng glPushMatrixglRotatef vẽ hình trụ và hoàn thành bản vẽ của bạn với glPopMatrix.

Ex .: glRotatef(yRotationAngle, 0.0f, 1.0f, 0.0f); // Rotate your object around the y axis on yRotationAngle radians

Ex .: OnRender() chức năng ví dụ

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 
} 
Các vấn đề liên quan