Jump to content


Photo

Point Magic (120+ Scripts) -- Version 1.1 Needs


  • Please log in to reply
61 replies to this topic

#21 Seeker

Seeker

    GMC Member

  • GMC Member
  • 365 posts

Posted 10 June 2007 - 03:57 AM

I'm probably going to use this in my Nintendo DS simulator. Keep up the good work!

<{POST_SNAPBACK}>


Thanks! I really look forward to seeing it if you do. :D Maybe I can include a short list of projects (with demos) that are using this system in the first post, if the project creator wants.

Nice system! It works quite well, but if I were to use this in a game I would make it so that you don't have to start at or end at a specific point and go in a specific direction.

The recognition is OK, I guess... Try as I might, I could not get it to recognize a square, though.  The other shapes were fine though (except for the "X", I couldn't figure out how to draw it). It uses a different method from mine.  I think it could be very useful for the formations, though.  Very nicely put together.  I would encourage anyone reading this to check it out!

<{POST_SNAPBACK}>

I can get all of the shapes except for the "X" and the "?". Even after reading what you said, it still doesn't work! :)

<{POST_SNAPBACK}>


Thank you. The question mark uses a "directional string" instead of point angles for its mouse recognition, which makes the question mark less accurate than the other shapes. You can define a question mark using the most accurate pointgrid_add() scripts, but I just wanted to show everyone that you can define shapes in two different ways using this system.

One easy way to create a question mark definition using the pointgrid_add() scripts would be to draw a question mark on the screen, then press F2 to save it to a file. Then you can use the pointgrid_add_file() script, or you can open the file in Notepad to see the point coordinates, and use the pointgrid_add_point() script for each point.

:P Not the X again! That's my favorite shape! For those that might have missed it: The X requires a little skill to draw (not that you're not skilled, lol). I've made it so that you first have to draw the line going down and to the right, release the mouse button, then draw the line going down and to the left, then release the mouse button, quickly. I gave you 300 milliseconds between when you draw the first line and the last line of the X. Maybe you didn't draw the X quickly enough?

Here's the X code:

xright = gesture_define(xright_grid,0,.95,'','','',0,'',0,'','','',0,300,0,'');
xleft = gesture_define(xleft_grid,0,.95,'','','',0,'',0,'','xright','',0,6000,0,'show_message("X: " + string(gesture_get_score(xleft)*100) +"%")');

If you go in the Demo object's creation event, you can change the 300 you see in the "xright" gesture_define() to a higher number to give you more time to draw the X. You can even lower the .95 you see in both the "xright" and the "xleft" definition to .8 for example to make it easier to draw the shape. Or that's what you did?

I could make it so that you can draw the shapes from any point and any direction, but if you define several shapes, it might slow the recognition process down a bit. I'll look into it and see how it works out. Would you guys actually want to be able to draw a shape from any spot on the shape, or would just being able to start at any of the shapes vertices and drawing in any direction be ok?

Well, for now, you have the "flips" and "rotations" gesture_define() arguments, so you can keep the number of shapes you have to define at a minimum. For example, let's say you want to make it so that the triangle can be drawn from any vertex and in any direction. You could do that with just 3 gesture definitions like this:

// Create triangle grids
triangle1_grid = pointgrid_create();
pointgrid_add_triangle(triangle1_grid,15,0,0,15,30,15,false);

triangle2_grid = pointgrid_create();
pointgrid_add_triangle(triangle2_grid,0,15,15,0,30,15,false);

triangle3_grid = pointgrid_create();
pointgrid_add_triangle(triangle3_grid,0,15,30,15,15,0,false);

// Define triangle shapes
triangle1 = gesture_define(triangle1_grid,0,.75,'','0','',45,'',0,'','','',0,0,0,'show_message("Triangle: " + string(gesture_get_score(triangle1)*100) +"%")');

triangle2 = gesture_define(triangle2_grid,0,.75,'','0','',45,'',0,'','','',0,0,0,'show_message("Triangle: " + string(gesture_get_score(triangle2)*100) +"%")');

triangle3 = gesture_define(triangle3_grid,0,.75,'','0','',45,'',0,'','','',0,0,0,'show_message("Triangle: " + string(gesture_get_score(triangle3)*100) +"%")');

If it weren't for the 5th argument in each gesture_define(), I would have had to create 6 triangle definitions to cover the entire triangle. But the '0' I placed in the 5th argument of each gesture makes it so that each triangle has a horizontal flip enabled, so you only need 3 definitions.

Edited by Seeker, 10 June 2007 - 04:46 AM.

  • 0

#22 Deri

Deri

    GMC Member

  • New Member
  • 70 posts

Posted 10 June 2007 - 05:15 PM

HA, I got the "X"! I just needed to draw it really fast. As for drawing shapes, I think being able to start at any verticie and go in any direction is fine, as long as it is accurate. You wouldn't want your spell/shape to not work, just because you drew it in the wrong direction, or started at the wrong place.
  • 0

#23 Seeker

Seeker

    GMC Member

  • GMC Member
  • 365 posts

Posted 11 June 2007 - 11:39 PM

HA, I got the "X"! I just needed to draw it really fast. As for drawing shapes, I  think being able to start at any verticie and go in any direction is fine, as long as it is accurate. You wouldn't want your spell/shape to not work, just because you drew it in the wrong direction, or started at the wrong place.

<{POST_SNAPBACK}>


Awesome!

VERSION 1.1 RELEASED in the first post. I have now made it so that you can draw a shape starting from any vertex and going in any direction. Please see the script named "Info" for all of the latest information. I also changed some of the settings in the Demo object to hopefully make the drawings easier. Please let me know how it works out.

The question mark still needs to be drawn as it originally was, because I defined it as a directional string, and only point grid shape definitions can use the "extended shape scan" feature I just added. The X still needs to be drawn as it is as well since it is a special type of shape. Also, I made it so that you HAVE to draw the hidden shape starting from a certain point and going in a certain direction. That's the way I wanted it.

Speaking of the hidden shape. Has anybody unlocked and drawn it yet? If you have, prove it! :D

Edited by Seeker, 12 June 2007 - 12:26 AM.

  • 0

#24 Deri

Deri

    GMC Member

  • New Member
  • 70 posts

Posted 12 June 2007 - 05:28 PM

Adding support for different directions and vertexes rely improved recognition, especially for the circle. It was hard to always start at the top of the circle, but now it recognizes the circle I draw 99.9% of the time. Good work. I'm still trying to think of a way to incorporate this into a game.
  • 0

#25 Seeker

Seeker

    GMC Member

  • GMC Member
  • 365 posts

Posted 13 June 2007 - 03:29 AM

Adding support for different directions and vertexes rely improved recognition, especially for the circle. It was hard to always start at the top of the circle, but now it recognizes the circle I draw 99.9% of the time. Good work. I'm still trying to think of a way to incorporate this into a game.

<{POST_SNAPBACK}>


I'm happy to hear that the new Version 1.1 gives you better results! Thank you. I wish I had thought of the extended shape scan feature in the first place. It only took me a few minutes to figure out how to program, and I know how important first impressions are.

It may be possible to boost that 99.9% to 100%. :-) I programmed the pointgrid_add_circle() script to add a new point to a grid after skipping every 18 points. I did that just in case someone decided to create a large circle for some reason, so that hundreds of points wouldn't be added to the grid. But I would think that lowering the point skip in that script from 18 to a slightly lower number would increase that percentage.

I'm still trying to think of exactly what type of game I want to create with this also. I'm pretty set on the action rpg demo I mentioned in the first post, but I'll have to add a few more things to my current stickman animator first, since I know I'll be using that in the game. I have a use for this in my upcoming programs also.

If anyone has any other requests, just let me know. ;)

Edited by Seeker, 14 June 2007 - 05:20 AM.

  • 0

#26 Seeker

Seeker

    GMC Member

  • GMC Member
  • 365 posts

Posted 14 June 2007 - 08:17 PM

Gesture Tutorial Extended

The comments written in the Demo object and the gesture_define() script are the main tutorial for the gesture system. I think I did a good job explaining how to define a shape after it is created, but I did not really explain how to create a shape.

Shapes can be created in two ways. You can create a point grid and add point coordinates to it, or you can create a directional string that contains compass directions ("N,S,W,E,NW,NE,SW,SE").

Point Grid Shapes

Let us say you want to add a trapezoid to the system using the point grid method. The first thing you have to do is create a point grid like this:

trapezoid_grid = pointgrid_create();

Now you need to add points to the grid that will form a trapezoid. There are a few methods for doing this:

Method 1: Manual Point Addition

1. Choose any one of the shape's vertices (corner points) to start with, and add a point to the grid for it (at any position in the room, as long as it is not in the negative region).

2. Choose a single direction to go in, and add the rest of the vertices that form the shape. (Stay in the positive region. Also, do not worry. The recognition will now recognize shapes that are drawn from any point and in any direction. I will explain how to enable that shortly.)

3. If the shape is a closed figure, add the first point to the grid twice, once at the beginning, and again after all of the other points are added.

In this code, I will start at the trapezoid's top-left corner and go counter-clockwise, adding a point for each of the trapezoid's vertices. I will also add the first point again at the end, since a trapezoid is a closed figure:

// Add top-left corner
pointgrid_add_point(trapezoid_grid,20,10);

// Add bottom-left corner
pointgrid_add_point(trapezoid_grid,10,20);

// Add bottom-right corner
pointgrid_add_point(trapezoid_grid,40,20);

// Add top-right corner
pointgrid_add_point(trapezoid_grid,30,10);

// Add top-left corner again since a trapezoid is a closed figure
pointgrid_add_point(trapezoid_grid,20,10);

I placed the trapezoid's points at least 10 units apart from each other. You can space a shape's points out as much as you want, but make sure the spacing is greater than or equal to the "stroke size" value you pass to the gesture_update() script in the Demo object's End Step event. In the demo, I set the stroke size to 5. Unless you go into the Demo object's Creation event and change that value, you will want to place the points in your shape at least 5 units apart from each other.

Method 2: File Point Addition

1. Draw a trapezoid while running the demo, and press F2 to save its points to a file.

2a. If you want to include the file in your distributions, you can use the pointgrid_add_file() script to add it to the trapezoid_grid like this:

pointgrid_add_file(trapezoid_grid,"trapezoid.mgs",1,0,0,1,1,0,-1);

See the list of arguments in the pointgrid_add_file() script to see what each value I passed to the script means. Basically, with the values I passed, the points saved in the "trapezoid.mgs" file are added to the trapezoid_grid without changing the points in any way.

2b. If you do NOT want to include the "trapezoid.mgs" file in your distributions, you can open it in a text editor like Notepad and use the pointgrid_add_point() script to add each point you see in the file (or at least each CORNER point) to the trapezoid_grid. Since a trapezoid is a closed figure, you want to add the first point you see in the file to the grid twice, once at the beginning, and again after all of the other points are added.

Both Methods

Now the trapezoid shape has been created. The last thing we need to do is enable it for gesture recognition using code like this:

trapezoid = gesture_define(trapezoid_grid,0,.85,'','-1','',45,'',0,'','','',0,0,0,'show_message("Trapezoid: " + string(gesture_get_score(trapezoid)*100) +"%")');

The '-1' I passed in the 5th argument (argument4) enables an extended shape scan for the trapezoid definition. This means that the user can draw the trapezoid starting from any vertex and going in any direction. (Otherwise, they would be forced to draw it starting from its top-left corner and going counter-clockwise, just as I created it.)

The gesture_define() script contains over 500 lines of comments that explain what each of the 16 arguments do and several other bits of information about the gesture system. The good thing is, you only HAVE to pass a value for the first argument (argument0) to define a shape. The rest of the arguments are for customizing and enabling interesting effects for each shape.

So to enable the trapezoid for gesture recognition, you could also use code like this:
trapezoid = gesture_define(trapezoid_grid);

/*
When you leave an argument out, or you pass a 0 or an empty string '' for that argument, that argument is ignored, and it does not affect the gesture recognition.
*/

Then you can go into the Demo object's End Step event and in the code action that says "Update system", you can do what is stated in the comments to execute the code needed when the trapezoid is recognized as the winning shape.

Or you could use code like this:

trapezoid = gesture_define(trapezoid_grid,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'show_message("Trapezoid: " + string(gesture_get_score(trapezoid)*100) +"%")');

To make sure that some shapes are not confused with others (because they have similar structures), you will have to read the gesture_define() script. Arguments in that script such as "similarity", "directions", and "priority" will help you.

Directional String Shapes

If you want to create a shape using the directional string method, you can read the notes in the gesture_define() script that explain how to do so. Keep in mind that directional string definitions are less accurate than point grid definitions.

The demo's question mark was defined using a directional string just to show you how it is done, which is why you may get lower percentages when drawing it. If you define a question mark using the pointgrid scripts, it will be several times more accurate. There just may be some times where defining a shape as a directional string will be to your advantage.

Edited by Seeker, 15 June 2007 - 01:24 AM.

  • 0

#27 Deri

Deri

    GMC Member

  • New Member
  • 70 posts

Posted 25 June 2007 - 02:12 PM

For me, the question mark doesn't work, so I think I won't be using directional strings in my games.
  • 0

#28 Seeker

Seeker

    GMC Member

  • GMC Member
  • 365 posts

Posted 26 June 2007 - 02:45 AM

For me, the question mark doesn't work, so I think I won't be using directional strings in my games.

<{POST_SNAPBACK}>


The directional string method included is easier to understand than the point grid method included, so it should appeal to new users of the gesture system. Directional strings depend on the size and speed of one's mouse strokes. So the best way to draw the question mark as I defined it in the demo would be to draw it large and fast or small and slow. But yeah, I'd recommend using point grids all the way. They are as accurate as you can get.

But you're thinking about using this in a game? That's great! I know many see this system as being too complex, but it only seems that way because of all of the options I include (most that you can just ignore, as I mentioned in the above tutorial). But what can I do to make it easier for others? A "lite" version with only the necessary scripts? An extension, maybe? Or is it not too complex after all? :-)

Now for anyone that missed the demo secrets, here are some screenshots.

The first secret is in the Gestures example. If you do what's necessary, you'll see this:

Posted Image

If you draw the shape quickly enough, you'll see this!:

Posted Image

The second secret is in the the RTS Formations example. If you do what's necessary, you can draw a formation shape like the one shown here:

Posted Image

With the shape I drew, upon release of the left mouse button, the yellow pacman moves to the rectangle's bottom-left corner, the dark green pacman moves to the bottom-right corner, the fuchsia pacman moves to the top-right corner, and the lime green pacman moves to the top-left corner.

I thought this was pretty neat. :P
  • 0

#29 Deri

Deri

    GMC Member

  • New Member
  • 70 posts

Posted 03 July 2007 - 10:40 PM

Well, it is complex, or at least it looks that way because of all the comments in the code. I think that to make it easy to understand you should include a tutorial in .rtf or .pdf format, that explanes how to make a program with recognition for basic shapes, like a circle or square. And a lite version of the system wouldn't be a bad idea.

Edit: I just looked at the code, and it's not that complicated, but I had a hard time figuring out what "0 - any - value { string: directional string | real: point grid id }" meant. after I figured out what you were trying to say, it was straight forward.

Edited by Deri, 03 July 2007 - 10:43 PM.

  • 0

#30 Seeker

Seeker

    GMC Member

  • GMC Member
  • 365 posts

Posted 15 July 2007 - 02:09 PM

Well, it is complex, or at least it looks that way because of all the comments in the code. I think that to make it easy to understand you should include a tutorial in .rtf or .pdf format, that explanes how to make a program with recognition for basic shapes, like a circle or square. And a lite version of the system wouldn't be a bad idea.

Edit: I just looked at the code, and it's not that complicated, but I had a hard time figuring out what "0 - any - value { string: directional string | real: point grid id }" meant. after I figured out what you were trying to say, it was straight forward.

<{POST_SNAPBACK}>


Thanks, but I've decided not to do all of that. I think the system is easy enough, surely not too complicated for anyone that takes the time to read the tutorial above and the one included in the source code. Anyone that really wants this can produce a lite version on their own, because I listed the 5 or so scripts that are actually needed in the tutorial. I'll only simplify things even further if others say they want it. I'd do it just for one person, but I know you already understand it, correct? So I'll leave things as they are. :D
  • 0

#31 Deri

Deri

    GMC Member

  • New Member
  • 70 posts

Posted 16 July 2007 - 08:53 PM

Makes cents, and I just saw your little tutorial above. I think that that would be perfect to include with the example. I was bored, so I converted it into .rtf format. If you want, you can include it in the download, it's your choice. Download here
  • 0

#32 Seeker

Seeker

    GMC Member

  • GMC Member
  • 365 posts

Posted 18 July 2007 - 02:05 AM

Makes cents, and I just saw your little tutorial above. I think that that would be perfect to include with the example. I was bored, so I converted it into .rtf format. If you want, you can include it in the download, it's your choice. Download here

<{POST_SNAPBACK}>


Thanks! I could do at least one more update for this, and I would include that tutorial. For now, I went ahead and linked to your download in the first post.
  • 0

#33 weckar

weckar

    Helping Hand

  • New Member
  • 1946 posts

Posted 09 August 2007 - 12:42 PM

Gesture Tutorial Extended

Point Grid Shapes

Let us say you want to add a trapezoid to the system using the point grid method. The first thing you have to do is create a point grid like this:

trapezoid_grid = pointgrid_create();

<{POST_SNAPBACK}>

Sorry to bother you, but where exactly does this go?
  • 0

#34 Seeker

Seeker

    GMC Member

  • GMC Member
  • 365 posts

Posted 09 August 2007 - 05:11 PM

No bother. I appreciate comments. :lol:

You can put that code in your controller object's Creation event. Since this information is buried in my comments, I'll post this here for everyone:

Only about 6 of the 120+ scripts are needed for the gesture recognition part of the Point Magic system:

1. gesture_init() can go in your controller/main object's Creation event. 0 arguments.

2. gesture_update() can go in a Step event of the main object. See arguments in script.

3. gesture_end() can go in the Game End event. 0 arguments.

4. You can use shape_grid = pointgrid_create() for each shape you are creating. 0 arguments.

5. You can use the pointgrid_add() scripts to add points that form a shape to a shape_grid. See arguments in script.

6. Finally, you can use shape_name = gesture_define() to define each gesture based on a shape_grid you added points to. See arguments in script.

So you guys can of course just import the scripts you actually need into your game. Though some of these scripts depend on a few other scripts, which you'll easily notice.

For those that want to know how this works, you'll want to the check the comments in the gesture_define() script and the code in the gesture_update() and gesture_score() scripts in particular. In the end, the gesture recognition boils down to the use of a dot product for the pointgrid shape definitions and the use of a string similarity for the directional string shape definitions. There are a number of other things that happen, but they are best to be read in the source code.

I have a list of improvements for the system (most almost unnoticeable) and a few other things for the next version. (It might take awhile though.)

Edited by Seeker, 09 August 2007 - 05:39 PM.

  • 0

#35 weckar

weckar

    Helping Hand

  • New Member
  • 1946 posts

Posted 12 August 2007 - 10:46 PM

I finally got the hang of this! just made a rain spell, 4 curves baby! :D
  • 0

#36 Lukearentz

Lukearentz

    My Two Cents

  • New Member
  • 2587 posts

Posted 12 August 2007 - 11:13 PM

HEY!!!! THIS IS REALLY COOL :D AND IT SOLVED A PROBLEM I WAS HAVING
  • 0

#37 Seeker

Seeker

    GMC Member

  • GMC Member
  • 365 posts

Posted 14 August 2007 - 05:22 AM

I finally got the hang of this! just made a rain spell, 4 curves baby! :D

<{POST_SNAPBACK}>


I'm happy it's working out for you. :angry:

HEY!!!! THIS IS REALLY COOL :D AND IT SOLVED A PROBLEM I WAS HAVING

<{POST_SNAPBACK}>


Thank you. And I'm glad this helped you with ... something. (I wonder what that was.)

If anyone has any more questions or requests to help them quick start their projects, just let me know. I know all of my comments in the source code are a bore, and I don't mind if anyone asks me a question that is covered in the comments and tutorials. Thank you.
  • 0

#38 Kyle_Solo

Kyle_Solo

    GMC Member

  • GMC Member
  • 1070 posts

Posted 22 August 2007 - 02:15 PM

I encourage you to make an extension for it and post it on GMbase. It might get more of the attention it deserves that way. You could even split it into separate extensions (RTS movement, gesture recognition, Linerider) so users can pick and choose. That would also make it less of a monumental task.

Edited by Kyle_Solo, 22 August 2007 - 02:17 PM.

  • 0

#39 Seeker

Seeker

    GMC Member

  • GMC Member
  • 365 posts

Posted 23 August 2007 - 06:34 AM

I encourage you to make an extension for it and post it on GMbase.  It might get more of the attention it deserves that way.  You could even split it into separate extensions (RTS movement, gesture recognition, Linerider) so users can pick and choose.  That would also make it less of a monumental task.

<{POST_SNAPBACK}>


Thanks for the link! An extension is on my list of to-dos for the next version. One of my games will use this system, though it is a little bit further down the road than some of my other projects. So there will be an update, and I'll submit the extension to the site, but it will probably be awhile from now.
  • 0

#40 Creative Fusion

Creative Fusion

    GMC Member

  • New Member
  • 55 posts

Posted 13 November 2007 - 05:05 PM

Hi, J. This is AWESOME, my friend! I didn't know you could do stuff like this. It's perfect for my mouse gesture-centered Okami-like game. Kyle's is nice also but another think I really like is that you gave out the source file to this one. ;) I don't like using extensions.... I want to try to add gamepad support, so the source is necessary unless you already plan on adding it in a future update???

So thank you for this. It saves me tons of time from trying to figure out how to do this on my own. I already had an idea but yours seems much better using a dot product and such for the grid method. (I'm not sure about the other string method.) Keep up the great work!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users