[PROPOSAL] A common script function to check if a vector intersects a bounding box.

This forum is the ideal place for all discussion relating to X4. You will also find additional information from developers here.

Moderator: Moderators for English X Forum

Post Reply
User avatar
RoverTX
Posts: 1426
Joined: Wed, 16. Nov 11, 18:37
x4

[PROPOSAL] A common script function to check if a vector intersects a bounding box.

Post by RoverTX » Sun, 18. Apr 21, 06:34

What is Proposed?

Proposal for a common script function with the following definition.

Code: Select all

<xs:element name="check_vector_intersect_boundingbox">
  <xs:annotation>
    <xs:documentation>
      Returns true if a vector intersects a given bounding box
    </xs:documentation>
  </xs:annotation>
  <xs:complexType>
    <xs:attributeGroup ref="action" />
    <xs:attribute name="component" type="object" use="required" />
    <xs:attribute name="position_one" type="position" use="required" />
    <xs:attribute name="position_two" type="position" use="required" />
    <xs:attribute name="result" type="lvaluename" use="required" />
  </xs:complexType>
</xs:element>
The above can be calculated in constant time. A example of an algorithm can be found below for the simple case where the bounding box is aligned to the axis. Effectively you are checking to see if the vector intersects any of the bounding box's six faces.
http://www.3dkingdoms.com/weekly/weekly.php?a=3

Why Is It Proposed?

Allowing to check if a vector intersects a bounding box would make scripts that need to avoid collision a lot easier. For example in the move.flee.boost command instead of taking a bunch of averages to create a point and then creating a vector from it and the ships position, you could just check if the ships current position and boost end point would intersect any obstacles bounding box. If no intersection boost in the current direction, otherwise rotate a little bit randomly and then see if you intersect.

I believe this would allow the Egosoft developers and modding community to do a lot of interesting things when it comes to ship movement in combat.

Alternatives

Exposing bounding boxes fully for everything that inherits from controllable. Bounding boxes could be represented as a set of 8 points with a given rotation if they are not axis aligned.

Rei Ayanami
Posts: 3333
Joined: Wed, 6. Nov 02, 20:31
x4

Re: [PROPOSAL] A common script function to check if a vector intersects a bounding box.

Post by Rei Ayanami » Sun, 18. Apr 21, 15:41

I'm not sure if just checking via a vector is enough, since the ships collision box is larger than a thin line.
With just checking the vector you could end up in situations where a XL ship thinks a small hole in a station is good enough to fly through.

Some other game engines, like Unreal or Unity, allow so-called tracing with various shapes:
https://docs.unrealengine.com/en-US/Int ... index.html
A line trace would "draw" a line from a given starting point to a given end point and return if there is anything between these two points, aka the same thing you proposed.
A sphere trace would do the same, but also check along the trace path (begin->end point) within the given sphere radius for any collision objects.
Then there are other shapes, such as box tracing or capsule tracing, wich are the same (move an invisible shape from a start to an end point and return any object that is in the way), just with different shapes used to check for collisions.

In order to check whether a ship can boost in a direction without anything in its way, you'd probably have to do a sphere trace, with the trace sphere radius being the ships bounding sphere radius.

User avatar
RoverTX
Posts: 1426
Joined: Wed, 16. Nov 11, 18:37
x4

Re: [PROPOSAL] A common script function to check if a vector intersects a bounding box.

Post by RoverTX » Sun, 18. Apr 21, 18:42

Rei Ayanami wrote:
Sun, 18. Apr 21, 15:41
I'm not sure if just checking via a vector is enough, since the ships collision box is larger than a thin line...

A sphere trace would do the same, but also check along the trace path (begin->end point) within the given sphere radius for any collision objects.
Then there are other shapes, such as box tracing or capsule tracing, wich are the same (move an invisible shape from a start to an end point and return any object that is in the way), just with different shapes used to check for collisions...
Nice! Have done limited spacial programing myself, and only 2D map data, so this sounds a lot better. I just went with vector hitbox collision as I knew off the top of my head that you could do it rather cheaply. What is the complexity of that calculation?

User avatar
RoverTX
Posts: 1426
Joined: Wed, 16. Nov 11, 18:37
x4

Re: [PROPOSAL] A common script function to check if a vector intersects a bounding box.

Post by RoverTX » Sun, 18. Apr 21, 20:37

Some more context this is currently done via find_gravidar_contact by passing it match_is_in_view_of & match_distance. Its a cone though instead of a vector or a tube, which means things that aren't actually in the ships path get counted as obstacles.

Alkeena
Posts: 603
Joined: Tue, 15. May 07, 20:43
x4

Re: [PROPOSAL] A common script function to check if a vector intersects a bounding box.

Post by Alkeena » Sun, 18. Apr 21, 23:21

RoverTX wrote:
Sun, 18. Apr 21, 20:37
Some more context this is currently done via find_gravidar_contact by passing it match_is_in_view_of & match_distance. Its a cone though instead of a vector or a tube, which means things that aren't actually in the ships path get counted as obstacles.
This might be a reasonable simplifying assumption depending on the arc radius of the cone. Ships can change direction while boosting and that script may not have fine control over the the precise inputs applied (a lot of the finer simulation points occur in the compiled executible rather than directly controlled by script). From the scripts' perspective the ship could end up straight ahead or 5 degrees off--this translates into a cone pretty readily.

Post Reply

Return to “X4: Foundations”