Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    Particle bouncing off wall. [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    7 Posts 0 Posters 560 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      On 24/01/2015 at 04:34, xxxxxxxx wrote:

      Hi
      I'm about to start a project which involves moving particles that bounce off or flow along a geometric surface.
      As a starting test, I'd like to bounce a particle around inside a cube.  So the particle has a position and a random starting velocity, and when it reaches a wall of the cube, it bounces in the appropriate direction. Looking around the SDK I can't see much in the way of collision detection and physics, so I guess I'll have to work things out manually - which I prefer anyway.

      So my particle needs to know if it has reached a polygon (wall of the cube) - how might this be this done?
      I would then imagine a reflection angle needs to be calculated based on the velocity vector of the particle and the normal of the polygon.

      Any help appreciated, cheers,
      Glenn.

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 24/01/2015 at 09:47, xxxxxxxx wrote:

        Take a look at GeRayCollider for your collisions. Then yes, once collided you'll have to calculate the new direction. That's simple vector maths, which you will use a *lot* if you start moving particles around.

        Steve

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 24/01/2015 at 09:57, xxxxxxxx wrote:

          ahhh perfect thank you!

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 25/01/2015 at 03:49, xxxxxxxx wrote:

            Hi again
            I got a basic test working which is great - I just have one small question.  When I move the source position of the ray, the collision point changes as expected, however when I move the collision object around nothing changes.

            import c4d
            from c4d.utils import GeRayCollider

            def main() :
                sourceobj = doc.SearchObject("Null") # The object the ray will start from 
                targetobj = doc.SearchObject("Cube") # The object the ray collides with    
                ray = GeRayCollider()                # Create a new GeRayCollider object
                ray.Init(targetobj, True)            # Assign the object to a variable

            start = sourceobj.GetAbsPos()
                direction = c4d.Vector(0, 1, 0)      #The direction the ray points.

            distance = 1000

            CollisionState = ray.Intersect(start, direction, distance)
                if CollisionState: targetobj[c4d.ID_BASEOBJECT_XRAY] = True
                else:  targetobj[c4d.ID_BASEOBJECT_XRAY] = False
                
                intersection = ray.GetIntersection(0)["hitpos"]
                print intersection

            main()

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 26/01/2015 at 13:15, xxxxxxxx wrote:

              Hi glenn,

              Nothing changes when you move the collision object around because you're likely changing its world coordinates, not its object coordinates, and yet are doing the ray collision calculations from object space.  Your sourceobj.GetAbsPos() call, for instance, is in object space.  When you move the source position of the ray, it changes in object space, hence the collision point changes occur as expected.

              If you really need it to be in world space, here's a link to a thread pointed out to me by Andreas that could help:

              Position/Normal under Cursor

              I hope that helps!

              Joey Gaspe
              SDK Support Engineer

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                On 26/01/2015 at 14:29, xxxxxxxx wrote:

                Thanks very much Joey for the explanation.   It's not something urgent I need working, but might want to look at in the future.  I'll use your link for reference.

                A quick work around I found is if I make the Null a child of the Cube - and move the cube around, then offset of the Null back to where it was, then that seems to work.

                Cheers,
                Glenn.

                1 Reply Last reply Reply Quote 0
                • H Offline
                  Helper
                  last edited by

                  On 26/01/2015 at 14:36, xxxxxxxx wrote:

                  Hi Glenn,

                  Thanks for letting me know.  Your use of the Null for your Cube is certainly a workaround that should work without issue.  I'll set this topic to solved, but leave it open for comments.

                  Thanks,

                  Joey Gaspe
                  SDK Support Engineer

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post