bool VortexParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps)
{
	if(getBeacon() != NULL)
	{
		Matrix BeaconToWorld(getBeacon()->getToWorld());
		Vec3f translation, tmp;
		Quaternion tmp2;
		BeaconToWorld.getTransform(translation,tmp2,tmp,tmp2);

		Pnt3f particlePos = System->getPosition(ParticleIndex);
		Real32 distanceFromAffector = particlePos.dist(Pnt3f(translation.x(),translation.y(),translation.z())); 

		if((getMaxDistance() < 0.0) || (distanceFromAffector <= getMaxDistance())) //only affect the particle if it is in range
		{	
			Vec3f particleDirectionFromVortex(particlePos.x() - translation.x(), particlePos.y() - translation.y(), particlePos.z() - translation.z());
			particleDirectionFromVortex = particleDirectionFromVortex.cross(getVortexAxis());
			particleDirectionFromVortex.normalize();
			particleDirectionFromVortex = particleDirectionFromVortex *
                ((-getMagnitude() *
                  elps)/OSG::osgClamp<Real32>(1.0f,std::pow(distanceFromAffector,getAttenuation()),TypeTraits<Real32>::getMax()));
			System->setVelocity(particleDirectionFromVortex + System->getVelocity(ParticleIndex),ParticleIndex);
		}
	}

	return false;
}
Light::Data SpotLight::getData( double time, const mat4 &transform ) const
{
	// Populate the LightData structure.
	Light::Data params = Light::getData( time, transform );
	params.position = vec3( transform * vec4( mPosition, 1 ) );
	params.direction = glm::normalize( mat3( transform ) * mDirection );
	params.range = mRange;
	params.attenuation = getAttenuation();
	params.angle = getConeParams();

	if( mFlags & ( Data::ShadowEnabled | Data::ModulationEnabled ) ) {
		mat4 invTransform = glm::inverse( transform );

		if( mFlags & Data::ShadowEnabled ) {
			params.shadowMatrix = getShadowMatrix() * invTransform;
			params.shadowIndex = mShadowIndex;
		}

		if( mFlags & Data::ModulationEnabled ) {
			params.modulationMatrix = getModulationMatrix( time ) * invTransform;
			params.modulationIndex = mModulationIndex;
		}
	}

	return params;
}
Example #3
0
void PointLight::updateRange()
{
	float minIntensity = 1 / (m_intensity * std::max(m_color.x, std::max(m_color.y, m_color.z)) * 256);
	float maxRange = 1000.0f;

	float range = maxRange;

	float c = getAttenuation()->getConstant();
	float l = getAttenuation()->getLinear();
	float e = getAttenuation()->getExponent();
	if (m_intensity < minIntensity * c) 
		range = 0;
	else 
		if (e > 0) 
			range = (-l + (float)std::sqrt(l * l + 4.0 * e * (m_intensity / minIntensity - c))) / (2.0f * e);
		else if (l > 0)
			range = std::max(.0f, (m_intensity - minIntensity * c) / (minIntensity * l));

	m_range = std::min(range, maxRange);
}
Example #4
0
void Light::enterScene(Scene* scene) {
    VisualComponent::enterScene(scene);

    light = createLight();

    setEnabled(isEnabled());
    setDiffuseColour(getDiffuseColour());
    setSpecularColour(getSpecularColour());
    setAttenuation(getAttenuation());

    getSceneNode()->attachObject(light);
}
Example #5
0
void PointLight::SetLight(X3DDrawContext* pDC)
{
//	m_radius->m_value;

	D3DXMATRIX modelView = pDC->m_renderContext->modelViewMatrix();

	D3DXVECTOR3 location(m_location->getValue());
	D3DXVECTOR4 v;

	D3DXVec3Transform(&v, &location, &modelView);

	float ambientIntensity = getAmbientIntensity();
	float intensity = getIntensity();
	Vec3f color = getColor();
	Vec3f attenuation = getAttenuation();

	Graphics::Light light;
	light.m_type = 2;
	light.m_ambient = Vec4f(ambientIntensity, ambientIntensity, ambientIntensity, 1.0f);
	light.m_diffuse = Vec4f(color[0]*intensity, color[1]*intensity, color[2]*intensity, 1.0f);
	light.m_position = Vec4f(v.x, v.y, v.z, 1/*positional*/);
	light.m_constant_attenuation = attenuation[0];
	light.m_linear_attenuation = attenuation[1];
	light.m_quadratic_attenuation = attenuation[2];

	pDC->m_renderContext->m_lights.push_back(light);

	++pDC->m_renderContext->m_nLight;

#if 0
	pDC->m_pGraphics3D->PushMatrix();
//	glTranslated(0, 0, 100);

	float light_position[4];
	m_location->getValue(light_position);
	light_position[3] = 1;	// positional
	float ambient[4] = {m_ambientIntensity->m_value, m_ambientIntensity->m_value, m_ambientIntensity->m_value, 1.0};
	float diffuse_specular[4] = {m_color->m_value[0], m_color->m_value[1], m_color->m_value[2], m_intensity->m_value};

	pDC->m_pGraphics3D->Enable(GL_LIGHT0+pDC->m_nLight);
	pDC->m_pGraphics3D->Lightfv(GL_LIGHT0+pDC->m_nLight, GL_POSITION, light_position);
	pDC->m_pGraphics3D->Lightfv(GL_LIGHT0+pDC->m_nLight, GL_AMBIENT, ambient);
	pDC->m_pGraphics3D->Lightfv(GL_LIGHT0+pDC->m_nLight, GL_DIFFUSE, diffuse_specular);
//	pDC->m_pGraphics3D->glLightfv(GL_LIGHT0+pDC->m_nLight, GL_SPECULAR , diffuse_specular);

	pDC->m_pGraphics3D->Lightf(GL_LIGHT0+pDC->m_nLight, GL_CONSTANT_ATTENUATION, m_attenuation->m_value[0]);
	pDC->m_pGraphics3D->Lightf(GL_LIGHT0+pDC->m_nLight, GL_LINEAR_ATTENUATION, m_attenuation->m_value[1]);
	pDC->m_pGraphics3D->Lightf(GL_LIGHT0+pDC->m_nLight, GL_QUADRATIC_ATTENUATION, m_attenuation->m_value[2]);

	pDC->m_pGraphics3D->PopMatrix();
#endif
}
void CX3DPointLightNode::print(int indent)
{
	FILE *fp = CX3DParser::getDebugLogFp();

	char *nodeName = getNodeName();
	if (nodeName)
	{
		float r, g, b;
		float x, y, z;

		CX3DParser::printIndent(indent);
		fprintf(fp, "%s (%s)\n", nodeName, CX3DNode::getNodeTypeString(getNodeType()));

		CX3DParser::printIndent(indent+1);
		fprintf(fp, "ambientIntensity : (%f)\n", getAmbientIntensity()->getValue());

		getColor()->getValue(r, g, b);
		CX3DParser::printIndent(indent+1);
		fprintf(fp, "color : (%f %f %f)\n", r, g, b);

		CX3DParser::printIndent(indent+1);
		fprintf(fp, "intensity : (%f)\n", getIntensity()->getValue());

		getLocation()->getValue(x, y, z);
		CX3DParser::printIndent(indent+1);
		fprintf(fp, "location : (%f %f %f)\n", x, y, z);

		CX3DParser::printIndent(indent+1);
		fprintf(fp, "radius : (%f)\n", getRadius()->getValue());

		getAttenuation()->getValue(x, y, z);
		CX3DParser::printIndent(indent+1);
		fprintf(fp, "attenuation : (%f %f %f)\n", x, y, z);

		CX3DParser::printIndent(indent+1);
		fprintf(fp, "on : %s\n", getOn()->getValue() ? "TRUE" : "FALSE");

		CX3DParser::printIndent(indent+1);
		fprintf(fp, "global : %s\n", getGlobal()->getValue() ? "TRUE" : "FALSE");
	}
}
Light::Data WedgeLight::getData( double time, const mat4 &transform ) const
{
	// Adjust position.
	vec3 position = mPosition - 0.5f * mLength * mAxis;

	// Populate the LightData structure.
	Light::Data params = Light::getData( time, transform );
	params.position = vec3( transform * vec4( position, 1 ) );
	params.direction = glm::normalize( mat3( transform ) * mDirection );
	params.horizontal = glm::normalize( mat3( transform ) * mAxis );
	params.width = mLength;
	params.range = mRange;
	params.attenuation = getAttenuation();
	params.angle = getConeParams();

	// Disable shadows and modulation.
	params.flags &= ~Data::ShadowEnabled;
	params.flags &= ~Data::ModulationEnabled;

	return params;
}
Example #8
0
void ScenRectangle::toXml(ostream &out)
 {
   //Dati obbligatori	 
  out<<" <Rect x=\""<<p.x<<"\" y=\""<<p.y<<"\" width=\""<<width<<"\" height=\""<<height<<"\"";
  
  //Nome (dato Opzionale)
  if(getName()!="")	 
     out<<" name=\""<<getName()<<"\"";
  
  //Angolo di rotazione (dato Opzionale)
  if(rotAngle!=0)
    out<<" rotation=\""<<rotAngle<<"\"";	  
  
  
  //Colore riempimento (Dato opzionale)
   Color fillCol=getFillColor(); 
   if((fillCol.getRi()!=128)||
     (fillCol.getGi()!=128)||
     (fillCol.getBi()!=128))
     { 
	  out<<" fill=\""<<fillCol.getRi()<<","
	                       <<fillCol.getGi()<<","
	                       <<fillCol.getBi()<<"\""; 
     }
   
   //Colore bordo (Dato opzionale)
   Color borderCol=getBorderColor(); 
   if((borderCol.getRi()!=255)||
     (borderCol.getGi()!=0)||
     (borderCol.getBi()!=0))
     { 
	  out<<" border=\""<<borderCol.getRi()<<","
	                              <<borderCol.getGi()<<","
	                              <<borderCol.getBi()<<"\""; 
     }  
	
   out<<" attenuation=\""<<getAttenuation()<<"\"/>\n";	
 }//Fine toXml
Example #9
0
float sfSoundStream_getAttenuation(const sfSoundStream* soundStream)
{
    CSFML_CALL_RETURN(soundStream, getAttenuation(), 0.f);
}
bool TurbulenceParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps)
{
	if(getBeacon() != NULL)
	{	
		Matrix BeaconToWorld(getBeacon()->getToWorld());
		Vec3f translation, tmp;
		Quaternion tmp2;
		BeaconToWorld.getTransform(translation,tmp2,tmp,tmp2);

		Pnt3f particlePos = System->getPosition(ParticleIndex);
		Real32 distanceFromAffector = particlePos.dist(Pnt3f(translation.x(),translation.y(),translation.z())); 

		if((getMaxDistance() < 0.0) || (distanceFromAffector <= getMaxDistance())) //only affect the particle if it is in range
		{	
			Real32 Xparam, Yparam, Zparam;

			Pnt3f pos(System->getPosition(ParticleIndex));
			getPerlinDistribution()->setPhase(getPhase()[0]);
			Xparam = getPerlinDistribution()->generate(pos[0]);
			getPerlinDistribution()->setPhase(getPhase()[1]);
			Yparam = getPerlinDistribution()->generate(pos[1]);
			getPerlinDistribution()->setPhase(getPhase()[2]);
			Zparam = getPerlinDistribution()->generate(pos[2]);

			Vec3f fieldAffect(Vec3f(Xparam, Yparam, Zparam));
			fieldAffect = fieldAffect * (getAmplitude()*
                                          (elps/(OSG::osgClamp<Real32>(1.0f,std::pow(distanceFromAffector,getAttenuation()),TypeTraits<Real32>::getMax()))));

			System->setVelocity(System->getVelocity(ParticleIndex) + fieldAffect, ParticleIndex);

		} // end distance conditional
	} // end null beacon conditional

	return false;
}
Example #11
0
float sfSound_getAttenuation(const sfSound* sound)
{
    CSFML_CALL_RETURN(sound, getAttenuation(), 0.f);
}
Real Speaker::attenuation(const Vec & RAY_DIRECTION) const {
    return getAttenuation(direction, RAY_DIRECTION, directionality);
}