JOGL - 打开 GL - 保持世界的一部分静止,同时移动其余部分

发布于 2024-11-03 13:18:47 字数 599 浏览 0 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

被你宠の有点坏 2024-11-10 13:18:49

与其依赖投影矩阵来保存火箭位置的状态,不如将此信息存储在您自己的代码中,然后将绝对坐标传递给 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.

或十年 2024-11-10 13:18:49

不完全是你问题的答案,但如果你想用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文