- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
原始问题
我想使用“gluPerspective”、“glViewport”和“gluLookAt”来操作我的相机和屏幕。
我将哪些功能应用于哪种矩阵模式?我应该/必须以什么顺序使用它们?
例如,我正在尝试像这样设置我的屏幕和相机:(但它不起作用!)
glMatrixMode(GL_PROJECTION) // Apply following to projection matrix - is this correct?
glLoadIdentity(); // Reset first
glPerspective(45.0, (double)w/(double)h, 1.0, 200.0); // Set perspective
glViewport(0, 0, w, h); // Set viewport
glMatrixMode(GL_MODELVIEW); // Apply following to modelview - should glViewport come under here?
glLoadIdentity(); // Reset first
gluLookAt(px, py, pz, cx, cy, cz, ux, uy, uz); // Set position, centre and then up vectors
// This surely comes after calling GL_MODELVIEW?
我四处寻找在线文档,我了解这些功能,只是不知道它们应该去哪里以及以什么顺序!
// Firstly, the window may have been resized so re-create the viewing area
glViewport(0, 0, width_of_window_rendering_area, height_of_window_rendering area);
这将重新创建用于在窗口内部的整个区域进行渲染的视口(viewport)。使用 sfml,您可以执行诸如 window.width() 或 window.height() 之类的操作,或类似的操作,具体取决于您使用的窗口工具包(glut、glfw、sdl 等)...
// The second step is to add a projection matrix. There are three main ones I like to use
// Uncomment the one you want
glMatrixMode(GL_PROJECTION); // Tell OpenGL to manipulate the correct matrix stack
glLoadIdentity(); // Reset the projection matrix, or bad things happen after multiple calls to below functions!
// glOrtho( ... ) // Uncomment to use 2D rendering
// gluPerspective( ... ) // Uncomment to use (easy) 3D rendering
glFrustrum( ... ) // Uncomment to use (harder/less intuitive?) 3D rendering
glMatrixMode(GL_MODELVIEW); // I always prefer to leave OpenGL in the modelview manipulation mode.
// I consider it the "default" and safest mode to leave OpenGL in, as any rogue
// calls to functions changing its contents is likely to mess up your geometry
// which should be visible as a problem on the screen, which tells you you need
// to fix something! Manipulating the other matrix stacks may not show obvious
// problems.
您需要从“glOrtho”、“gluPerspective”和“glFrustrum”三个选项中选择一个。还有'gluOrtho2D',但要小心使用! (我更喜欢自己用“glOrtho”指定近平面和远平面。)您还需要用函数的参数替换“...”。
// The third step is to clear the screen and set your camera / geometry position
glClear(GL_COLOR_BUFFER_BIT); // use bitwise OR ('||') with 'GL_DEPTH_BUFFER_BIT' and 'GL_STENCIL_BUFFER_BIT' if required
gluLookAt( ... );
// I like to use gluLookAt, or at least I _italic_used to! Now I implement my own camera...
// That is another fun thing you should try if you are comfortable with 3D geometry and hard math!
// The fourth step is to draw your scene. You may want to put lighting stuff first or in with the drawing
glutWireTeapot( ... );
方法二:
最佳答案
我将我的 reshape 回调函数定义为:
调用 glViewport(...)
一次在开始。
然后用单位矩阵重新加载投影矩阵:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glPerspective(...)
glMatrixMode(GL_MODELVIEW);
gluLookAt(...)
如果您需要更改相机位置,可以随时调用。
关于opengl - gluPerspective、glViewport、gluLookAt 以及 GL_PROJECTION 和 GL_MODELVIEW 矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13053334/
我在 OpenGL 的天空盒内制作过山车,并且没有太多关于它的功能或计算机图形的背景知识,这被证明是非常困难的。我使用 Catmull-Rom 样条插值绘制了一个过山车,并使用 glVertex3f
我正在尝试制作一个在 3D 空间中自由移动的相机。 glulookat 函数如下所示: gluLookAt(g_eye[0],g_eye[1],g_eye[2], g_look
我正在尝试将我的太空入侵者游戏切换为第一人称视角,即从船上看世界的视角。我对应该关注什么点感到有点困惑。我目前在 gluLookAt 中使用这些参数: GL11.glMatrixMode(GL11.G
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 Improve th
我正在尝试使用 gluLookAt() 函数来控制放大和缩小。现在它根本没有改变矩阵,我不知道为什么。 相关代码如下: // Basic Opengl display function void on
我没有多少 OpenGL 经验。我正在尝试画一个茶壶并在茶壶周围移动相机。为此,我使用了 gluLookAt 函数。问题是,当我调用 gluLookAt 时,屏幕是空白的,我看不到我的茶壶。 #inc
我刚买了一台新电脑,现在必须让我的演示程序与 SDL2/OpenGL 一起运行。我使用该程序尝试了各种技术并使用了 gluLookAt(显然,不应该再使用它,甚至永远不应该使用它)。 现在我正在寻找一
我使用 Eclipse 在 OpenGL 中创建了一个保龄球游戏。 现在我想在按下按键时更改相机的 View 。 但是当我按下 x 按钮时,一切都消失了。 这里是我们的代码:- #include #
我正在用 opengl 编程,我想更改相机 View : ... void RenderScene() //Zeichenfunktion { glClearColor( 1.0, 0.5, 0.0
伪代码: drawScene() { for(every 3Dobject) { glMatrixMode(GL_MODELVIEW); glLoadIdent
这就是我计算视线 vector 和向上 vector 的方式。 ly = sin(inclination); lx = cos(inclination)*sin(azimuth);
我正在使用 openGL/GLUT 只是想绘制一个图元并使用 gluLookAt() 来移动相机。遇到麻烦,我只看到黑色。这是我的渲染函数代码。 glMatrixMode(GL_MODELVIEW);
为什么 gluLookAt 不工作? 它对场景没有任何影响,就好像它甚至没有被调用一样。 是因为我正在使用 glMatrixMode(GL_MODELVIEW); 如果我不包含它,屏幕上什么也看不到。
我有一个 OpenGL 程序,当我调用它时它可以工作: gluLookAt(0.1,0.1,0.1, 0,0,0, 0,0.1,0); ...但不是当我这样称呼时: gluLookAt(0.01,0.
通过这条指令 gluLookAt: gluLookAt( p1, p2, p3, l1, l2, l3, u1, u2, u3 ); 如何将相机向左移动一个单位,同时保持注视同一点的方向? 显然我不能
我正在尝试使用 gluLookAt() 设置视角 这里有我的代码,我尝试在其中设置相机但没有结果 这里的函数displaycone(): void displayCone(void) { gl
我想使用 Camera 外部矩阵和 gluLookAt 函数在图像上显示模型。 模型平移到原点,即模型的质心位于原点。 (模型坐标系以右手为准) 然后使用 cvFindExtrinsicCameraP
我尝试自己计算观察矩阵,而不是使用 gluLookAt()。我的问题是我的矩阵不起作用。然而,在 gluLookAt 上使用相同的参数确实有效。 我创建观察矩阵的方法: Vector3 Eye, At
据我了解, gluLookAt( eye_x, eye_y, eye_z, center_x, center_y, center_z, up_x,
我正在开发一个简单的 2D 自上而下 OpenGL 游戏,其中相机跟随玩家。我使用 gluLookAt 将相机定位在玩家上方并朝其方向看。然而,在运行游戏时,即使没有输入,相机也会围绕轴旋转。 旋转速
我是一名优秀的程序员,十分优秀!