billiards-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Billiards-devel] Programming experiments with Billiards


From: Dimitris Papavasiliou
Subject: Re: [Billiards-devel] Programming experiments with Billiards
Date: Tue, 19 Jan 2010 13:53:09 +0200

Lets see,

Ok, I think I found the "offending" code in game.lua, lines 177-178. Now
I can set the observer longitude and latitude.

I also managed to set the observer's azimuth with this code
local oldnewshot = billiards.looking.newshot

billiards.looking.newshot = function ()
  -- First call the old function to setup the default
  -- behavior we don't want to change.

  oldnewshot()

  -- Now change what we don't like.
  bodies.observer.azimuth = math.rad(90)
  bodies.observer.elevation = math.rad(45)
  bodies.observer.longitude = bodies.cueball.position[1]
  bodies.observer.latitude = bodies.cueball.position[2]
end

That looks ok but why would you need to change the observer's longitude and latitude.  That's actually the point the observer is looking at and should always be the position of the cue ball.  Doesn't oldnewshot() take care of this?
 
- Show quoted text -
Ok, I tried to implement the transition between looking and aiming mode
with the following:

if options.experiment2 then
  billiards.looking.experiment2 = function ()
     for i, ball in ipairs (bodies.balls) do
        local x = ball.position[1]
        local y = ball.position[2]
        if i == 1 then
           print (string.format ("White ball position: (%f, %f)", x,
y))
        elseif i == 2 then
           print (string.format ("Black ball position: (%f, %f)", x,
y))
        end
     end
     print ("Entering aiming mode...")
     bodies.observer.islooking = false
     bodies.observer.isaiming = true
  end

  billiards.aiming.experiment2 = function ()
     print ("Stepping into function 'billiards.aiming.experiment2'")
     joints.arm.motor = {arm_velocity, 1000}
  end
end

but it doesn't work. The console output shows the text:
"Stepping into function 'billiards.aiming.experiment2'", but the balls
don't move.
Can you help me with this?

I can't try this out at the moment so my reply will be relatively vague for now.  First a matter of minor importance.  If you see the last blocks of code in observer.lua you'll see that the observer table has a so-called "metatable" attached to it which performs some actions when some of its keys are set.  So when you set the isaiming key to true then __newindex "metamethod" fires and set all other is*, like islooking to false automagically.  You therefore don't need to do this yourself.

Now regarding the other point.  If the balls don't move (does the cue stick appear?), then the stick never pushes the cue ball so it probably doesn't move either.  In that case there's either some hook somewhere that sets its motor to 0 or, and this is more likely, you set the stick's motor before it gets linked to the tree.  Inside cue.lua you'll find:
   
billiards.aiming.cue = function ()
                          bodies.cue.parent = bodies.cueball.parent
                       end

This links the cue when entering aiming mode thus making it appear.   If this gets called *after* your hook you're probably screwed.  You can test this by printing the cue's parrent inside your hook:

print (bodies.cue.parent)

If you get nil you have a problem there.  You may be able to resolve this by renaming your hook from experiment2 to something else or by calling billiards.aiming.cue() from your hook but I'm not sure if any of this will work.  This is all rather irritating.  I'll have to switch the hook mechanism to integer keys that provide some ordering at least.  Looks like I'll be releasing Billiards 0.3.1 in the weekend...

Let me know if you have any luck,
Dimitris

reply via email to

[Prev in Thread] Current Thread [Next in Thread]