LevelLocals.SphericalCoords: Compute spherical coordinates from one point in the world to another #553
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This acts on static map data only, so it should be client-server safe. Useful for checking whether one actor is inside another actor's view cone.
Here's the documentation for this new method (which I'll add to the wiki if this PR is merged):
LevelLocals.SphericalCoords
Vector3 SphericalCoords(Vector3 viewpoint, Vector3 targetPos [, Vector2 viewAngles] [, bool absolute])
Usage
Computes spherical coordinates pointing to targetPos from viewpoint.
Parameters
true
, the calculation will ignore portals. Default isfalse
, meaning portals will be accounted for.Return value
A
Vector3
, with these components:viewAngles.X
(the viewpoint's yaw) must turn left (if negative) or right (if positive) to facetargetPos
, in degrees. This is the azimuthal angle or φ (phi).viewAngles.Y
(the viewpoint's pitch) must pitch down (if negative) or up (if positive) to facetargetPos
, in degrees. This is the polar angle or θ (theta).targetPos
is fromviewpoint
, in world units. This is the radius or r.Note that the Z coordinate is the same as you'd get from
LevelLocals.Vec3Diff(viewpoint, targetPos).Length()
, and similar toa.Distance3D(b)
(where a and b are actors).Distance3D
only computes distances between the bottoms of actors, however, and does not account for their heights or viewpoints.Example
You can use this to determine how close an actor is to the player's crosshairs.
Here's a more complete example: an inventory item that tells you what you're aiming at.