Results 1 to 14 of 14

Thread: Math

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113

    Angry

    I'm looking for a way for a ball to bounce off a line.

    ok i have a ball going on a 90' angle to a
    line (152,200)-(192,160) which has a slop of -1




  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    any gravity? Any friction? Any collision detection? Is it only the graphical part your interested in? What are you trying to accomplish?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113
    NO gravity NO friction



  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    start position of the ball? does it have a radius?
    velocity? in pixels please
    image/picturebox? shapecontrol ddraw, how do you draw the ball?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113
    B_angle(1)=90
    B_Velocity(1)=1

    angleofball = B_angle(ball) * (2 * 3.14159265358979) / 360
    X = Pball(ball).Left + Cos(angleofball) * B_Velocity(ball)
    Y = Pball(ball).Top + Sin(angleofball) * B_Velocity(ball)
    This works

    i have the ball at 50,10

    I'm making pong
    the line with the slop is the thing to hit the ball back


    [Edited by BIacksun on 10-14-2000 at 05:59 PM]

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    The ball doesn't hit the wall, do you want me to change the values so that you have it bounce with slopes?
    BTW, don't calculate ball position by trigonometry, calculate vectors by angle instead.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7
    Guest
    I sent you an example of a Ping Pong game, check your mail. It's not the most advanced, but it works .

    Hope that helps.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113
    i want somthig like this

    If Y > (?line.Y2?) Then
    m = (.Y2 - .Y1) / (.X2 - .X1)
    B_angle(ball) = ???????????????????
    End If

    so when the ball hits the line, the ball will change it's
    angle.



    [Edited by BIacksun on 10-14-2000 at 06:23 PM]

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    The math behind it was a bit hard to figure out and i'm still not sure if it will work, anyway here's the collision point and the exit angle:
    Code:
        kw = (y2 - y1) / (x2 - y1)
        kb = Tan(angle)
        bw = y1 - k * x1
        bb = ballY - k * ballX
        'collision point
        cx = (kw * x1 + bw - bb) / kb
        cy = kw * cx + bw
        'exit angle
        angle = Tan(kw) + 180 - Atn(Abs((kw - kb) / (1 + kw * kb)))
    x1,y1,x2y2, the wall coordinates
    angle, the angle of the ball velocity
    BTW, i have an old vb3 sample that demonstrate this better, but it's a real mess to understand it, anyway it works
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113
    what is "k"
    and what do i do with


    IS this for the ball to make it to the line?
    bw = y1 - k * x1
    bb = ballY - k * ballX
    'collision point
    cx = (kw * x1 + bw - bb) / kb
    cy = kw * cx + bw

    I need a example of this stuff

    [Edited by BIacksun on 10-14-2000 at 08:53 PM]

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    k is the k in line equation: y=kx+b
    ah sorry should be kb for the ball and kw for the wall
    bw = y1 - kw * x1
    bb = ballY - kb * ballX
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113
    is it not
    y=mx+b
    m = rise/run (slop)

  13. #13
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    whatever, were talking about the same thing
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113
    thanx for the help

    but i faild.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width