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

CollisionParabola into CollisionInvSphere #670

Closed
wants to merge 5 commits into from

Conversation

hecris
Copy link
Contributor

@hecris hecris commented Jun 9, 2019

The algorithm basically combines CollisionSphere::intersects_parabola with CollisionInvSphere::test_intersection_from_segment:
Recursively divide the parabola into "close-enough" line segments and then test their intersection with the sphere using similar implementation to CollisionInvSphere::test_intersection_from_segment.
I included unit tests and you can use this as a visualizer (similar to @rdb 's test program for parabola-into-box):

from panda3d.core import *
# load_prc_file_data("", "notify-level-collide debug")

from direct.directbase import DirectStart
base.cam.set_y(-20)

parabola = CollisionParabola(LParabola((1, 0, 1), (1, 0, 0), (-1, 0, 0)), 0.0, 1.0)
into = CollisionInvSphere((-1, -1, -1), 3)

into_node = CollisionNode("into")
into_node.add_solid(into)
into_node.set_into_collide_mask(1)
into_np = render.attach_new_node(into_node)
into_np.show()

from_np_parent = render.attach_new_node("from-parent")

from_node = CollisionNode("from")
from_node.add_solid(parabola)
from_node.set_from_collide_mask(1)
from_np = from_np_parent.attach_new_node(from_node)
from_np.show()

handler = CollisionHandlerEvent()

base.cTrav = CollisionTraverser()
base.cTrav.show_collisions(base.render)
base.cTrav.add_collider(from_np, handler)

def update(task):
    if base.mouseWatcherNode.has_mouse():
        pos = base.mouseWatcherNode.get_mouse()
        from_np_parent.set_pos(pos[0] * 10, 0, pos[1] * 10)
    # print('')
    return task.cont

base.taskMgr.add(update)

base.run()

Suggestions are welcomed!

Copy link
Member

@rdb rdb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review! Feel free to poke me regularly on Discord if I take a while to look at your PRs.

The surface normal should always point towards the center for an inverse sphere. You have it pointing away from the center. You can just flip the sign of that.

The surface point should always lie on the surface of the into object. In some cases it seems to go "inside" the inverse sphere. You can actually calculate the surface point by taking what you got for the normal and multiplying it by the radius, and adding it to the center.

The point you did calculate using the current math, you can set as the interior point, actually, using new_entry->set_interior_point(...).

@rdb rdb self-assigned this Jun 16, 2019
@rdb rdb added the gsoc label Jun 16, 2019
@hecris
Copy link
Contributor Author

hecris commented Jun 16, 2019

Thanks @rdb ! Will make the changes soon.

@rdb
Copy link
Member

rdb commented Jun 20, 2019

Great, thanks a lot! Merged in 563ff75. For future reference, please configure your editor to strip extra spaces at the ends of lines.

@rdb rdb closed this Jun 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants