Ejemplo n.º 1
0
	IResult Intersects(const Ray3& ray, const Transformation& objT) const{
		if (!mBV)
			return IResult(false, FLT_MAX);
		Ray3 localRay = objT.ApplyInverse(ray);
		Ray3::IResult ret = localRay.Intersects(mBV.get());
		return ret;
	}
	void GatherPointLightData(const BoundingVolume* aabb, const Transformation& transform, POINT_LIGHT_CONSTANTS* plConst)
	{
		struct GatheredData
		{
			GatheredData(Real distSQ, unsigned idx)
				:mDistanceSQ(distSQ), mIndex(idx)
			{

			}
			Real mDistanceSQ;
			unsigned mIndex;
		};
		static std::vector<GatheredData> gathered;
		gathered.reserve(50);

		unsigned i = 0;
		for (auto it = mPointLights.begin(); it != mPointLights.end(); /**/)
		{		
			IteratingWeakContainer(mPointLights, it, p);
			if (!p->GetEnabled())
				continue;
			Ray3 ray(p->GetPosition(), transform.GetTranslation() - p->GetPosition());
			Ray3 localRay = transform.ApplyInverse(ray);
			auto iresult = localRay.Intersects(aabb);
			Real distSQ = Squared(iresult.second);
			Real range = p->GetRange();
			if (distSQ < (range*range))
			{
				gathered.push_back(GatheredData(distSQ, i));
			}
			++i;
		}

		std::sort(gathered.begin(), gathered.end(), [](const GatheredData& a, const GatheredData& b){
			return a.mDistanceSQ < b.mDistanceSQ;
		}
		);

		plConst->gPointLightColor[0].w = 0;
		int count = std::min(3, (int)gathered.size());
		unsigned validNumber = 0;
		for (int i = 0; i < count; i++)
		{
			PointLightPtr p = mPointLights[gathered[i].mIndex].lock();
			if (p){
				plConst->gPointLightPos[validNumber] = Vec4(p->GetPosition(), p->GetRange());
				plConst->gPointLightColor[validNumber] = Vec4(p->GetColorPowered(), (Real)count);
				++validNumber;
			}
		}

		gathered.clear();
	}
Ejemplo n.º 3
0
bool BVaabb::TestIntersection(const Ray3& ray) const
{
	Vec3 normal;
	Ray3::IResult ret = ray.Intersects(mAABB, normal);
	return ret.first;
}