- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我对glm lookAt函数的返回值有疑问。当我以 Debug模式执行时,此时
glm函数的 ... Result[3][2] = dot(f, eye); ...
在矩阵的平移z位置中的值错误。值是-2,向我表明前向和眼向 vector 处于相反的位置。我的眼睛,中心 vector 和向上 vector 分别是eye(0,0,2),center(0,0,-1)和up(0,1,0)。凸轮余弦 vector 为:f(0,0,-1),s(1,0,0)和u(0,1,0)。用户查看的优势点是(0,0,0)。因此,正确的 View 矩阵应为:
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
但我得到这个:
1 -0 -0
-0 1 -0 -0
0 0 0 1-2
0 0 0 0 1
我的代码是:
struct camera {
vec3 position = vec3(0.0f); // position of the camera
vec3 view_direction = vec3(0.0f); // forward vector (orientation)
vec3 side = vec3(0.0f); // right vector (side)
vec3 up = vec3(0.0f, 1.0f, 0.0f); // up vector
float speed = 0.1;
float yaw = 0.0f; // y-rotation
float cam_yaw_speed = 10.0f; // 10 degrees per second
float pitch = 0.0f; // x-rotation
float roll = 0.0f;
...
// calculate the orientation vector (forward)
vec3 getOrientation(vec3 vantage_point) {
// calc the difference and normalize the resulting vector
vec3 result = vantage_point - position;
result = normalize(result);
return result;
}
// calculate the right (side) vector of the camera, by given orientation(forward) and up vectors
mat4 look_at_point(vec3 vantage_point) {
view_direction = getOrientation(vantage_point);
// calculate the lookat matrix
return lookAt(position, position + view_direction, up);
}
};
...
GLfloat points[] = {
0.0f, 0.5f, 0.0f,
0.5f, 0.0f, 0.0f,
-0.5f, 0.0f, 0.0f };
float speed = 1.0f; // move at 1 unit per second
float last_position = 0.0f;
// init camera
main_cam.position = vec3(0.0f, 0.0f, 2.0f); // don't start at zero, or will be too close
main_cam.speed = 1.0f; // 1 unit per second
main_cam.cam_yaw_speed = 10.0f; // 10 degrees per second
vec3 vantage_point = vec3(0.0f, 0.0f, 0.0f);
mat4 T = translate(mat4(1.0), main_cam.position);
//mat4 R = rotate(mat4(), -main_cam.yaw, vec3(0.0, 1.0, 0.0));
mat4 R = main_cam.look_at_point(vantage_point);
mat4 view_matrix = R * T;
// input variables
float near = 0.1f; // clipping plane
float far = 100.0f; // clipping plane
float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians
float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio
mat4 proj_matrix = perspective(fov, aspect, near, far);
use_shader_program(shader_program);
set_uniform_matrix4fv(shader_program, "view", 1, GL_FALSE, &view_matrix[0][0]);
set_uniform_matrix4fv(shader_program, "proj", 1, GL_FALSE, &proj_matrix[0][0]);
...
最佳答案
我怀疑问题出在这里:
mat4 view_matrix = R * T; // <---
lookAt
返回的矩阵已经完成翻译。
T
会将其转换为(0,0,2),但现在它与相机重合,因此
R
会将其发送回(0,0,0)。现在,您将得到射影除以零事故的除法。
T
删除乘法:
mat4 view_matrix = R;
现在(0,0,0)将被映射到(0,0,-2),即相机所看的方向。 (在相机空间中,投影中心在(0,0,0),并且相机朝负Z方向看)。
view_direction
计算
vantage_point
,然后将
position + view_direction
反馈回
lookAt
是实现目标的一种相当人为的方式。您在
getOrientation
函数中执行的操作是
lookAt
在内部已执行的操作。相反,您可以从
view_direction
的结果中获取
lookAt
:
mat4 look_at_point(vec3 vantage_point) {
// calculate the lookat matrix
mat4 M = lookAt(position, vantage_point, up);
view_direction = -vec3(M[2][0], M[2][1], M[2][2]);
return M;
}
但是,考虑到最终您将尝试实现偏航/俯仰/侧倾摄像机控制,因此您就是
better off to not using lookAt
at all。
关于c++ - LookAt(glm)返回错误的转换z值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39943833/
我正在试验光线行进,并且一直在关注 Jamie Wong's tutorial. 当移动相机部分来时,他们使用该功能 mat4 viewMatrix(vec3 eye, vec3 center, ve
您好,我对glm lookAt函数的返回值有疑问。当我以 Debug模式执行时,此时 glm函数的 ... Result[3][2] = dot(f, eye); ...在矩阵的平移z位置中的值错误。
我正在使用一个在我为 LWJGL 找到的名为 JOML 的开源数学库中计算的 LookAt 矩阵。在我的游戏中获得免费摄像头。它在左右旋转时效果很好,但向上和向下看似乎会导致严重的扭曲问题,类似于大幅
我正在编写 3d 引擎,并且遇到了 DirectX 文档中描述的 LookAt 算法: zaxis = normal(At - Eye) xaxis = normal(cross(Up, zaxis)
在虚幻中,我想要 在前向 vector 指向目标当前位置的位置旋转角色, 确保我的 Actor 的向上 vector 与我的目标的向上 vector 相同 在Unity3D中,它 super 简单。这
我在 OpenGL 2.0(固定管道)中构建了一个 lookAt 相机。我的相机跟踪它的位置、观察点和向上 vector 。到目前为止,我已经使用以下代码将相机偏转了一定程度: void Camera
我正在使用 Three.js 透视相机,我需要了解相机所注视的点。 如何使用相机的矩阵/旋转向量计算它? 最佳答案 相机向下看它的内部负 z 轴。所以选择相机负 z 轴上的任意点,如下所示: var
我尝试使用 Lookat 功能通过平移手势旋转相机。我使用 swift 和 Metal(在本例中 Metal 与 OpenGLES 的工作原理相同)。这是我的代码 查看功能: let kEye =
我在谷歌上进行了广泛的搜索,但我还没有找到我认为实际上很常见的情况的解决方案。假设我有一个THREE.PerspectiveCamera初始化为查看空间中的某个点: var camera = new
我正在使用 glm::lookAt 获取一个矩阵来改变世界。这工作正常,我可以生成矩阵,将其输入着色器,一切正常。我现在需要做的是通过 lookAt 矩阵转换任意 vector (即 100,100,
我目前正在尝试使用 Source SDK 在 C++ 中编写一个 LookAt 函数。我做了一些研究,发现了很多链接,但其中很多都是关于 Unity 或 Glm 的,并且使用的是四元数和旋转矩阵,但我
假设我有以下顶点着色器代码: attribute vec4 vPos; uniform mat4 MVP; uniform mat4 LookAt; void main{ gl_Positi
我一直在尝试编写一个 View 矩阵/查看矩阵,但我的代码中的某个地方有错误,我需要帮助找到它。当我使用我的函数时,我得到一个空白屏幕,而不是我应该得到的三角形的测试 View 。 public st
据我所知,“lookat”方法是在场景中放置/旋转相机的最简单方法之一。所以我在我的光线追踪代码中实现了 ( https://www.scratchapixel.com/lessons/mathema
大家好,我正在尝试做一个使用 glm 库中的 lookAt 的 Camera 类。我有 4 个点,第一个是 eye,即相机在空间中的位置,第二个是 look,即相机正在注视的点,第三个是 upp,用于
我正在努力解决以下问题。我正在处理骨骼动画,我希望(即)玩家的头部跟随空间中的另一个物体。我的上轴是 +Z 我的前轴是 +Y,四元数的大小在 W 中。我尝试使用 gluLookAt 的 mesa 代码
我需要设置场景的初始“lookAt”点,这将是屏幕和控件旋转的中心。如果可能的话,我更愿意设置一个点(或一个对象的位置),而不是旋转 Angular 。 控件是OrbitControl。如果我只是在控
我正在关注 tutorial学习 OpenGL,他们使用 glm::lookAt() 函数来构建 View ,但我无法理解 glm::lookAt() 的工作原理,显然,有没有 GLM 的详细文档。谁
在 SparkAR 中,我想要一个元素(称为 toRotate),它总是看着相机,类似于已经问过的 here (但接受的解决方案对我来说并不令人满意,我没有足够的声誉来回答它的评论)。 问题在于该元素
在 Three.js 中,我希望相机指向 3D 空间中的某个点。 为此,我尝试使用 camera.lookAt 函数,如下所示: camera.lookAt(new THREE.Vector3(-10
我是一名优秀的程序员,十分优秀!