参照 http://www.chai3d.org/doc/classc_light.html
コード
light2->setPos(cVector3d( 0, 0,0.0)); // position the light source
light2->m_ambient.set(0.8, 0.8, 0.8);
light2->m_diffuse.set(0.8, 0.8, 0.8);
light2->m_specular.set(0.8, 0.8, 0.8);
light2->setDirectionalLight(false);//make a positional light
openglを使用するレンダリングコードは
void cLight::renderLightSource()
{
// check if light source enabled
if (m_enabled == false)
{
// disable OpenGL light source
glDisable(m_glLightNumber);
return;
}
computeGlobalCurrentObjectOnly();
// enable this light in OpenGL
glEnable(m_glLightNumber);
// set lighting components
glLightfv(m_glLightNumber, GL_AMBIENT, m_ambient.pColor());
glLightfv(m_glLightNumber, GL_DIFFUSE, m_diffuse.pColor() );
glLightfv(m_glLightNumber, GL_SPECULAR, m_specular.pColor());
// position the light source in (global) space (because we're not
// _rendered_ as part of the scene graph)
float position[4];
position[0] = (float)m_globalPos.x;
position[1] = (float)m_globalPos.y;
position[2] = (float)m_globalPos.z;
//position[0] = (float)m_localPos.x;
//position[1] = (float)m_localPos.y;
//position[2] = (float)m_localPos.z;
// Directional light source...
if (m_directionalLight) position[3] = 0.0f;
// Positional light source...
else position[3] = 1.0f;
glLightfv(m_glLightNumber, GL_POSITION, (const float *)&position);
// set cutoff angle
glLightf(m_glLightNumber, GL_SPOT_CUTOFF, m_cutOffAngle);
// set the direction of my light beam, if I'm a _positional_ spotlight
if (m_directionalLight == false)
{
cVector3d dir = m_globalRot.getCol0();
float direction[4];
direction[0] = (float)dir.x;
direction[1] = (float)dir.y;
direction[2] = (float)dir.z;
direction[3] = 0.0f;
glLightfv(m_glLightNumber, GL_SPOT_DIRECTION, (const float *)&direction);
}
// set attenuation factors
glLightf(m_glLightNumber, GL_CONSTANT_ATTENUATION, m_attConstant);
glLightf(m_glLightNumber, GL_LINEAR_ATTENUATION, m_attLinear);
glLightf(m_glLightNumber, GL_QUADRATIC_ATTENUATION, m_attQuadratic);
// set exponent factor
glLightf(m_glLightNumber, GL_SPOT_EXPONENT, m_spotExponent);
}
環境全体が均一に照らされるのはなぜですか? 原点 0,0,0 の周りに集光されたライトを取得するにはどうすればよいですか? 私の原点は、グリッドの中央の立方体です。