Reflecting particle

This is a discussion on Reflecting particle within the C++ Programming forums, part of the General Programming Boards category; Hi guys For my 2 year project I have decided to make a particle simulator and so far so good ...

  1. #1
    Registered User bobbinator's Avatar
    Join Date
    Jul 2009
    Posts
    29

    Question Reflecting particle

    Hi guys

    For my 2 year project I have decided to make a particle simulator and so far so good
    But I want the particle to bounce when it hits a side. Now this is a little complex as i need to have a formula that calculates the gradient and direction of the bounced particle.

    I hope this makes sense, thanks!

    (for example, how does pong get the ball to bounce)
    Last edited by bobbinator; 09-08-2009 at 02:32 AM.

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Well, change the direction. IE if it hits the right side, it is now travelling in the original y, and the inverse x. You can figure out the other sides using similar logic. So keep some speed, and on update set x += speed * dx and y += speed * dy.

    Other then this simpler route you can keep track of the angle of the particle, relative to some axis, and use the trig functions to figure out the new position.

  3. #3
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    Well, change the direction. IE if it hits the right side, it is now travelling in the original y, and the inverse x. You can figure out the other sides using similar logic. So keep some speed, and on update set x += speed * dx and y += speed * dy.
    For that you'll need two speed variables speedX and speedY, or perhaps a vector with two components.

    But most of the better implementations of pong use something more than that. You could for instance do it using some trig as mentioned above.

    If you want to reflect the particle against a plane, then you'll have to use the get the dot product between your vector and the normal and calculate the new direction. Something like -

    Code:
    R = V - (2 * N * dot(V, N));
    Spidey out!

  4. #4
    Registered User bobbinator's Avatar
    Join Date
    Jul 2009
    Posts
    29
    I know this may be asking for a lot but...could you upload an example please please please......
    Thanks!

  5. #5
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Well, for the simplest implementation as I mentioned above it's pretty easy. First you must be able to tell when a particle hits a wall. After that change the direction of movement by taking the inverse of the correct position that you are changing.

    You should post the section of code you need help with and ask specific questions. Also there are plenty of google examples in every language of doing a pong implementation.

  6. #6
    Registered User bobbinator's Avatar
    Join Date
    Jul 2009
    Posts
    29
    No worries, i figured it out !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Arrays vs Vectors vs Lists for particle rendering?
    By indigo0086 in forum Game Programming
    Replies: 4
    Last Post: 07-01-2007, 10:28 PM
  2. [OGL] Particle class wanted!
    By cboard_member in forum Game Programming
    Replies: 2
    Last Post: 02-17-2006, 07:44 AM
  3. Particle System Tutorial
    By MipZhaP in forum Game Programming
    Replies: 5
    Last Post: 08-21-2004, 03:39 AM
  4. OpenGL Particle Engine Demo
    By frenchfry164 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 11-25-2003, 09:10 AM
  5. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21