Archive 17/01/2023.

Object within radius?

darkirk

Is there a built-in routine in Urho to detect what objects are within X radius of another one?

Eugene

Probably, triggers??

lezak

Or if You dont’t want to use physics, there is Octree::GetDrawables that can be used with a SphereOctreeQuery

johnnycable

Raycast < distance during update?
Object Position (vector) - Object Position (Vector) < distance during update?

Eugene

Are you sure about performance of this approach?

johnnycable

Well, if you have no other choice…:wink:

darkirk

Thanks for the help guys! :slight_smile:

Modanung

I guess both methods have their pros-n-cons. I’d expect the octree query to efficiently looks only within the specified range while ignoring the rest of the world and returning visually accurate results.
Whereas when simply checking the distance between nodes you could start with applying a filter through calling GetChildrenWithTag, GetChildrenWithComponent and GetDerivedComponents on the Scene with recursive set to true. Once you get the node’s position checking distances is in essence a simple pythagorean problem.

In many cases triggers could also do the trick.

Modanung

Note that this is comparing a Vector3 and float.
I implemented the function as such:

float LucKey::Distance(const Vector3 from, const Vector3 to, bool planar)
{
    if (!planar)
        return (to - from).Length();
    else
        return ((to - from) * Vector3(1.0f, 0.0f, 1.0f)).Length();
}

With planar having false as its default value.

johnnycable

What if I’m spiderman and I’m walking on the side of a skyscraper? :rofl:

Modanung

Then the distance to the skyscraper would be zero. :stuck_out_tongue:

johnnycable

float LucKey::Distance(const Vector3 from, const Vector3 to, Vector3 complanarity = Vector3(1,1,1))
{
return ((to - from) * complanarity).Length();
}
spiderman is served :wink:

Modanung

How about:

float Distance(Vector3 from, Vector3 to, const bool planar = false, Vector3 normal = Vector3::UP);
float LucKey::Distance(Vector3 from, Vector3 to, const bool planar, Vector3 normal)
{
    Vector3 difference{ to - from };
    if (planar) {
        difference -= difference.ProjectOntoAxis(normal) * normal.Normalized();
    }
    return difference.Length();
}

Should work for any plane. Not just axial planes. :slight_smile:

johnnycable

Modanung

Seems to work. :slight_smile:

The size of the boxes in the images relies on: LucKey::Distance(boxPos, Vector3::ZERO, ..., ...)

Here’s a video:

https://vimeo.com/222029488

Modanung

Spiderman may like this DistanceToPlane function as well:

float DistanceToPlane(Vector3 from, Vector3 normal = Vector3::UP, Vector3 origin = Vector3::ZERO);
float LucKey::DistanceToPlane(Vector3 from, Vector3 normal, Vector3 origin)
{
    return Abs((from - origin).ProjectOntoAxis(normal));
}
johnnycable

Yeah. Could do for another dynamic geometry example… or better swipe plane raycast… or so…:slightly_smiling_face:

slapin

Aw, seen that word again and want to ask for a meaning…

What is swipe?
What is swipe plane raycast?