如何在OpenGL中移动摄像头来捕获6个立方体人脸图像并保存为文件(如下图)?
发布于 2019-12-12 12:48:35
"plugin“是什么意思?我感到困惑的是,你需要如何计算相机的位置和方向向量来捕捉骰子的每一边,或者如何实现观察和透视功能。对于lookat和透视函数,有许多资源可供参考:
Can't understand gluLookAt arguments
gluPerspective parameters- what do they mean?
这些函数通常在许多库中提供,但如果您需要,我将发布我的实现。
计算相机位置和方向/上方向向量,以便正视骰子的每一面。要做到这一点,您必须关心相对于相机和骰子之间的距离的透视FOV(视野)。如果你仔细阅读上面的文章,你可以确定这些函数的参数。
如果你在屏幕上看到每一面,我认为你需要将每个骰子的结果场景组合到一个屏幕(或FBO)并保存它的方法。如果您获得了6组用于lookat和透视的参数,则可以使用glViewPort。
// if pixel per each side : 10
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
//back side draw
glViewPort(0, 10, 10, 10);
//call glulookat & gluperspective or equivalent functions with arguments so that back side of dice drew on your Viewport fully
gluLookAt(...);
gluPerpective(...);
glDrawElements(...);
//up side draw
glViewPort(10, 0, 10, 10);
gluLookAt(...);
gluPerpective(...);
glDrawElements(...);
//left side draw
glViewPort(10, 10, 10, 10);
gluLookAt(...);
gluPerpective(...);
glDrawElements(...);
...
上述代码在结果FBO的每个选定视口中绘制6次。
发布于 2019-12-11 22:37:05
一个使用PyQt5在z=0平面中制作大小为X
,Y
的平面的图像的示例。
Xt = X/2 #center of your camera in X
Yt = Y/2 #center of your camera in Y
dist = math.tan(math.radians(60))*Y/2 #Compute the distance of the campera from plane
#assuming a 60 degree projection
aspect = float(self.width)/float(self.height) #aspect ratio of display
center = QtGui.QVector3D(Xt, Yt, 0) #look at this point
eye = QtGui.QVector3D(Xt, Yt, dist) #Point of Camera in space
up = QtGui.QVector3D(0, 1, 0)
self.modelview = QtGui.QMatrix4x4()
self.modelview.lookAt(eye,center,up) #build modelview matrix with given parameters
self.projection = QtGui.QMatrix4x4()
self.projection.perspective(60.0, aspect, dist*0.0001, dist*10000.0) #build projection matrix
对每个边重复此过程+调整到立方体的z距离应该会产生所需的结果。您只需将结果写入帧缓冲区,并将该缓冲区读取到数组中。
https://stackoverflow.com/questions/59286627
复制相似问题