JOGL - 打开 GL - 保持世界的一部分静止,同时移动其余部分
我对 JOGL 有点陌生,我正在开发一款游戏。我有一枚火箭、背景中有星星和行星。我希望火箭在屏幕底部保持静止,按下“GO”按钮,然后行星开始下降,让火箭躲避。
我总是以点击“开始”结束,行星坠落(通过翻译),火箭也坠落。我知道为什么相机在移动时会发生这种情况,所以整个世界都在移动。我一直在尝试使用pushMatrix和popMatrix,但没有任何运气。
即
if (goButtonPressed)
{
//gl.glTranslatef(0.0f,0.3f,0f); // this line just keeps the whole thing still
drawRocket(gl); // I was trying to 'undo' the translation
gl.glPushMatrix();
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glTranslatef(0.0f, -0.3f, 0f);
gl.glPopMatrix();
}
我想要在 opengl 中做的事情可能吗?我是不是把事情搞得太难了?
I'm kind of new to JOGL, and I am working on a game. I have a rocket, stars in the background, and planets. I want the rocket to remain stationary at the bottom of the screen, the GO button to be pressed, and then planets start coming down for the rocket to avoid.
I keep ending up with hitting go, the planets coming down (via translation), and the rocket also going down. I know Why this is happened with the camera moving, so the whole world is moving. I've been trying to use the pushMatrix and popMatrix, but haven't had any luck.
i.e.
if (goButtonPressed)
{
//gl.glTranslatef(0.0f,0.3f,0f); // this line just keeps the whole thing still
drawRocket(gl); // I was trying to 'undo' the translation
gl.glPushMatrix();
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glTranslatef(0.0f, -0.3f, 0f);
gl.glPopMatrix();
}
Is what I am trying to do possible in opengl? Am I making it too difficult?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与其依赖投影矩阵来保存火箭位置的状态,不如将此信息存储在您自己的代码中,然后将绝对坐标传递给 JOGL?然后,可以使用更明显的代码(例如rocket.y += dy; )来更新对象的位置。
顺便说一句,投影矩阵并不打算用于空间变换。使用 GL_MODELVIEW 来避免日后出现微妙的问题。
Instead of relying on the projection matrix to hold the state of your rockets' positions, how about storing this information in your own code and then passing absolute coordinates to JOGL? Then updating the position of an object can be done with a more obvious bit of code like
rocket.y += dy;
.As a small aside, the projection matrix is not intended to be used for spatial transformations. Use GL_MODELVIEW instead to avoid subtle problems down the road.
不完全是你问题的答案,但如果你想用 Java 中的 opengl 制作游戏,你应该看看 JMonkeyEngine。
http://jmonkeyengine.com/
您想要做的事情当然可以使用 opengl 实现,并且相当容易使用JMonkeyEngine。他们的网站上有大量教程等。
Not exactly an answer to your question, but you should look at JMonkeyEngine if you want to make a game with opengl in Java.
http://jmonkeyengine.com/
The thing you are trying to do is certainly possible with opengl and fairly easy to do with JMonkeyEngine. They have plenty of tutorials and such on their site.