4 Replies - 1826 Views - Last Post: 23 July 2011 - 07:44 PM Rate Topic: -----

#1 gilvim  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-July 11

java: biliard game shoot power

Posted 23 July 2011 - 10:12 AM

I'm creating a java billiard game and trying to make power indicator which will say how fast ball needs to move...
i have code which move the ball, but here i move ball by the position of the mouse.. and cannot figure it out how to move it by the power.
      
        double power = 9;
        int x1 = p2.x - p1.x, y1 = p2.y - p1.y;
        shoot.start(p2,x1,y1, player));


p2 - ball position x and y (Point)
p1 - mouse position
x1 and y1 - how much ball will be moving to x or y

Is This A Good Question/Topic? 0
  • +

Replies To: java: biliard game shoot power

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10462
  • View blog
  • Posts: 38,777
  • Joined: 27-December 08

Re: java: biliard game shoot power

Posted 23 July 2011 - 11:14 AM

Power isn't a good measurement, IMO. Take a look at momentum instead, as it is easier to work with for collisions. Remember that power is the Integral(force dx) and momentum is the Integral(force dt). I have some tutorials on collision handling that you may find helpful:
http://www.dreaminco...-1d-collisions/
http://www.dreaminco...-2d-collisions/
Was This Post Helpful? 0
  • +
  • -

#3 gilvim  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-July 11

Re: java: biliard game shoot power

Posted 23 July 2011 - 01:28 PM

it's about collision, i already have made that part... now i need to calculate a shoot.. i was thinking to extend a line between ball position and mouse and then take just a section of it. but i don't know how to proper extend that line.
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10462
  • View blog
  • Posts: 38,777
  • Joined: 27-December 08

Re: java: biliard game shoot power

Posted 23 July 2011 - 01:33 PM

Take a look at some trig instead. Power still isn't what you want to use here- momentum is. Think about a two-dimensional collision between the ball and the stick. Think about the conservation of momentum, and think about the angle at which the stick is striking the ball. You can use that to break up the momentum using polar coordinates.
Was This Post Helpful? 0
  • +
  • -

#5 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: java: biliard game shoot power

Posted 23 July 2011 - 07:44 PM

Be careful not to over think this problem, I don't think an accurate simulation is required.

Put simply, the more power you charge in the power bar, the less time the ball will take to get from point A (the point at which the cue hits the ball) to point B (the point where the cue ball hits the other ball), so this is a function of time more than anything else.

As an initial thought you need to first determine the minimum and terminal speed for the cue ball for a given distance. This can be any fixed distance that will be normalized according to the actual distance between the two balls.

Where the force vs momentum debate comes in is the point at which the balls collide and the rules that govern their physical properties, but that is another debate.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1