Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RE::TESObjectCELL::ForEachReferenceInRange #110

Open
Elephant42 opened this issue Nov 5, 2021 · 1 comment
Open

RE::TESObjectCELL::ForEachReferenceInRange #110

Elephant42 opened this issue Nov 5, 2021 · 1 comment

Comments

@Elephant42
Copy link

Hello,

I've been hammering away at an SKSE plugin for a couple of weeks using your excellent library and have managed to get most of what I need working but have struck a brick wall on one feature. Would you have any suggestions on how to use the method RE::TESObjectCELL::ForEachReferenceInRange.
I'm trying to get a list of RE::TESObjectREFR* that are within a certain radius of a target Actor.

TIA for any help you care to offer.

@SteveTownsend
Copy link

SteveTownsend commented Nov 23, 2021

I think this should be return distance <= (a_radius * a_radius) ? since it's comparing to the square of the distance.

	void TESObjectCELL::ForEachReferenceInRange(const NiPoint3& a_origin, float a_radius, std::function<bool(TESObjectREFR&)> a_callback) const
	{
		ForEachReference([&](TESObjectREFR& ref) {
			const auto distance = a_origin.GetSquaredDistance(ref.GetPosition());
			return distance <= a_radius ?
						 a_callback(ref) :
						 true;
		});
	}

It's also possible to optimize by not doing any floating point mult if any of dx/dy/dz are > radius from ref

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants