Exemplo n.º 1
0
Vector3 Colorful::Shade(const HitInfo& hit, const Scene& scene) const {
    const Ray& ray = hit.eyeRay;
    const Vector3 viewDir = -ray.direction;
    const std::vector<Light*>& lights = scene.GetLights();
    Vector3 shadedColor(0.0f, 0.0f, 0.0f);

    // Loop over all lights
    std::vector<Light*>::const_iterator light_it = lights.begin();
    for (light_it=lights.begin(); light_it != lights.end(); ++light_it) {
		Light* light = *light_it;
		Vector3 direction = light->GetPosition() - hit.point;

		float distance2 = direction.Length2();
		float falloff = light->Falloff(distance2);
		direction.Normalize();

		const float intensity = hit.normal.Dot(direction) * falloff * light->GetWattage() * math::INV_PI;
		if( intensity > 0.0f ) {
			Vector3 color = light->GetColor();
			color *= intensity;

			color = Vector3 (  (1-hit.texCoord.y)*(1-hit.texCoord.y),
							hit.texCoord.x*hit.texCoord.x,
							hit.texCoord.x );

			shadedColor += color;
		}
	}

    return shadedColor;
}
Exemplo n.º 2
0
//----------------------------------------------------------------------------------------------------
void Object3D::Normalize()
{
	AutoArray< WORD > count( vertex.size() );//平均値取得用
	int i;
	for(i=0;i<vertex.size();i++)
	{
		vertex[i].n.setVector( 0,0,0 );
		count[i] = 0;
	}
	for(i=0;i<face.size();i++)
	{
		ModelFace &f = face[i];
		const Vector3 &v1 = vertex[f[0]].p;
		const Vector3 &v2 = vertex[f[1]].p;
		const Vector3 &v3 = vertex[f[2]].p;

		Vector3 n = Vector3::Cross( v2-v1,v3-v1 );
		if( n.Length2() )//垂直か?長さはあるか?
		{
			n.Normalize();
			vertex[f[0]].n += n;count[f[0]]++;
			vertex[f[1]].n += n;count[f[1]]++;
			vertex[f[2]].n += n;count[f[2]]++;
		}
	}
	for(i=0;i<vertex.size();i++)
	{
		if(count[i]) vertex[i].n /= (float) count[i];
	}
}
Exemplo n.º 3
0
bool BoundingSphere::Contains(const BoundingSphere &other, Vector3 & toOther, Vector3 & otherFarEnd)
{
	toOther = other.getCenter() - m_Center;
	toOther.Normalize();
	otherFarEnd = other.getCenter() + toOther*other.GetRadius();
	
	Vector3 toOtherFarEnd = otherFarEnd - m_Center;
	return toOtherFarEnd.Length2() < m_SquareRadius;
}
Exemplo n.º 4
0
bool BoundingSphere::ContainsOther(const BoundingSphere & self, const BoundingSphere & other, Vector3 & toOther, Vector3 & otherFarEnd)
{

	if (self.getCenter() == other.getCenter())
	{
		return other.GetRadius() < self.GetRadius();
	}

	toOther = other.getCenter() - self.getCenter();
	toOther.Normalize();
	otherFarEnd = other.getCenter() + toOther*other.GetRadius();

	Vector3 toOtherFarEnd = otherFarEnd - self.getCenter();
	return toOtherFarEnd.Length2() < self.GetSquaredRadius();
}
Exemplo n.º 5
0
void BoundingSphere::init(const BoundingSphere::Vector3 &pole1, const BoundingSphere::Vector3 &pole2)
{
	m_Center = (pole1 + pole2) / 2.0f;
	Vector3 poleVec = (pole1 - pole2);
	m_SquareRadius = poleVec.Length2();
	m_Radius = sqrt(m_SquareRadius);

	float maxExtent = fabs(poleVec[0]);
	m_ElongatedDim = 0;
	if ( maxExtent < fabs(poleVec[1]) )
	{
		maxExtent = fabs(poleVec[1]);
		m_ElongatedDim = 1;
	}

	if ( maxExtent < fabs(poleVec[2]) )
	{
		maxExtent = fabs(poleVec[2]);
		m_ElongatedDim = 2;
	}
}