简体   繁体   English

OpenGL 3D点精灵相机矩阵

[英]OpenGL 3D point sprites camera matrix

I am having problems with placing point sprites in 3D space because of the matrices I am using. 由于使用的矩阵,我在将点精灵放置在3D空间中时遇到问题。 The problem is in my vertex shader (I have omitted the unnecessary parts): 问题出在我的顶点着色器中(我省略了不必要的部分):

#version 330

in vec3 position; // 3d position of the particle
uniform mat4 vp_matrix; // the projection and view matrices from the camera

void main()
{
    gl_Position = vp_matrix * vec4(position, 1);
}

Currently I am uploading the view and projection matrices to this matrix uniform. 目前,我正在将视图和投影矩阵上载到此矩阵统一中。 But this leads to the particles to rotate and move around in unexpected ways when the camera moves (ie differently from the other objects in my scene). 但这会导致粒子在相机移动时(即与我场景中的其他对象不同)旋转并以意外方式移动。

Does it make sense to apply the projection matrix to a point sprite? 将投影矩阵应用于点精灵是否有意义? Or should I only be applying the view matrix? 还是只应应用视图矩阵? Should I be applying the entire view matrix, or just the translation and/or rotation? 我应该应用整个视图矩阵,还是仅应用平移和/或旋转?

My apologies, turns out this "strange" movement was because of a wrong offset where I had wrote 3 floating point values instead of 2. 我很抱歉,这是“奇怪的”运动是由于错误的偏移量造成的,在此我写了3个浮点值而不是2。

But in case anyone is wondering what matrix to apply to point sprites, @Rabbid76 is correct, you must apply the projection matrix to it, and you must also apply the view matrix. 但是,如果有人想知道将什么矩阵应用于点精灵,@ Rabbid76是正确的,则必须对其应用投影矩阵,并且还必须应用视图矩阵。 This means you DO apply both the view and projection matrices from the camera; 这意味着您必须同时应用摄像机的视图矩阵和投影矩阵。 this is because the camera's rotation and translation DOES need to affect points. 这是因为相机的旋转和平移确实需要影响点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM