当我在屏幕上翻译3D模型时,移动看起来并不平滑。它跳转(毫不奇怪,因为我翻译了1倍)到每个翻译的位置。我的问题是如何在不显示这种生涩/跳跃动画效果的情况下让模型在屏幕上移动。 我试过减少翻译因子,但这当然会减慢运动速度。 以下代码块位于显示(GLAutoDrawable drawable){}例程中:
for (float x = -8;x < 8; x+=2){
for (float z = -8; z < 8; z+=2){
view2 = rotate(view,(float)20,(float)1,(float)0,0); //rotate 30deg on x
//rotate the model. spin on Y. (rotate is a custom func - not using
//old glRotate)
view2 = rotate(view2,(float)rotAngle,(float)0,(float)1,0);
//transX and transY are incremented/decremented by 1 every time
//the KeyPressed event is fired. Animator running at 60fps.
//translate() is a simple matrix multiplier. This is where
//the model gets its new co-ordinates (that it jumps to...)
view2 = translate(view2, (float)transX - x, 0, transZ - z);
//pass transform to the vertex shader
gl.glUniformMatrix4fv(iView, 1, false, view2, 0);
//the projection matrix (static)
gl.glUniformMatrix4fv(iProj, 1, false, projection, 0);
gl.glDrawArrays(GL3.GL_TRIANGLES, 0, 36); //draw 12 triangles (36 vertices).
}
}
答案 0 :(得分:2)
尽快重绘;你必须达到每秒至少约40帧,这样东西才能顺利移动;在较慢的帧速率下,你需要运动模糊来掩盖急动。
在绘制框架之间测量给定框架的绘图代码中的相同点之间的时间,并根据该时间移动。注意
无论是否启用V-Sync,SwapBuffers几乎立即返回。它是OpenGL管道,它最终会停滞不前。