如何使对象在webGL上直线移动?

时间:2018-11-06 22:43:31

标签: javascript 3d

我做了一个物体,意思是一个球体,但我想让它像球一样在x轴上移动。

gPush() ;
{
    gScale(2,2,2);
    gRotate(TIME*180/3.14159,0,1,0) ;
    setColor(vec4(1.0,0.0,0.0,1.0)) ;
    drawSphere() ;
}
gPop() ;

那是我制作的旋转球体,但是如何在x轴上移动它呢?

1 个答案:

答案 0 :(得分:0)

您可以通过将TIME乘以您要移动的距离来使其移动。意思是,如果您希望它缓慢移动,可以尝试

gPush() ;
{
    gScale(2,2,2);
    gRotate(TIME*180/3.14159,1,0,0) ;
    gTranslate(TIME*0.5,0,0); 
    // the 0.5 is the speed and as its on x it would move on the x-axis.

    setColor(vec4(1.0,0.0,0.0,1.0)) ;
    drawSphere() ;
}
gPop() ;