Commit Graph

8139 Commits

Author SHA1 Message Date
Bill Currie fc14826cd6 Reorganize the code a little. 2011-12-07 10:42:39 +09:00
Bill Currie 4f13d19b7e Optimize edges_intersect().
I found wolfram's line-line intersection page and noticed their equation
for the time of intersection was rather different to mine. After analyzing
the differences, it turns out they produce exactly the same results (when
the lines are coplanar), but their method allows me to eliminate one dot
product (4->3). Not only that, but it turns out that their method works
equally well for skew lines (ie, non-coplanar).

mine:
  CxA.CxA
  -------
  CxA.AxB

theirs:
  CxA.AxB
  -------
  AxB.AxB
2011-12-07 10:35:58 +09:00
Bill Currie ff693a956a Avoid missed portals in trace_to_leaf(). 2011-12-06 22:09:40 +09:00
Bill Currie 8c840a7003 Sanitize trace_hits_plane().
While unit normals aren't needed, they were too big for sane math. Now
epsilon can be used for the distance tests. One of the two new tests passes
now :).
2011-12-06 22:06:25 +09:00
Bill Currie 2b65f81b72 Use a saner "infinity".
8e6 is just too big for reasonable floating point.
This fixes the bogus portals.
2011-12-06 20:50:09 +09:00
Bill Currie 632817fed5 Fail properly when the portals are bogus. 2011-12-06 20:48:31 +09:00
Bill Currie f496f4d260 Whee, more tests that break things :) 2011-12-06 20:47:57 +09:00
Bill Currie 8fe703d747 Trace to adjoining leafs when necessary.
When the trace stradles a plane in the current leaf, check the other side
of the portal, too, as it is possible that leaf will restrict the movement
of the trace.

All current tests pass! However, I can think of some situations (and I
already have a solution) where things will fail, but that's next.
2011-12-06 17:27:05 +09:00
Bill Currie 4c17ca9583 Break out trace_hits_portal() from trace_enters_leaf(). 2011-12-06 08:46:04 +09:00
Bill Currie 9a9079a2b3 Correct the start-solid in a corner test.
It turns out that the box trace CAN get out of the solid from that location
(though a similar point trace can not). This is because of my decision to
allow non-points to touch a plane from either side without crossing the
plane, whereas a point touching a plane is always considered to be on the
front side of the plane as there is no further information to disambiguate
on which side of the plane the point is.
2011-12-05 22:11:58 +09:00
Bill Currie 4419d4c4ad Move the trace into the leaf before testing the contents.
The trace is moved as far into the leaf as possible without leaving the
other side of the leaf. This ensures that trace_contents is started from a
good location. There is currently a problem with traces that stradle a
plane getting, but this has cleared up all the current contents related
tests.
2011-12-05 22:11:58 +09:00
Bill Currie c588d28b96 Clear contents flags before calling trace_contents. 2011-12-05 22:11:58 +09:00
Bill Currie 8307d9f233 Rename check_in_leaf to trace_enters_leaf. 2011-12-05 22:11:58 +09:00
Bill Currie 3bd029d599 Make the contents flags clear.
I got tired of not being able to remember which flag was which in the
output.
2011-12-05 22:11:47 +09:00
Bill Currie 8e512a087c More failing contents tests.
However, I have a plan :)
2011-12-05 09:03:04 +09:00
Bill Currie b4a497baab Correctly restore the saved start point.
This fixes the point test failures.
2011-12-04 21:12:12 +09:00
Bill Currie 7da6df9dfb Use the "real" contents of the trace's location when visiting a leaf.
When visiting a leaf in box mode, use trace_contents() to get the highest
priority contents of any leafs touched by the box in the current location.
I'm now down to one failing test case, and it's an "allsolid" issue that
might be an incorrect assumption in my test case.
2011-12-04 19:14:35 +09:00
Bill Currie 053d801e92 Break out the leaf visit code into its own funciton. 2011-12-04 18:52:17 +09:00
Bill Currie 4e76aa3025 Don't split on a plane parallel to the motion.
This seems to improve the start/all solid cases a little, and it should
speed things up a little by avoiding unnecessary polygon tests.
2011-12-04 12:46:22 +09:00
Bill Currie ed8e09608a Fix the negative fractions coming from edge_portal_dist().
I have a better fix in the works, but I wanted edge_portal_dist() to be
correct.
2011-12-04 12:11:27 +09:00
Bill Currie e5903a60ff Put the mistaken test case back in. 2011-12-04 11:00:38 +09:00
Bill Currie eb5d2720e4 Avoid a segfault when there's no split plane. 2011-12-04 10:55:46 +09:00
Bill Currie cdfc922bce Fix a silly test case error. 2011-12-04 10:47:52 +09:00
Bill Currie 487a6b20ab Test collisions with a ridge smaller than the box.
Whee, found a failing test case :)
2011-12-04 09:02:12 +09:00
Bill Currie 55eb88b52c Create some tests for MOD_HullContents. 2011-12-03 22:18:43 +09:00
Bill Currie 581972c905 More file splitting for code reuse. 2011-12-03 21:13:01 +09:00
Bill Currie dadfb78992 Split out the hull data so it can be used in other tests. 2011-12-03 20:23:42 +09:00
Bill Currie 9ad298a716 Check whether the portal and box intersect.
Now on to creating tests for MOD_HullContents :)
2011-12-03 19:59:12 +09:00
Bill Currie d9a641c600 Avoid a segfault when the hull hasn't been portalized.
Serves me right for forgetting to test the main engine :P
2011-12-03 09:06:57 +09:00
Bill Currie 27642a080a Avoid infinite recursion. 2011-12-01 12:57:06 +09:00
Bill Currie f9d56f2941 Add MOD_HullContents().
If trace is null or point type, or the hull doesn't have portals, or the
first node is a leaf, MOD_HullContents operates in point mode (exactly the
same way as SV_HullPointContents()). However, in box mode, all leafs
touched by the trace are checked for their contents. The contents field of
trace (a bit field) will indicate the contents type of all touched leafs.
The returned contents value indicates the most important contents:

    solid > lava > slime > water > empty

The one's complement value of the contents type is the bit number of the
contents bit field. I'm not sure how useful this will be as getting the
amount of overlap is currently not supported.
2011-12-01 12:26:33 +09:00
Bill Currie 7ee31dd475 Allow the trace start to be in multiple leafs.
This fixes a couple of in-solid tests, but something better is needed.
2011-11-28 20:56:21 +09:00
Bill Currie 13d37f4838 Add a bunch of in-solid tests.
Tests where the box is only partially in a solid tend to fail (particularly
when the solid is on the back side of the split plane).
2011-11-28 20:56:21 +09:00
Bill Currie 50b08c98fa Add some snug-fit tests and fix the uncovered bugs.
The tests involve the box fitting into a hole with zero slop (this would be
impossible with point clipping).
2011-11-28 20:56:21 +09:00
Bill Currie 985667ecba Fix plane touching box backsideness.
Because a box has size, even when touching a plane, the side on which the
box is can be determined (unlike a point).
2011-11-28 20:56:21 +09:00
Bill Currie 869cd19260 Box traces can now graze a corner. 2011-11-28 20:56:21 +09:00
Bill Currie 45d55d7e9a Test the simple wedge. 2011-11-28 20:56:21 +09:00
Bill Currie 2c9b07b257 Scale the box edge vectors.
Now they represent the lengths of the edges as expected by the edge/polygon
code.
2011-11-28 20:56:20 +09:00
Bill Currie 60dbc0e342 Fix the last few bugs breaking the distance code.
The code itself seems to work now. There are still some problems: the box
faces are using unit vectors for the edges, or I should go back to unit
vectors for the portal edges; starting in a solid corner won't always work;
etc. However, that's just mopping up: the main algorithm seems to be
working.
2011-11-28 20:56:20 +09:00
Bill Currie 996859c367 Correct the projection code.
That needed to be the intersection of two coplanar lines.
2011-11-28 20:56:20 +09:00
Bill Currie ab2ec644d6 Clip the portals when running the test cases.
When the portals are too big, floats break down and break the tests. This
might not be much of an issue in real maps, but my tests use "infinite"
planes.
2011-11-28 20:56:20 +09:00
Bill Currie 2abff68089 Fix some more silly bugs.
The target test now works, but some others have broken due to getting
negative fractions.
2011-11-28 20:56:20 +09:00
Bill Currie a1da8ecdd0 Fix some silly errors that broke most of the box tests.
Uninitialized variables and crossed signs. Oops :/
2011-11-28 20:56:20 +09:00
Bill Currie 8fc99566ab Add code to clip the motion of the box to the leaf's portals.
Unfortunately, something is broken (all box tests fail due to 0 fraction).
2011-11-28 20:56:20 +09:00
Bill Currie 5ee552ea5b Don't normalize the portal edge vectors.
This simplifies the collision handling code.
2011-11-28 20:56:20 +09:00
Bill Currie 174f381125 Add some more tests for the ramp.
These tests pass, but show the basic polygon testing working (just not the
collision handling and thus fraction determination).
2011-11-28 20:56:20 +09:00
Bill Currie 750b5ba0ed Be a little more lenient with float comparisons.
Unfortunately, Pythagorus and binary don't play well together, so rounding
errors are inevetible when testing with a slope. However, 1e-6 seems to be
a good epsilon (printf's %g hides it nicely :).
2011-11-28 20:56:20 +09:00
Bill Currie 3a386293fc Add Vector3Scale macro.
Vector3Scale individually scales the components of one vector by the
components of another vector.
2011-11-28 20:56:19 +09:00
Bill Currie 4044f9d8e2 Shrink the default winding size.
The minimum number of points on a valid winding is 3, and the most common
will be 4 (especially useful for static structures).
2011-11-28 20:56:19 +09:00
Bill Currie 73b93ffd74 Clean up the in_leaf test line. 2011-11-28 20:54:35 +09:00