这与LookAt目标位置无关,如果它是z = 0或z = 1000或-1000?
我试过了
gluLookAt(512, 384, 2000,
512, 384, 0,
0.0f, 1.0f, 0.0f);
Run Code Online (Sandbox Code Playgroud)
并且工作正常,现在我将第3行(UP向量),最后一个数字更改为0.8
:
gluLookAt(512, 384, 2000,
512, 384, 0,
0.0f, 1.0f, 0.8f);
Run Code Online (Sandbox Code Playgroud)
它完全相同...接下来我尝试并修改了第3行,第一个数字为0.8
:
gluLookAt(512, 384, 2000,
512, 384, 0,
0.8f, 1.0f, 0.8f);
Run Code Online (Sandbox Code Playgroud)
现在视图就像向左旋转了45度.这个UP向量如何工作?
我必须做一个功课,我尝试实现lookAt功能.我试过很多方面,但我得到的唯一结果是蓝屏.我的程序的其余部分工作很大,事实上,如果我使用glm :: lookAt一切都很好.这是我的代码:
mat4 Transform::lookAt(const vec3 &eye, const vec3 ¢er, const vec3 &up)
{
vec3 w(glm::normalize(eye - center)) ;
vec3 u(glm::normalize(glm::cross(up, w)));
vec3 v(glm::cross(w, u)) ;
mat4 ret = mat4 (
vec4 (u.x,v.x,w.x,0),
vec4 (u.y,v.y,w.y,0),
vec4 (u.z,v.z,w.z,0),
vec4 (-u.x*eye.x-u.y*eye.y-u.z*eye.z,
-v.x*eye.x-v.y*eye.y-v.z*eye.z,
-w.x*eye.x-w.y*eye.y-w.z*eye.z,
1)
);
return ret;
Run Code Online (Sandbox Code Playgroud) OpenGL文档说应该在GL_MODELVIEW矩阵上完成gluLookAt()调用:
http://www.opengl.org/resources/faq/technical/viewing.htm
事实上,文档链接到一篇文章,该文章说在GL_PROJECTION矩阵上使用gluLookAt()极其糟糕:
另一方面,有许多教程和示例,其中gluLookAt()实际上是在GL_PROJECTION矩阵上调用的.同时,虽然上面提到的文章确实说不在GL_PROJECTION矩阵上使用它,但是在大多数这样的用法中,这样做没有明显的问题.
那么我的问题是:在现实生活中使用gluLookAt()的最佳方法是什么?在GL_PROJECTION矩阵上使用它真的不是很难吗?
我想使用'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?
Run Code Online (Sandbox Code Playgroud)
我一直在寻找在线文档,我理解这些功能,而不是它们应该去的地方以及它们的顺序!
现在几个月后,我正在添加一个快速编辑,以显示我用于使用OpenGL渲染事物的系统.这是为了帮助将来看到这个问题的其他人.
我主要使用两种方法.
方法1:
此方法将所有内容组合在一
// …
Run Code Online (Sandbox Code Playgroud) 根据我的理解,
gluLookAt(
eye_x, eye_y, eye_z,
center_x, center_y, center_z,
up_x, up_y, up_z
);
Run Code Online (Sandbox Code Playgroud)
相当于:
glRotatef(B, 0.0, 0.0, 1.0);
glRotatef(A, wx, wy, wz);
glTranslatef(-eye_x, -eye_y, -eye_z);
Run Code Online (Sandbox Code Playgroud)
但是当我打印出ModelView
矩阵时,调用glTranslatef()
似乎不能正常工作.这是代码片段:
#include <stdlib.h>
#include <stdio.h>
#include <GL/glut.h>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
static const int Rx = 0;
static const int Ry = 1;
static const int Rz = 2;
static const int Ux = 4;
static const int Uy = 5;
static const int Uz = 6; …
Run Code Online (Sandbox Code Playgroud) 我正在使用LWJGL学习OpenGL 3.我试图实现一个等效的gluLookAt()
,虽然它的工作原因我有点困惑为什么.
我承认只是从网络上的各种来源复制这些代码,但经过深入研究后,我认为理解它背后的数学,并且我理解LWJGL在做什么.
但是,"正确" gluLookAt
代码在我的应用程序中表现不正确,因为相机似乎转向了错误的方式.我只设法获得通过转置正交向量的工作我的代码forward
,side
以及up
(希望我使用的是正确的术语!),我敢肯定是错误的...
private static final Vector3f forward = new Vector3f();
private static final Vector3f side = new Vector3f();
private static final Vector3f up = new Vector3f();
private static final Vector3f eye = new Vector3f();
public static Matrix4f lookAt(float eyeX, float eyeY, float eyeZ,
float centerX, float centerY, float centerZ,
float upX, float upY, float upZ) {
forward.set(centerX - eyeX, centerY - eyeY, centerZ - eyeZ);
forward.normalise();
up.set(upX, upY, …
Run Code Online (Sandbox Code Playgroud) 我正在OpenGL中的天空盒内制作一个过山车,并且没有太多关于它的功能或计算机图形的背景,它被证明是非常困难的.我使用Catmull-Rom样条插值绘制了一个过山车,并用glVertex3f绘制了每个点.现在我想update()
每50ms 调用一次功能来将摄像机移动到轨道上.gluLookAt()
产生奇怪的结果,要么从屏幕上删除轨道,产生黑屏等等.我想我需要移动一些矩阵函数,但我不知道在哪里放置每个.到目前为止,这是我的代码:
int main(int argc, char** argc)
{
// ... load track, etc ...
// Init currpos, nextpos, iter, up
currpos = Vec3f(0, 0, 0);
nextpos = currpos;
iter = 0;
up = Vec3f(0, 1, 0);
deque<Vec3f> points;
Vec3f newpt;
// Loop through the points and interpolate
for (pointVectorIter pv = g_Track.points().begin(); pv != g_Track.points().end(); pv++)
{
Vec3f curr(*pv); // Initialize the current point and a new point (to be drawn)
points.push_back(curr); // Push the current …
Run Code Online (Sandbox Code Playgroud) 您好,我的鼠标在 openGL 中移动时遇到了一个奇怪的问题。这是我用鼠标移动相机的代码
void camera(int x, int y)
{
GLfloat xoff = x- lastX;
GLfloat yoff = lastY - y; // Reversed since y-coordinates range from bottom to top
lastX = x;
lastY = y;
GLfloat sensitivity = 0.5f;
xoff *= sensitivity;
yoff *= sensitivity;
yaw += xoff; // yaw is x
pitch += yoff; // pitch is y
// Limit up and down camera movement to 90 degrees
if (pitch > 89.0)
pitch = 89.0;
if (pitch < -89.0) …
Run Code Online (Sandbox Code Playgroud) 我有立方体,每个侧锁都有不同的颜色 -
public void display(GLAutoDrawable drawable) {
final GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
///// SET CAMERA /////
setCamera(gl, glu, 100);
// /////// Cube - start ///////////
// cube
// ----- Render the Color Cube -----
gl.glLoadIdentity(); // reset the current model-view matrix
gl.glTranslatef(0f, 0.0f, -7.0f); // translate right and into the
// screen
gl.glRotatef(angleCube, 1.0f, 1.0f, 1.0f); // rotate about the x, y and
// z-axes
gl.glBegin(GL.GL_QUADS); // of the color cube
// Top-face
gl.glColor3f(0.0f, 1.0f, 0.0f); // …
Run Code Online (Sandbox Code Playgroud)