当前位置: 首页>>代码示例>>C++>>正文


C++ LightSource类代码示例

本文整理汇总了C++中LightSource的典型用法代码示例。如果您正苦于以下问题:C++ LightSource类的具体用法?C++ LightSource怎么用?C++ LightSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LightSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: pushStateSet

void ScreenMVCullVisitor::apply(LightSource& node)
{
    // push the node's state.
    StateSet* node_state = node.getStateSet();
    if(node_state)
        pushStateSet(node_state);

    StateAttribute* light = node.getLight();
    if(light)
    {
        if(node.getReferenceFrame() == osg::LightSource::RELATIVE_RF)
        {
            RefMatrix& matrix = *getModelViewMatrix();
            addPositionedAttribute(&matrix,light);
        }
        else
        {
            // relative to absolute.
            addPositionedAttribute(0,light);
        }
    }

    handle_cull_callbacks_and_traverse(node);

    // pop the node's state off the geostate stack.    
    if(node_state)
        popStateSet();
}
开发者ID:johnmangan,项目名称:calvr,代码行数:28,代码来源:ScreenMVCullVisitor.cpp

示例2: render_direct

//Outputs the color of the object as enlightened by at the point where `ray` hits it.
rt::color Object::render_direct(const Ray & ray, Scene & scene, const LightSource & light_source) {
    rt::color basic = compose(light_source.get_color(), color);
    Impact imp = get_impact(ray);
    Ray to_light(imp.point, light_source.get_origin());
    double scalar = -(ray.get_direction() | imp.normale);
    if (((light_source.get_origin()-imp.point) | imp.normale) <= 0) {
        return rt::color::BLACK;
    }
    std::list<Object *> others;
    Object* interceptor = scene.get_interceptor(to_light, &others);
    // In case there has been mixups due to rounding errors and the object catches
    // its own ray back to the light when it shouldn't (which is NOT always the case)
    // detect it
    if (interceptor) {
        if (interceptor != this && interceptor->intersects(ray) < (imp.point - light_source.get_origin()).norm())
            return rt::color::BLACK;
        if (intersects(to_light) >= OWNRAY_EPSILON)
            return rt::color::BLACK;
        if (others.size() > 1)
            return rt::color::BLACK;
    }
    return rt::color(
            static_cast<unsigned char>(scalar*basic.get_red()),
            static_cast<unsigned char>(scalar*basic.get_green()),
            static_cast<unsigned char>(scalar*basic.get_blue())
        );
}
开发者ID:laarmen,项目名称:ray_tracer,代码行数:28,代码来源:object.cpp

示例3: Thing

LightSource::LightSource(LightSource const& original)
  : Thing(original), impl(new Impl())
{
  impl->direction = original.get_light_direction();
  impl->level = original.get_light_level();
  impl->color = original.get_light_color();
  impl->max_strength = original.get_max_light_strength();
  impl->lit = original.is_lit();
}
开发者ID:chrisfont,项目名称:MetaHack,代码行数:9,代码来源:LightSource.cpp

示例4: apply

   virtual void apply( LightSource &node )
   {
      if( node.getStateSet() )
      {
         apply( *node.getStateSet() );
      }

      ++_numInstancedLightSources;
      _lightSourceSet.insert( &node );
      traverse( node );
   }
开发者ID:forry,项目名称:Lexoanim,代码行数:11,代码来源:SceneInfoDialog.cpp

示例5: qDebug

void Canvas::setup(int bots, int lights, QVector<QPointF> botLoc, QVector<QPointF> lightLoc, int **matrix) {

    this->addLine(0,0,400,400);
    if (bots == 0)
    {
        bots = 1;
        qDebug() << "ERROR: Invalid number of robots. Defaulting to 1.";
    }
    if (lights == 0)
    {
        lights = 1;
        qDebug() << "ERROR: Invalid number of lights. Defaulting to 1.";
    }

    if (botLoc.size() < bots)
    {
        botLoc.clear();
        botLoc = defaultBotLoc(bots);
        qDebug() << "ERROR: Not enough robot locations. Using the default locations.";
    }
    if (lightLoc.size() < bots)
    {
        lightLoc.clear();
        lightLoc = defaultLightLoc(lights);
        qDebug() << "ERROR: Not enough light locations. Using the default locations.";
    }
    m_robotManager->setKMatrix(matrix);
    Robot* robot;
    for(int i = 0; i < bots; i++) {
        robot = new Robot();
        robot->setTransformOriginPoint(ROBOT_HEIGHT, ROBOT_HEIGHT);

        robot->setPos(botLoc[i]);

        createRobot(robot);
    }
    LightSource *light;
    for (int i = 0; i < lights; i++)
    {
        light = new LightSource();
        light->setPos(lightLoc[i]);
        // TODO: take intensity from a file
        light->setIntensity(100);
        createLight(light);
    }
}
开发者ID:bmdelaune,项目名称:452-p4,代码行数:46,代码来源:canvas.cpp

示例6: lightsource_process

CAMLprim value lightsource_process(value record_lightsource,
                                   value list_polygon_objects,
                                   value polygon_view) {
  CAMLparam3(record_lightsource, list_polygon_objects, polygon_view);
  CAMLlocal5(polygon_prev_head, list_polygon_head, vector_prev_head,
             list_vector_head, tmp_polygon);
  CAMLlocal1(tmp_vector);
  LightSource l = LightSource(Vector_val(Field(record_lightsource, 0)),
                              Double_val(Field(record_lightsource, 1)),
                              Double_val(Field(record_lightsource, 2)));
  std::vector<Polygon> tmp_polygon_list = std::vector<Polygon>();
  polygon_list_to_std_vector(list_polygon_objects, &tmp_polygon_list);
  std::vector<Vector> tmp_vector_list = std::vector<Vector>();
  vector_list_to_std_vector(Field(polygon_view, 0), &tmp_vector_list);
  Polygon polygon = Polygon(tmp_vector_list);
  // auto start = std::chrono::steady_clock::now();
  std::vector<Polygon> list_polygon = l.process(tmp_polygon_list);
  // auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
  //     std::chrono::steady_clock::now() - start);
  // printf("--> %lld\n", duration.count());
  polygon_prev_head = Val_unit;
  for (Polygon p : list_polygon) {
    vector_prev_head = Val_unit;
    for (Vector v : p.get_vertices()) {
      tmp_vector = caml_alloc_small(2, Double_array_tag);
      Double_field(tmp_vector, 0) = v.x;
      Double_field(tmp_vector, 1) = v.y;
      list_vector_head = caml_alloc_small(2, 0);
      Field(list_vector_head, 0) = tmp_vector;
      Field(list_vector_head, 1) = vector_prev_head;
      vector_prev_head = list_vector_head;
    }
    tmp_polygon = caml_alloc_small(1, 0);
    Field(tmp_polygon, 0) = list_vector_head;

    list_polygon_head = caml_alloc_small(2, 0);
    Field(list_polygon_head, 0) = tmp_polygon;
    Field(list_polygon_head, 1) = polygon_prev_head;
    polygon_prev_head = list_polygon_head;
  }
  CAMLreturn(list_polygon_head);
}
开发者ID:SodaCookie,项目名称:amnesia-engine,代码行数:42,代码来源:lightsource.cpp

示例7: glLightfv

    void OpenGLSceneRenderer::showLight(const LightSource& l, const SkyDragonEngineOptions& engineOptions) {

        float p[4];
        float a[4];
        float d[4];
        float s[4];

        for (int i = 0; i < 4; i++) {
            p[i] = l.GetPosition()[i];
            a[i] = l.GetAmbient()[i];
            d[i] = l.GetDiffuse()[i];
            s[i] = l.GetSpecular()[i];
        }

        glLightfv(_glLightSources[_curLight], GL_POSITION, p);
        glLightfv(_glLightSources[_curLight], GL_AMBIENT, a);
        glLightfv(_glLightSources[_curLight], GL_DIFFUSE, d);
        glLightfv(_glLightSources[_curLight], GL_SPECULAR, s);

        _curLight++;
    }
开发者ID:vviswanathan,项目名称:SkyDragon-Engine,代码行数:21,代码来源:OpenGLSceneRenderer.cpp

示例8: Light

LightSource* ChessUtils::createLightSource(StateSet* stateSet, int lightNumber,	
	Vec4 position, Vec3 direction,	
	float spotCutoff, float spotExponent,
	float constanteAttenuation,
	Vec4 ambientLight, Vec4 diffuseLight, Vec4 specularLight) {
	Light* light = new Light();
	light->setLightNum(lightNumber);
	light->setPosition(position);
	light->setDirection(direction);
	light->setAmbient(ambientLight);
	light->setDiffuse(diffuseLight);
	light->setSpecular(specularLight);
	light->setConstantAttenuation(constanteAttenuation);	
	light->setSpotCutoff(spotCutoff);
	light->setSpotExponent(spotExponent);

	LightSource* lightS = new LightSource();
	lightS->setLight(light);
	lightS->setLocalStateSetModes(osg::StateAttribute::ON);
	lightS->setStateSetModes(*stateSet, osg::StateAttribute::ON);	

	return lightS;
}
开发者ID:carlosmccosta,项目名称:AR-Chess,代码行数:23,代码来源:ChessUtils.cpp

示例9: ASSERT

bool SVGFESpecularLightingElement::setFilterEffectAttribute(FilterEffect* effect, const QualifiedName& attrName)
{
    FESpecularLighting* specularLighting = static_cast<FESpecularLighting*>(effect);

    if (attrName == SVGNames::lighting_colorAttr) {
        RenderObject* renderer = this->renderer();
        ASSERT(renderer);
        ASSERT(renderer->style());
        return specularLighting->setLightingColor(renderer->style()->svgStyle().lightingColor());
    }
    if (attrName == SVGNames::surfaceScaleAttr)
        return specularLighting->setSurfaceScale(m_surfaceScale->currentValue()->value());
    if (attrName == SVGNames::specularConstantAttr)
        return specularLighting->setSpecularConstant(m_specularConstant->currentValue()->value());
    if (attrName == SVGNames::specularExponentAttr)
        return specularLighting->setSpecularExponent(m_specularExponent->currentValue()->value());

    LightSource* lightSource = const_cast<LightSource*>(specularLighting->lightSource());
    SVGFELightElement* lightElement = SVGFELightElement::findLightElement(*this);
    ASSERT(lightSource);
    ASSERT(lightElement);
    ASSERT(effect->filter());

    if (attrName == SVGNames::azimuthAttr)
        return lightSource->setAzimuth(lightElement->azimuth()->currentValue()->value());
    if (attrName == SVGNames::elevationAttr)
        return lightSource->setElevation(lightElement->elevation()->currentValue()->value());
    if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr || attrName == SVGNames::zAttr)
        return lightSource->setPosition(effect->filter()->resolve3dPoint(lightElement->position()));
    if (attrName == SVGNames::pointsAtXAttr || attrName == SVGNames::pointsAtYAttr || attrName == SVGNames::pointsAtZAttr)
        return lightSource->setPointsAt(effect->filter()->resolve3dPoint(lightElement->pointsAt()));
    if (attrName == SVGNames::specularExponentAttr)
        return lightSource->setSpecularExponent(lightElement->specularExponent()->currentValue()->value());
    if (attrName == SVGNames::limitingConeAngleAttr)
        return lightSource->setLimitingConeAngle(lightElement->limitingConeAngle()->currentValue()->value());

    ASSERT_NOT_REACHED();
    return false;
}
开发者ID:darktears,项目名称:blink-crosswalk,代码行数:39,代码来源:SVGFESpecularLightingElement.cpp

示例10: jsonToColor

void Config::load(SceneRenderer * sceneRenderer, Manager * manager) {
    Json::Value root;   // will contains the root value after parsing.
	Json::Reader reader;

	std::ifstream file;
	file.open(fileName);
    bool parsingSuccessful = reader.parse(file, root, false);
	file.close();
	if(!parsingSuccessful) {
		// report to the user the failure and their locations in the document.
		System::Console::WriteLine("Failed to parse configuration\n");
		System::Console::WriteLine(gcnew System::String(reader.getFormatedErrorMessages().c_str()));
		throw std::runtime_error("Failed to parse configuration file: "+fileName);
	}

	Json::Value sceneJSON = root.get("scene", NULL);
	Scene * scene = sceneRenderer->getScene();
	Json::Value bgColorJSON = sceneJSON.get("backgroundColor", NULL);
	if(bgColorJSON != NULL) {
		scene->setBackgroundColor(jsonToColor(bgColorJSON));
	}

	Json::Value lightsJSON = sceneJSON.get("lights", NULL);
	if(lightsJSON != NULL) {
		Json::Value::Members lightsName = lightsJSON.getMemberNames();
		for(std::vector<std::string>::iterator it = lightsName.begin(); it != lightsName.end(); it++) {
			std::string lightName = *it;
			Json::Value lightJSON = lightsJSON[lightName];
			RGBColor lightColor = jsonToColor(lightJSON["color"]);
			LightSource * light;
			std::string lightTypeStr = lightJSON["type"].asString();
			if(lightTypeStr == "AmbientLightSource") {
				light = new AmbientLightSource(lightColor);
			} else if(lightTypeStr == "PointLightSource") {
				light = new PointLightSource(jsonToP3(lightJSON["position"]), lightColor);
				Json::Value specularCoefJSON = lightJSON.get("specularCoef", NULL);
				PointLightSource * pLight = static_cast<PointLightSource*>(light);
				if(specularCoefJSON != NULL) {
					pLight->setSpecularCoef(specularCoefJSON.asDouble());
				}
				Json::Value specularExpJSON = lightJSON.get("specularExponent", NULL);
				if(specularExpJSON != NULL) {
					pLight->setSpecularExponent(specularExpJSON.asDouble());
				}
			}
			Json::Value diffuseCoefJSON = lightJSON.get("diffuseCoef", NULL);
			if(diffuseCoefJSON != NULL) {
				light->setDiffuseCoef(diffuseCoefJSON.asDouble());
			}
			//scene->addLightSource(light);
			manager->getLightSources()->add(lightName, light, lightTypeStr);
		}
	}

	Json::Value objectsJSON = sceneJSON.get("objects", NULL);
	if(objectsJSON != NULL) {
		Json::Value::Members objectsName = objectsJSON.getMemberNames();
		for(std::vector<std::string>::iterator it = objectsName.begin(); it != objectsName.end(); it++) {
			std::string objectName = *it;
			Json::Value object3DJSON = objectsJSON[objectName];
			Object3D * object3D;
			std::string oject3DTypeStr = object3DJSON["type"].asString();
			if(oject3DTypeStr == "Sphere") {
				object3D = new Sphere(jsonToP3(object3DJSON["center"]),
									  object3DJSON["radius"].asDouble());
			} else if(oject3DTypeStr == "Plane") {
				
				if(object3DJSON.get("u", NULL) != NULL) {
					object3D = new Plane(jsonToP3(object3DJSON["p"]),
									 jsonToP3(object3DJSON["u"]),
									 jsonToP3(object3DJSON["v"]));
				} else {
					object3D = new Plane(jsonToP3(object3DJSON["p"]),
										 jsonToP3(object3DJSON["normal"]));
				}
			} else if(oject3DTypeStr == "Triangle") {
				object3D = new Triangle(jsonToP3(object3DJSON["A"]),
									    jsonToP3(object3DJSON["B"]),
										jsonToP3(object3DJSON["C"]));
			}
			//scene->addObject3D(object3D);
			manager->getObjects3D()->add(objectName, object3D, oject3DTypeStr);
		}
	}

	Json::Value polyhedraJSON = sceneJSON.get("polyhedra", NULL);
	if(polyhedraJSON != NULL) {
		Json::Value::Members polyhedraName = polyhedraJSON.getMemberNames();
		for(std::vector<std::string>::iterator it = polyhedraName.begin(); it != polyhedraName.end(); it++) {
			std::string objectName = *it;
			Json::Value polyhedronJSON = polyhedraJSON[objectName];
			Polyhedron * polyhedron;
			std::string polyhedronTypeStr = polyhedronJSON["type"].asString();
			if(polyhedronTypeStr == "Parallelepiped") {
				polyhedron = new Parallelepiped(jsonToP3(polyhedronJSON["A"]),
												jsonToP3(polyhedronJSON["B"]),
												jsonToP3(polyhedronJSON["C"]),
												jsonToP3(polyhedronJSON["D"]));
			} else if(polyhedronTypeStr == "Maya") {
				std::vector<Triangle*> triangles;
//.........这里部分代码省略.........
开发者ID:Tug,项目名称:RayTracer,代码行数:101,代码来源:Config.cpp

示例11: Group

Node* Universe::createUniverse() {
	// we need the scene's state set to enable the light for the entire scene
	Group *scene = new Group();
	lightStateSet = scene->getOrCreateStateSet();
	lightStateSet->ref();
	
	// create a light
	LightSource *lightSource = new LightSource();
	lightSource->setLight(createLight(Vec4(0.9, 0.9, 0.9, 1.0)));
	// enable the light for the entire scene
	lightSource->setLocalStateSetModes(StateAttribute::ON);
	lightSource->setStateSetModes(*lightStateSet, StateAttribute::ON);
	
	lightTransform = new PositionAttitudeTransform();
	lightTransform->addChild(lightSource);
	lightTransform->setPosition(Vec3(3, 0, 0));
	
	// create objects
	try {
		CrfGeometry* crfGeometry = new CrfGeometry();
		
               
                    // Stars
                    Material *material = new Material();
                    material->setEmission(Material::FRONT, Vec4(1.0, 1.0, 1.0, 1.0));
                    material->setAmbient(Material::FRONT,  Vec4(1.0, 1.0, 1.0, 1.0));
                    material->setShininess(Material::FRONT, 25.0);

                    crfGeometry->prepareMaterial(material);
                
                if(_starfield_enabled) {
                    for (int i = 0; i < 6; i++) {
                            starField[i] = crfGeometry->createPlane(_diameter, "./textures/stars.jpg", true);
                            scene->addChild(starField[i]);
                    }
                    
                    this->positionStarField();
                }
                
                if(_spacewarp_enabled) 
                    scene->addChild(this->createSpacewarp());
                    
		// sun
		crfGeometry->prepareMaterial(material);
		sun = crfGeometry->createSphere(300, "./textures/sunmap.jpg", false);
		
		// planets
		Material *material2 = new Material();
		material2->setEmission(Material::FRONT, Vec4(0.1, 0.1, 0.1, 1.0));
		crfGeometry->prepareMaterial(material2);
		mercury= crfGeometry->createSphere(3.8, "./textures/mercurymap.jpg", false);
		venus = crfGeometry->createSphere(9.5, "./textures/venusmap.jpg", false);
		earth = crfGeometry->createSphere(10, "./textures/earthmap1k.jpg", false);
		emoon = crfGeometry->createSphere(2, "./textures/moonmap1k.jpg", false);
		mars = crfGeometry->createSphere(5.3, "./textures/mars_1k_color.jpg", false);
		jupiter = crfGeometry->createSphere(109, "./textures/jupitermap.jpg", false);
		saturn = crfGeometry->createSphere(91, "./textures/saturnmap.jpg", false);
	} catch (char *e) {
		std::cerr << e;
	}
        
        
	
	lightTransform->addChild(sun);
	scene->addChild(lightTransform);
	scene->addChild(mercury);
	scene->addChild(venus);
	earth->addChild(emoon);
	scene->addChild(earth);
	scene->addChild(mars);
	scene->addChild(jupiter);
	scene->addChild(saturn);
	
	return scene;
}
开发者ID:bhulliger,项目名称:CRF,代码行数:75,代码来源:Universe.cpp

示例12: Plane


//.........这里部分代码省略.........
		CAR_CAMERA_DISTANCE);
	_carCamera->setCenter(_car->getPosition()->getX(), _car->getPosition()->getY(), _car->getPosition()->getZ());
	//_carCamera->setUp(_car->getSpeed()->getX(), _car->getSpeed()->getY(), _car->getSpeed()->getZ());
	_carCamera->setUp(0, 0, 1);
	_carCamera->update(60, 1, 0.01, 150);


	//Constructing light sources

	Vela* vela1 = new Vela();
	vela1->setPosition(-6, 6, 1.6);
	_gameObjects.push_back(vela1);

	Vela* vela2 = new Vela();
	vela2->setPosition(6, 6, 1.6);
	_gameObjects.push_back(vela2);

	Vela* vela3 = new Vela();
	vela3->setPosition(0, -6, 1.6);
	_gameObjects.push_back(vela3);

	Vela* vela4 = new Vela();
	vela4->setPosition(-10, -10, 1.6);
	_gameObjects.push_back(vela4);

	Vela* vela5 = new Vela();
	vela5->setPosition(10, -10, 1.6);
	_gameObjects.push_back(vela5);

	Vela* vela6 = new Vela();
	vela6->setPosition(0, 14, 1.6);
	_gameObjects.push_back(vela6);


	LightSource* daylight = new LightSource(0);
	daylight->setPosition(0, 0, 10, 0);
	daylight->setAmbient(0.5, 0.5, 0.5, 1);
	daylight->setDiffuse(1, 1, 1, 1);
	daylight->setSpecular(1, 1, 1, 1);
	_lightSources.push_back(daylight);

	LightSource* candle1 = new LightSource(1);
	candle1->setPosition(-6, 6, 1, 1);
	candle1->setAmbient(0.7, 0.7, 0.7, 1);
	candle1->setDiffuse(1, 1, 1, 1);
	candle1->setSpecular(1, 1, 1, 1);
	candle1->setAttenuation(1, 0, 0.1);
	_lightSources.push_back(candle1);

	LightSource* candle2 = new LightSource(2);
	candle2->setPosition(6, 6, 1, 1);
	candle2->setAmbient(0.7, 0.7, 0.7, 1);
	candle2->setDiffuse(1, 1, 1, 1);
	candle2->setSpecular(1, 1, 1, 1);
	candle2->setAttenuation(1, 0, 0.1);
	_lightSources.push_back(candle2);

	LightSource* candle3 = new LightSource(3);
	candle3->setPosition(0, -6, 1, 1);
	candle3->setAmbient(0.7, 0.7, 0.7, 1);
	candle3->setDiffuse(1, 1, 1, 1);
	candle3->setSpecular(1, 1, 1, 1);
	candle3->setAttenuation(1, 0, 0.1);
	_lightSources.push_back(candle3);

	LightSource* candle4 = new LightSource(4);
	candle4->setPosition(-10, -10, 1, 1);
	candle4->setAmbient(0.7, 0.7, 0.7, 1);
	candle4->setDiffuse(1, 1, 1, 1);
	candle4->setSpecular(1, 1, 1, 1);
	candle4->setAttenuation(1, 0, 0.1);
	_lightSources.push_back(candle4);

	LightSource* candle5 = new LightSource(5);
	candle5->setPosition(10, -10, 1, 1);
	candle5->setAmbient(0.7, 0.7, 0.7, 1);
	candle5->setDiffuse(1, 1, 1, 1);
	candle5->setSpecular(1, 1, 1, 1);
	candle5->setAttenuation(1, 0, 0.1);
	_lightSources.push_back(candle5);

	LightSource* candle6 = new LightSource(6);
	candle6->setPosition(0, 15, 1, 1);
	candle6->setAmbient(0.7, 0.7, 0.7, 1);
	candle6->setDiffuse(1, 1, 1, 1);
	candle6->setSpecular(1, 1, 1, 1);
	candle6->setAttenuation(1.0, 0, 0.1);
	_lightSources.push_back(candle6);

	LightSource* spotlight = new LightSource(7);
	spotlight->setAmbient(0.8, 0.8, 0.8, 1);
	spotlight->setDiffuse(1, 1, 1, 1);
	spotlight->setSpecular(1, 1, 1, 1);
	spotlight->setExponent(new GLfloat(5));
	spotlight->setCutOff(new GLfloat(40));
	spotlight->setAttenuation(0, 0.6, 0.3);
	_lightSources.push_back(spotlight);

	initIsDone = true;
}
开发者ID:Danisodu,项目名称:Computer-Graphics,代码行数:101,代码来源:GameManager.cpp

示例13: printf

void InstantRadiosity::castIndirect(RayTracer *rt, MeshWithColors *scene, const LightSource& ls, int num)
{
    // If the caller requests a different number of lights than before, reallocate everything.
    // (This is OpenGL resource management stuff, don't touch unless you specifically need to)
    if (m_indirectLights.size() != num)
    {
        printf("Deleting %i indirect light sources.\n", num);
        for (auto iter = m_indirectLights.begin(); iter != m_indirectLights.end(); iter++)
            iter->freeShadowMap();
        m_indirectLights.resize(num);
        for (auto iter = m_indirectLights.begin(); iter != m_indirectLights.end(); iter++)
            iter->setEnabled(false);
    }

    // Request #num exiting rays from the light.
    std::vector<Vec3f> origs, dirs, E_times_pdf;
    ls.sampleEmittedRays(num, origs, dirs, E_times_pdf);

    // At this point m_indirectLights holds #num lights that are off.
    // Loop through the rays and fill in the corresponding lights in m_indirectLights
    // based on what happens to the ray.
    for (int i = 0; i < num; i++)
    {
        // Intersect against the scene
        Hit h = rt->rayCast(origs[i], dirs[i]);
        const RTTriangle* tri = h.triangle;

        if ( tri != 0 )
        {
            // YOUR CODE HERE
            // Ray hit the scene, now position the light m_indirectLights[i] correctly,
            // color it based on the texture or diffuse color, etc. (see the LightSource declaration for the list
            // of things that a light source needs to have)
            // A lot of this code is like in the Assignment 2's corresponding routine.

            const RTToMesh* map = (const RTToMesh*)tri->m_userPointer;
            const Vec3i& indices = scene->indices( map->submesh )[ map->tri_idx ];

            // Fetch the barycentrics
            Vec3f barycentrics = tri->getBarycentrics(h.intersection);

            // Check for backfaces => don't accumulate if we hit a surface from below!
            const Vec3f tnormal = tri->getNormal(h.intersection, barycentrics);

            // Divide incident irradiance by PI so that we can turn it into outgoing
            // radiosity by multiplying by the reflectance factor below.
            //Ei *= (1.0f / FW_PI);

            Vec3f Ei;
            // check for texture
            const MeshBase::Material& mat = scene->material(map->submesh);
            if ( mat.textures[MeshBase::TextureType_Diffuse].exists() )
            {
                // Yes, texture; fetch diffuse albedo from there.
                // First interpolate UV coordinates from the vertices using barycentrics
                // Then turn those into pixel coordinates within the texture
                // Finally fetch the color using Image::getVec4f() (point sampling is fine).
                // Use the result as the diffuse reflectance instead of mat.diffuse.

                const Texture& tex = mat.textures[MeshBase::TextureType_Diffuse];
                const Image& teximg = *tex.getImage();

                Vec2f texCoord = barycentrics[0] * scene->vertex(indices[0]).t +
                                 barycentrics[1] * scene->vertex(indices[1]).t +
                                 barycentrics[2] * scene->vertex(indices[2]).t;

                Vec2i texCoordi = Vec2i( (texCoord.x - floor(texCoord.x))*teximg.getSize().x,
                                         (texCoord.y - floor(texCoord.y))*teximg.getSize().y );

                Ei = teximg.getVec4f(texCoordi).getXYZ();
            }
            else
            {
                Ei = mat.diffuse.getXYZ();
            }

            Vec3f emission = E_times_pdf[i] * Ei;

            // Set the indirect light parameters
            m_indirectLights[i].setPosition(h.intersection);
            Mat3f orientation = LightSource::formBasis(-tnormal);
            m_indirectLights[i].setOrientation(orientation);
            m_indirectLights[i].setEmission(emission);
            m_indirectLights[i].setFOV(m_indirectFOV);

            // Replace this with true once your light is ready to be used in rendering
            m_indirectLights[i].setEnabled(true);
        }
        else
        {
            // If we missed the scene, disable the light so it's skipped in all rendering operations.
            m_indirectLights[i].setEnabled(false);
        }
    }
}
开发者ID:Zerphed,项目名称:advanced-computer-graphics-course,代码行数:95,代码来源:InstantRadiosity.cpp

示例14: ASSERT

bool SVGFEDiffuseLightingElement::setFilterEffectAttribute(FilterEffect* effect, const QualifiedName& attrName)
{
    FEDiffuseLighting* diffuseLighting = static_cast<FEDiffuseLighting*>(effect);

    if (attrName == SVGNames::lighting_colorAttr) {
        RenderObject* renderer = this->renderer();
        ASSERT(renderer);
        ASSERT(renderer->style());
        return diffuseLighting->setLightingColor(renderer->style()->svgStyle()->lightingColor());
    }
    if (attrName == SVGNames::surfaceScaleAttr)
        return diffuseLighting->setSurfaceScale(surfaceScale());
    if (attrName == SVGNames::diffuseConstantAttr)
        return diffuseLighting->setDiffuseConstant(diffuseConstant());

    LightSource* lightSource = const_cast<LightSource*>(diffuseLighting->lightSource());
    const SVGFELightElement* lightElement = SVGFELightElement::findLightElement(this);
    ASSERT(lightSource);
    ASSERT(lightElement);

    if (attrName == SVGNames::azimuthAttr)
        return lightSource->setAzimuth(lightElement->azimuth());
    if (attrName == SVGNames::elevationAttr)
        return lightSource->setElevation(lightElement->elevation());
    if (attrName == SVGNames::xAttr)
        return lightSource->setX(lightElement->x());
    if (attrName == SVGNames::yAttr)
        return lightSource->setY(lightElement->y());
    if (attrName == SVGNames::zAttr)
        return lightSource->setZ(lightElement->z());
    if (attrName == SVGNames::pointsAtXAttr)
        return lightSource->setPointsAtX(lightElement->pointsAtX());
    if (attrName == SVGNames::pointsAtYAttr)
        return lightSource->setPointsAtY(lightElement->pointsAtY());
    if (attrName == SVGNames::pointsAtZAttr)
        return lightSource->setPointsAtZ(lightElement->pointsAtZ());
    if (attrName == SVGNames::specularExponentAttr)
        return lightSource->setSpecularExponent(lightElement->specularExponent());
    if (attrName == SVGNames::limitingConeAngleAttr)
        return lightSource->setLimitingConeAngle(lightElement->limitingConeAngle());

    ASSERT_NOT_REACHED();
    return false;
}
开发者ID:0omega,项目名称:platform_external_webkit,代码行数:44,代码来源:SVGFEDiffuseLightingElement.cpp

示例15: glMatrixMode

void WorldObject::Draw(Camera* camera)
{
    glMatrixMode(GL_MODELVIEW);
    camera->LoadMatrix();
    glTranslatef(this->position.x, this->position.y, this->position.z);
    
    glRotatef(this->rotation.z, 0, 0, 1.0f);
    glRotatef(this->rotation.y, 0, 1.0f, 0);
    glRotatef(this->rotation.x, 1.f, 0, 0);
    glScalef(this->scale, this->scale, this->scale);
    
    
    glBegin(GL_TRIANGLES);
    for(int i = 0; i < this->faceCount; i++)
    {
        modelFace face = this->faces[i];
        vector3 v1 = this->vertices[face.v1];
        vector3 v2 = this->vertices[face.v2];
        vector3 v3 = this->vertices[face.v3];
        
        vector3 transformedv1 = this->GetTransformedVertex(face.v1);
        vector3 transformedv2 = this->GetTransformedVertex(face.v2);
        vector3 transformedv3 = this->GetTransformedVertex(face.v3);
        
        vector3 v1norm = this->GetVertexNormal(face.v1);
        vector3 v2norm = this->GetVertexNormal(face.v2);
        vector3 v3norm = this->GetVertexNormal(face.v3);
        
        vector3 v1Color = { 0, 0, 0 };
        vector3 v2Color = { 0, 0, 0 };
        vector3 v3Color = { 0, 0, 0 };
        
        std::vector<LightSource*> lightSources = this->world->GetLightSources();
        for(int i = 0; i < lightSources.size(); i++)
        {
            LightSource* ls = lightSources[i];
            
            vector3 v1LightColor = ls->CalculateLight(this, transformedv1, v1norm, camera);
            vector3 v2LightColor = ls->CalculateLight(this, transformedv2, v2norm, camera);
            vector3 v3LightColor = ls->CalculateLight(this, transformedv3, v3norm, camera);
            
            v1Color.x += v1LightColor.x;
            v1Color.y += v1LightColor.y;
            v1Color.z += v1LightColor.z;
            
            v2Color.x += v2LightColor.x;
            v2Color.y += v2LightColor.y;
            v2Color.z += v2LightColor.z;
            
            v3Color.x += v3LightColor.x;
            v3Color.y += v3LightColor.y;
            v3Color.z += v3LightColor.z;
        }
        
        glColor3f(v1Color.x, v1Color.y, v1Color.z);
        glVertex3f(v1.x, v1.y, v1.z);
        
        glColor3f(v2Color.x, v2Color.y, v2Color.z);
        glVertex3f(v2.x, v2.y, v2.z);
        
        glColor3f(v3Color.x, v3Color.y, v3Color.z);
        glVertex3f(v3.x, v3.y, v3.z);
    }
    glEnd();
    
    this->transformedNormalsAreValid = true;
}
开发者ID:lucasbiagini,项目名称:PG,代码行数:67,代码来源:WorldObject.cpp


注:本文中的LightSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。