素描靠近对方的对象 [英] Sketching objects near each other

查看:131
本文介绍了素描靠近对方的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制在屏幕上从下面的图:

  | ---- |领域
             | ---- |
             / /
            / /
           / / 圆筒
          / /
         / /角= 45
         | |
         | |
         | |圆筒
         | |
         | |
         | |
  - - - - - - 圆筒
 -----------

我的输出:

  / /
            / /
           / / 圆筒
          / / | ----- |领域
         / /角= 45 | ----- |

我将勾画顶部即与气缸球体。我的code是下面,请看看,说什么是错的。

我试图找出错误,为什么我的原语不靠近对方。但是,我找不到。我曾试图改变翻译的参数,但它不工作。请帮助

 无效对象(无效){
    GLUquadraticObj * T = gluNewQuadratic();    的glTranslatef(-2.0f,-1.0F,0.0);
    gluCylinder(T,0.1F,0.1F,0.3f,32,32);
    gluSphere(T,0.2F,26,13);}无效显示(无效){
    glLoadIdentity();
    glClearColor(0.0,0.0,0.0,1.0F);    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    glPushMatrix();
    目的();
    glPopMAtrix();
    glPopMatrix();
    glutSwapBuffers();
    glFlush();
}无效重塑(INT W,INT高){
    glViewport(0,0,W,H);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0f,W / H,1.0,500.0f);
    glLoadIdentity();
}


解决方案

您需要将调用gluCylinder和gluSphere之间的转换英寸在当前code,它们将都具有相同的转换,即,它们将在相同的位置/取向。尝试:

  gluCylinder(T,0.1F,0.1F,0.3f,32,32);
的glTranslatef(-2.0f,-1.0F,0.0);
gluSphere(T,0.2F,26,13);

另外你叫PopMatrix()更多的时间比你调用PushMatrix()。

I want to sketch the below graph on the screen:

             |----|    sphere
             |----|
             / /
            / /
           / /         cylinder
          / /
         / / angle = 45
         | |
         | |
         | |           cylinder
         | |
         | |
         | |
 -----------           cylinder
 -----------

My output:

             / /
            / /
           / /         cylinder
          / /                        |-----|  sphere
         / / angle = 45              |-----|

I will sketch the top part namely sphere with a cylinder. My code is below, please look and say what is wrong.

I have tried to find the error why my primitives do not near to each other. But, I could not find. I have tried to change parameters of translate, but it does not work. Please, help

void object(void) {
    GLUquadraticObj *t = gluNewQuadratic();

    glTranslatef(-2.0f, -1.0f, 0.0f);
    gluCylinder(t, 0.1f, 0.1f, 0.3f, 32,32);
    gluSphere(t, 0.2f, 26, 13);

}

void display(void) {
    glLoadIdentity();
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
    object();
    glPopMAtrix();
    glPopMatrix();
    glutSwapBuffers();
    glFlush();        
}

void reshape(int w, int h) {
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0f, w/h, 1.0, 500.0f);
    glLoadIdentity();
}

解决方案

You need to translate in between the calls to gluCylinder and gluSphere. In the current code, they will both have the same transformations, i.e. they will be in the same position/orientation. Try:

gluCylinder ( t, 0.1f, 0.1f, 0.3f, 32,32);
glTranslatef ( -2.0f, -1.0f, 0.0f );
gluSphere ( t, 0.2f, 26, 13 ) ;

Also you call PopMatrix() more times than you call PushMatrix().

这篇关于素描靠近对方的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆