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

Sweeping non-moving objects #2

Closed
sponge opened this issue Jul 11, 2016 · 2 comments
Closed

Sweeping non-moving objects #2

sponge opened this issue Jul 11, 2016 · 2 comments

Comments

@sponge
Copy link

sponge commented Jul 11, 2016

The annotated source says "If the sweep isn’t actually moving anywhere, just do a static test. It’s faster and will give us a better result for that case."

and then the code goes on to show:

    if delta.x == 0 and delta.y == 0
      sweep.pos.x = box.pos.x
      sweep.pos.y = box.pos.y
      sweep.hit = this.intersectAABB(box)
      if sweep.hit?
        sweep.time = sweep.hit.time = 0
      else
        sweep.time = 1

Shouldn't sweep.pos.x = box.pos.x actually be sweep.pos.x = this.pos.x? If the object isn't moving, why would the position be the object you are colliding with?

(BTW, this has been a great resource! I've ported it more or less directly to a single C header file along with the tests: https://github.com/sponge/sdlgame/blob/master/src/sweep.h it mostly seems to be working besides a couple of weird edge cases that I'm not sure are my fault or are present in the original. I won't make any claims about how good my C is, though!)

@noonat
Copy link
Owner

noonat commented Feb 15, 2017

@sponge First, apologies for taking so long to respond!

The sweep in this case is representative of the movement of "box", not of "this". That is, it's intersecting the movement of "box" into a static "this", and the sweep object is capturing the result of that movement.

In the case of a movement where delta x and y are both zero, the sweep is starting at the box's start position and moving nowhere. The box is sitting where it started and not progressing at all, and the sweep time is just a boolean indicating whether it hit anything.

@noonat noonat closed this as completed Feb 15, 2017
@sponge
Copy link
Author

sponge commented Feb 15, 2017

No worries, and I had forgotten about this issue myself! I did indeed have the concept of which box was which messed up, and forgot to close this here :)

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