试图让我的星星移动并停在某个位置 [英] trying to get my star to move and stop at a certain point

查看:95
本文介绍了试图让我的星星移动并停在某个位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了我的粒子系统,但是现在形成的恒星不断增长,我不知道如何阻止它....
我正在使用glTranslated()并设置z值,以使其在z轴上的该点处停止平移,但无法正常工作.有什么想法吗?

这是我设置z值的功能:

I got my particle system out but now my star that is formed keeps growing and I dont know how to stop it....
I am using glTranslated() and am setting the z value so that it will stop translating at that point in the z axis but it is not working as desired. Any ideas?

This is my function to set the z value:

const double z = 0.0;
const double movez = z + 0.01;
else {
     if(movez >= 20.0){          
       float  movez = 20.0; 
     }
          
     glColor3f(1.0,1.0,1.0);
     glPushMatrix();
     glTranslated(0,0,movez);
     glutSolidSphere(14,40,40);
     glPopMatrix();   
}


谢谢

推荐答案

glColor3f(1.0,1.0,1.0);
    glPushMatrix();
    glTranslated(0,0,movez);
    glutSolidSphere(14,40,40);
    glPopMatrix();


glTranslated将当前矩阵乘以转换矩阵.
每个渲染都会乘以先前的矩阵,从而导致在转换后的矩阵上进行翻译.
我们可以通过用单位矩阵重置当前矩阵来解决此问题.


glTranslated multiplies current matrix by a translation matrix.
Each rendering multiply previous matrix, which cause translation on translated matrix.
We can solve this issue by resetting current matrix with identity matrix.

glColor3f(1.0,1.0,1.0);
     glPushMatrix();
     glLoadIdentity();// This will load identity matrix.
     glTranslated(0,0,movez);
     glutSolidSphere(14,40,40);
     glPopMatrix();


这篇关于试图让我的星星移动并停在某个位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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