SimpleShape::SimpleShape(vec3 position, vec3 aColour, vec3 dColour, vec3 sColour, float shine) { setPosition(position); setAmbientColour(aColour); setDiffuseColour(dColour); setSpecularColour(sColour); setShininess(shine); }
void DeferredLight::updateFromParent() { setAttenuation(parentLight->getAttenuationConstant(), parentLight->getAttenuationLinear(), parentLight->getAttenuationQuadric()); setSpecularColour(parentLight->getSpecularColour()); if (getCastChadows()) { ENABLE_BIT(permutation,LightMaterialGenerator::MI_SHADOW_CASTER); } else { DISABLE_BIT(permutation, LightMaterialGenerator::MI_SHADOW_CASTER); } }
void Light::enterScene(Scene* scene) { VisualComponent::enterScene(scene); light = createLight(); setEnabled(isEnabled()); setDiffuseColour(getDiffuseColour()); setSpecularColour(getSpecularColour()); setAttenuation(getAttenuation()); getSceneNode()->attachObject(light); }
void Viewer::draw_trackball_circle() { auto w = width(); auto h = height(); setDiffuseColour(QColor(0.0, 0.0, 0.0)); setSpecularColour(QColor(0.0, 0.0, 0.0)); // Set orthographic Matrix QMatrix4x4 orthoMatrix; orthoMatrix.ortho(0.0, (float)w, 0.0, (float)h, -0.1, 0.1); // Translate the view to the middle QMatrix4x4 transformMatrix; transformMatrix.translate(w/2.0, h/2.0, 0.0); // Bind buffer object mCircleBufferObject.bind(); sphereShaders.setAttributeBuffer("vert", GL_FLOAT, 0, 3); sphereShaders.setUniformValue(mvpMatrixLoc, orthoMatrix * transformMatrix); sphereShaders.setUniformValue(flatLoc, true); // Draw buffer glDrawArrays(GL_LINE_LOOP, 0, 40); }
void App::createScene() { #pragma region Plane // Define the mathematical plane Ogre::Plane plane(Vector3::UNIT_Y, 0); // Create the plane into memory Ogre::MeshManager::getSingleton().createPlane( "plane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 500, 500, // size 25, 25, // how many quads are used to make the plane true, 1, 5, 5, Vector3::UNIT_Z); // Create an instance of the plane auto planeEnt = mSceneMgr->createEntity("PlaneEntity", "plane"); planeEnt->setMaterialName("Examples/BeachStones"); // Create a node for the plane and attach he plane to it mSceneMgr->getRootSceneNode()->createChildSceneNode("planeNode")->attachObject(planeEnt); #pragma endregion #pragma region Lights // Directional auto sunlight = mSceneMgr->createLight("sun"); sunlight->setType(Ogre::Light::LT_DIRECTIONAL); sunlight->setDirection(Ogre::Vector3(0, -1, -1)); sunlight->setDiffuseColour(Ogre::ColourValue(.30, .30, 0)); sunlight->setSpecularColour(Ogre::ColourValue(.30, .30, 0)); // Spotlight auto spotlight = mSceneMgr->createLight("spotlight"); spotlight->setType(Ogre::Light::LT_SPOTLIGHT); spotlight->setSpotlightRange( Ogre::Degree(5.0f), // inner angle Ogre::Degree(15.0f), // outer angle 0.0f); // falloff spotlight->setDiffuseColour(Ogre::ColourValue(1.0f, 0.0f, 0.0f)); // Sphere to visualize the spotlights source auto sphereEnt = mSceneMgr->createEntity("sphere", "sphere.mesh"); sphereEnt->setMaterialName("Examples/checker"); auto sphereNode = mSceneMgr->getSceneNode("planeNode")->createChildSceneNode("spotlightNode"); sphereNode->attachObject(sphereEnt); sphereNode->attachObject(spotlight); sphereNode->scale(0.02f, 0.02f, 0.02f); sphereNode->translate(0.0f, 15.0f, 0.0f); sphereNode->lookAt(Ogre::Vector3(0, 0, 0), Ogre::Node::TS_PARENT); #pragma endregion #pragma region Entities std::array<Ogre::Entity*, 6> entities; auto entParentNode = mSceneMgr->getSceneNode("planeNode")->createChildSceneNode("entParentNode"); float angleOffset = 360.0f / 6.0f; float radius = 30.0f; for (int i = 0; i < entities.size(); ++i) { auto e = mSceneMgr->createEntity("Sinbad.mesh"); entParentNode->createChildSceneNode(Ogre::Vector3( radius * Math::Cos(Math::DegreesToRadians(angleOffset * i)), // x = r cos(t) 6.75f, // y = height radius * Math::Sin(Math::DegreesToRadians(angleOffset * i)))) // z = r sin(t) ->attachObject(e); } // Barrel auto barrel = mSceneMgr->createEntity("barrel.mesh"); mSceneMgr->getSceneNode("planeNode")->createChildSceneNode("barrel", Ogre::Vector3(0, 2.5f, 0))->attachObject(barrel); #pragma endregion // Skybox mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 5000, false); }
Node::NodeSP SceneLoader::__loadLight(const QDomElement& og_component, Node::NodeSP dt_node) { Node::NodeSP node = dt_node; if ( !og_component.isNull() ) { QString name = og_component.attribute(SL_NAME); if ( node == nullptr ) { node = mScene->addChildNode(new Node(name + "_node")); QDomElement pos = og_component.firstChildElement(SL_POS); QDomElement dir = og_component.firstChildElement(SL_LIGHT_DIRECTION); node->setPosition(pos.attribute(SL_X).toFloat(), pos.attribute(SL_Y).toFloat(), pos.attribute(SL_Z).toFloat()); node->setDirection(Ogre::Vector3(dir.attribute(SL_X).toFloat(), dir.attribute(SL_Y).toFloat(), dir.attribute(SL_Z).toFloat())); } //add light component auto light = node->addComponent<LightComponent>(new LightComponent(name)); auto og_light = light->getOgreLight(); QDomElement colour_diffuse = og_component.firstChildElement(SL_LIGHT_DIFFUSE); QDomElement colour_specular = og_component.firstChildElement(SL_LIGHT_SPECULAR); QDomElement light_attenuation = og_component.firstChildElement(SL_LIGHT_ATTENUATION); //set light attributes og_light->setDiffuseColour(colour_diffuse.attribute(SL_COLOUR_R).toFloat(), colour_diffuse.attribute(SL_COLOUR_G).toFloat(), colour_diffuse.attribute(SL_COLOUR_B).toFloat()); og_light->setSpecularColour(colour_specular.attribute(SL_COLOUR_R).toFloat(), colour_specular.attribute(SL_COLOUR_G).toFloat(), colour_specular.attribute(SL_COLOUR_B).toFloat()); og_light->setAttenuation(light_attenuation.attribute(SL_LIGHT_ATTENUATION_RANGE).toFloat(), light_attenuation.attribute(SL_LIGHT_ATTENUATION_CONSTANT).toFloat(), light_attenuation.attribute(SL_LIGHT_ATTENUATION_LINEAR).toFloat(), light_attenuation.attribute(SL_LIGHT_ATTENUATION_QUADRATIC).toFloat()); QString light_type = og_component.attribute(SL_LIGHT_TYPE); if ( light_type == SL_LIGHT_TYPE_POINT ) { og_light->setType(Ogre::Light::LT_POINT); } else if ( light_type == SL_LIGHT_TYPE_DIRECTIONAL ) { og_light->setType(Ogre::Light::LT_DIRECTIONAL); } else if ( light_type == SL_LIGHT_TYPE_SPOT ) { og_light->setType(Ogre::Light::LT_SPOTLIGHT); QDomElement light_range = og_component.firstChildElement(SL_LIGHT_RANGE); og_light->setSpotlightRange(Ogre::Radian(light_range.attribute(SL_LIGHT_RANGE_INNER).toFloat()), Ogre::Radian(light_range.attribute(SL_LIGHT_RANGE_OUTER).toFloat()), light_range.attribute(SL_LIGHT_RANGE_FALLOFF).toFloat()); } QString cast_shadows = og_component.attribute(SL_CAST_SHADOWS); if ( cast_shadows == SL_TRUE ) { light->setCastShadows(true); } else if ( cast_shadows == SL_FALSE ) { light->setCastShadows(false); } light->enable(); } return node; }