void GPC_RenderTools::ProcessLighting(RAS_IRasterizer *rasty, bool uselights, const MT_Transform& viewmat) { bool enable = false; int layer= -1; /* find the layer */ if(uselights) { if(m_clientobject) layer = static_cast<KX_GameObject*>(m_clientobject)->GetLayer(); } /* avoid state switching */ if(m_lastlightlayer == layer && m_lastauxinfo == m_auxilaryClientInfo) return; m_lastlightlayer = layer; m_lastauxinfo = m_auxilaryClientInfo; /* enable/disable lights as needed */ if(layer >= 0) enable = applyLights(layer, viewmat); if(enable) EnableOpenGLLights(rasty); else DisableOpenGLLights(); }
/** Walk recursively through a node and switch on all lights. \param node World object to search for lights */ void GLRenderInstance::applyLights(WorldObject& node) { double M[16]; int idx=0; WorldObject::ChildIterator it; for(it=node.childsBegin(); it!=node.childsEnd(); it++) { glPushMatrix(); // Set the local transformation it->second->localTransform().toList(M); glMultMatrixd(M); // Check if the object is a light source... LightSource* lgt = dynamic_cast<LightSource*>(it->second.get()); if (lgt!=0) { // Is it a point light? GLPointLight* pntlgt = dynamic_cast<GLPointLight*>(lgt); if (pntlgt!=0) { if (pntlgt->enabled.getValue()) { pntlgt->applyGL(idx); glEnable(GL_LIGHT0+idx); idx++; } } // Is it a spot light? GLSpotLight* spotlgt = dynamic_cast<GLSpotLight*>(lgt); if (spotlgt!=0) { if (spotlgt->enabled.getValue()) { spotlgt->applyGL(idx); glEnable(GL_LIGHT0+idx); idx++; } } // Is it a distant light? GLDistantLight* dstlgt = dynamic_cast<GLDistantLight*>(lgt); if (dstlgt!=0) { if (dstlgt->enabled.getValue()) { dstlgt->applyGL(idx); glEnable(GL_LIGHT0+idx); idx++; } } } // Search the children for lights applyLights(*(it->second)); glPopMatrix(); } }
void GLRenderInstance::drawScene(WorldObject& root, const mat4d& viewmat) { double M[16]; glLoadIdentity(); if (left_handed) glScaled(-1,1,1); // Default light source // (this is overwritten if there's at least one light in the scene) GLfloat pos[4] = {0,0,1,0}; GLfloat diffuse[4] = {1,1,1,1}; GLfloat specular[4] = {1,1,1,1}; glLightfv(GL_LIGHT0, GL_POSITION, pos); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, specular); glEnable(GL_LIGHT0); // View transformation glRotated(180,0,1,0); viewmat.toList(M, false); glMultMatrixd(M); // Apply the light sources applyLights(root); // Draw the scene if (draw_coordsys) drawCoordSystem(); defaultmat.applyGL(); if (drawNode(root, false)) { // There have been objects that use blending, so draw them now... glDepthMask(GL_FALSE); drawNode(root, true); glDepthMask(GL_TRUE); } }
void Animate(void) { // limpa a janela glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Reset the matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if (!arcCam){ //MOVIMENTO E ROTAÇÃO DA CAMARA COM TECLADO E RATO // Move the camera to our location in space glRotatef(cam->getXRot(), 1.0f, 0.0f, 0.0f); // Rotate our camera on the x-axis (looking up and down) glRotatef(cam->getYRot(), 0.0f, 1.0f, 0.0f); // Rotate our camera on the y-axis (looking left and right) // Translate the ModelView matrix to the position of our camera - everything should now be drawn relative // to this position! glTranslatef(-cam->getXPos(), -cam->getYPos(), -cam->getZPos()); } else{ //Camara orbital arcCamX = arcCamRadius * sin(arcCamAngle); arcCamZ = arcCamRadius * cos(arcCamAngle); gluLookAt(arcCamX, 30, arcCamZ, 0, 0, 0, 0, 1, 0); arcCamAngle += 0.01; if (arcCamAngle > 2 * PI){ arcCamAngle = 0; } } if (spinMode) { //Controla a velocidade da simulação if (holdingMoreSimulationSpeed && simulationSpeed > 15){ simulationSpeed -= simulationSpeedChangeAcceleration; simulationSpeedChangeAcceleration += 0.1; } if (holdingLessSimulationSpeed){ simulationSpeed += simulationSpeedChangeAcceleration; simulationSpeedChangeAcceleration += 0.1; if (simulationSpeed > 5000){ spinMode = false; simulationSpeed = 5000; } } //Atualiza a posição dos planetas e luas UpdatePlanetas(); UpdateLuas(); } applyLights(); glViewport(0, 0, width, height); ResizeWindow(width, height); glEnable(GL_TEXTURE_2D); //Desenha os planetas e luas DrawPlanetas(false); DrawLuas(); //Desenhar displayLists de estrelas glCallList(displayListIndex); glPushMatrix(); //Mover oara posição da camara if (!arcCam){ glTranslatef(cam->getXPos(), 0, cam->getZPos()); } else{ glTranslatef(arcCamX, arcCamY, arcCamZ); } //Desenhar a skybox na posição da camara - a skybox acompanha o movimento da camara DrawSkybox(); glPopMatrix(); //Desenhar anéis de saturno DrawRings(); //Desenhar minimap DrawMinimap(); glfwSwapBuffers(); // Swap the buffers to display the scene (so we don't have to watch it being drawn!) }