Adding modular functionality to the RGB knobs in the demo

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding modular functionality to the RGB knobs in the demo

IndianaScones

Hello!

  I am attempting to change the behavior of the RGB knobs in the building.
Instead of a smooth range of motion, I would like to make them each have 4
settings (when you click and drag a knob, it jumps through each of the 4
settings).  Each of these settings will play a different looped audio track.
The key in the doorway behind you (when at the controls) will be invisible
at first, but it will appear when you have set the knobs to the correct
combination.

Here is an example of what I'm trying to accomplish (the settings with
asterisks would be the secret combination):
http://old.nabble.com/file/p32859425/screen.jpg 


The nodes in question are:

18  http://old.nabble.com/file/p32859425/node18.lua node18.lua  (the RGB
controls) &

16  http://old.nabble.com/file/p32859425/node16.lua node16.lua  (where the
key is)

I've managed to fumble through a few scripting changes (making the colored
light switches on the platform take you to a new node when you press the
correct combination of buttons), but I am a sound designer, and I think what
I'm going for here might be beyond me.

It may be a lot of help to ask for (I don't know), but if someone can even
point me in the right direction, I would greatly appreciate it.  When I look
at all that stuff in node 18 dealing with the RGB controls, I am completely
lost.
--
View this message in context: http://old.nabble.com/Adding-modular-functionality-to-the-RGB-knobs-in-the-demo-tp32859425p32859425.html
Sent from the pipmak-users mailing list archive at Nabble.com.



Reply | Threaded
Open this post in threaded view
|

Re: Adding modular functionality to the RGB knobs in the demo

cwalther
Administrator
IndianaScones wrote:

>  I am attempting to change the behavior of the RGB knobs in the building.
> Instead of a smooth range of motion, I would like to make them each have 4
> settings (when you click and drag a knob, it jumps through each of the 4
> settings).  Each of these settings will play a different looped audio track.
> The key in the doorway behind you (when at the controls) will be invisible
> at first, but it will appear when you have set the knobs to the correct
> combination.
>
> Here is an example of what I'm trying to accomplish (the settings with
> asterisks would be the secret combination):
> http://old.nabble.com/file/p32859425/screen.jpg 
>
> ...
>
> It may be a lot of help to ask for (I don't know), but if someone can even
> point me in the right direction, I would greatly appreciate it.  When I look
> at all that stuff in node 18 dealing with the RGB controls, I am completely
> lost.

I understand - there is a bit of math involved in moving something on a circle, and then there is the animated gauge and all that adding more complexity to the script of node 18.

Here's a replacement mousestilldown function for the red knob that snaps the knob to five regularly spaced positions on its circle, and hopefully makes things a bit clearer with the comments:

        onmousestilldown = function()
                -- center of the circle
                local x0, y0 = 219, 422
                -- mouse location relative to the center of the circle
                local x, y = pipmak.mouseloc()
                x = x - x0
                y = y - y0
                -- if the mouse is exactly in the center, treat it as slightly above
                if x == 0 and y == 0 then y = -1 end
                -- angle, clockwise from the top, in radians ([0..2*pi))
                local a = math.atan2(x, -y)
                -- angle in fifth-circles ([0..5))
                a = a/(2*math.pi)*5
                -- round to the closest whole number
                a = math.floor(a + 0.5)
                -- convert back to radians
                a = a/5*2*math.pi
                -- convert from angle back to coordinates ([-1..1])
                x = math.sin(a)
                y = -math.cos(a)
                -- place the knob: center of the knob on a circle of radius 21 around the center coordinates, therefore its top left corner 8 pixels offset from that horizontally and vertically
                redknob:moveto(x0 + x*21 - 8, y0 + y*21 - 8)
        end

To have irregularly spaced positions, as you depict, instead of rounding the angle to the nearest whole number, you need to check if it's inside each of the five ranges individually, and then snap it to the respective position.

Does that help?

 -Christian

Reply | Threaded
Open this post in threaded view
|

Re: Adding modular functionality to the RGB knobs in the demo

IndianaScones
Hi Christian!

Thank you.

The more I thought about it, it seemed like maybe it would be easier for me to just erase the knobs all together and go with buttons.  I appreciate your help, but even aside from the math of moving the wheels, there are also programming aspects that I'm not familiar with, such as where to tie the audio tracks to the dial settings.  If I make buttons, and then either learn to make a hotspot map or perhaps just add a bunch of handles, then I think I can work within my present knowledge.  The only thing I'm uncertain I can do is make the correct combination of buttons in node 18 trigger the key appearing in node 16.  Still, with enough elbow grease I think I can reason it out.

Nonetheless, trying to make sense of your code (with the aid of the comments) is helping me get a better handle on the math involved, though I still have to look up some of the programming vernacular.

Jonathan

On Fri, Nov 18, 2011 at 12:12 PM, Christian Walther <[hidden email]> wrote:
IndianaScones wrote:
>  I am attempting to change the behavior of the RGB knobs in the building.
> Instead of a smooth range of motion, I would like to make them each have 4
> settings (when you click and drag a knob, it jumps through each of the 4
> settings).  Each of these settings will play a different looped audio track.
> The key in the doorway behind you (when at the controls) will be invisible
> at first, but it will appear when you have set the knobs to the correct
> combination.
>
> Here is an example of what I'm trying to accomplish (the settings with
> asterisks would be the secret combination):
> http://old.nabble.com/file/p32859425/screen.jpg
>
> ...
>
> It may be a lot of help to ask for (I don't know), but if someone can even
> point me in the right direction, I would greatly appreciate it.  When I look
> at all that stuff in node 18 dealing with the RGB controls, I am completely
> lost.

I understand - there is a bit of math involved in moving something on a circle, and then there is the animated gauge and all that adding more complexity to the script of node 18.

Here's a replacement mousestilldown function for the red knob that snaps the knob to five regularly spaced positions on its circle, and hopefully makes things a bit clearer with the comments:

       onmousestilldown = function()
               -- center of the circle
               local x0, y0 = 219, 422
               -- mouse location relative to the center of the circle
               local x, y = pipmak.mouseloc()
               x = x - x0
               y = y - y0
               -- if the mouse is exactly in the center, treat it as slightly above
               if x == 0 and y == 0 then y = -1 end
               -- angle, clockwise from the top, in radians ([0..2*pi))
               local a = math.atan2(x, -y)
               -- angle in fifth-circles ([0..5))
               a = a/(2*math.pi)*5
               -- round to the closest whole number
               a = math.floor(a + 0.5)
               -- convert back to radians
               a = a/5*2*math.pi
               -- convert from angle back to coordinates ([-1..1])
               x = math.sin(a)
               y = -math.cos(a)
               -- place the knob: center of the knob on a circle of radius 21 around the center coordinates, therefore its top left corner 8 pixels offset from that horizontally and vertically
               redknob:moveto(x0 + x*21 - 8, y0 + y*21 - 8)
       end

To have irregularly spaced positions, as you depict, instead of rounding the angle to the nearest whole number, you need to check if it's inside each of the five ranges individually, and then snap it to the respective position.

Does that help?

 -Christian
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Pipmak-Users mailing list
[hidden email]
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users

Reply | Threaded
Open this post in threaded view
|

Re: Adding modular functionality to the RGB knobs in the demo

cwalther
Administrator
> there are also programming aspects that I'm not familiar with, such as where to tie the audio tracks to the dial settings.
> ...
> The only thing I'm uncertain I can do is make the correct combination of buttons in node 18 trigger the key appearing in node 16.

The current button combination (assuming that it doesn't automatically reset once you leave, as the knobs in the original demo do) is part of your game state, so you store it in the global "state" table. In node 16, you then make the visibility of the key dependent on that state, and in node 18, the audio track.

 -Christian