我已经在OpenGL + Python + Pyside中创建了一个场景。旋转对象并使用灯光时,我无法平滑地改变颜色。
当具有相同法线向量的物体的每一侧都从另一侧跳到另一侧时,其每一侧都有一个角度。对于具有其他法线向量的另一侧,此角度是不同的。
我没有旋转相机,而是旋转物体。
我记录了一个GIF,可以显示我在说什么: https://imgur.com/a/zRxdHxB
这是我初始化OpenGL的方式:
somefunctionWithParam(param)
这是我绘制场景的方式:
list_of_dicts = [{"name": "thisisname1", "filebytestotal": 334632,"memorybytes": 5467234},
{"name": "thisisname2", "filebytestotal": 2351, "memorybytes": 324523},
{"name": "thisisname3", "filebytestotal": 2314651, "memorybytes": 2235},
{"name": "thisisname1", "filebytestotal": 13432, "memorybytes": 546534},
{"name": "thisisname1", "filebytestotal": 32342, "memorybytes": 341234}]
# reshape
from collections import defaultdict
dict_of_lists = defaultdict(list)
for obj in list_of_dicts:
dict_of_lists[obj['name']].append({
'bytestotal': obj['filebytestotal'],
'memorybytes': obj['memorybytes'],
})
dict_of_lists
> {'thisisname1': [{'bytestotal': 334632, 'memorybytes': 5467234}, ...], ...}
# and now calculate your averages
for key, totals_list in dict_of_lists.items():
bytes_total = [obj['bytestotal'] for obj in totals_list]
bytes_total_avg = sum(bytes_total) / len(bytes_total)
print(key, bytes_total_avg)
# and the same for memory bytes
我这样设置材料:
for word in corpus:
if (len(wn.synsets(word)) = 2)
return word
灯光位置为def initializeGL(self):
self.qglClearColor(QtGui.QColor.fromRgb(42, 11, 0))
GL.glEnable(GL.GL_DEPTH_TEST)
GL.glEnable(GL.GL_CULL_FACE)
if ENABLE_LIGHT:
GL.glEnable(GL.GL_LIGHTING)
GL.glEnable(GL.GL_LIGHT0)
ambient0 = [0.2, 0.2, 0.2, 1];
diffuse0 = [0.9, 0.9, 0.9, 1];
specular0 = [0.7, 0.7, 0.7, 1];
GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, self.light_pos)
GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, ambient0);
GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, diffuse0);
GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, specular0);
glob_ambient = [0.7, 0.7, 0.7, 0.7];
GL.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, glob_ambient);
GL.glEnable(GL.GL_COLOR_MATERIAL);
GL.glShadeModel(GL.GL_FLAT);
GL.glViewport(0,0, self.width, self.heigh)
GL.glMatrixMode(GL.GL_PROJECTION)
GLU.gluPerspective(40.0, self.width/self.heigh, 0.01, 10000.0);
GL.glMatrixMode(GL.GL_MODELVIEW)
self.initialized = True
眼睛位置为def paintGL(self):
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
GL.glMatrixMode(GL.GL_MODELVIEW);
GL.glLoadIdentity();
GLU.gluLookAt(*self.eyePos.getEyePos())
GL.glTranslated(0.0, 0.0, 0)
GL.glRotated(self.xRot, 1.0, 0.0, 0.0)
GL.glRotated(self.yRot, 0.0, 1.0, 0.0)
GL.glRotated(self.zRot, 0.0, 0.0, 1.0)
if self.scene:
self.scene.renderScene()
GL.glPushMatrix();
GL.glLoadIdentity();
GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, self.light_pos)
GL.glPopMatrix()
GL.glFlush()
对象位置为(...)
GL.glBegin(GL.GL_POLYGON)
GL.glColor4fv([0.25, 0.25, 0.35, 1])
GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, [0.2, 0.2, 0.2, 1])
GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, [0.2, 0.2, 0.2, 1])
GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, [0.2, 0.2, 0.2, 1])
GL.glNormal3fv(self.Normals[n])
(...)
对象的宽度为20个单位,高度为20个单位。
如何摆脱这种烦人的影响?