|
Post by basica on Nov 19, 2015 21:18:10 GMT 1
Yes, vovchik is right. The robot-dancing presentation is better in person I was playing with canvas and thought it might be handy to have a mouse function. So here's a "front end" demo for canvas using Glut which adds a mouse callback. INCLUDE canvas.bac
FUNCTION Load_mouse
LOCAL lib$ LOCAL seq
CATCH GOTO lib_handle_error
lib$ = "libglut.so.0"
LABEL lib_import_retry IMPORT "glutMouseFunc(void*)" FROM lib$ TYPE void GOTO lib_continue
LABEL lib_handle_error INCR seq IF seq > 100 THEN RETURN FALSE lib$ = LEFT$(lib$, INSTRREV(lib$, ".")) & STR$(seq) GOTO lib_import_retry LABEL lib_continue
RETURN TRUE END FUNCTION
IF CANVAS.library$ = "GLUT" THEN Load_mouse
CONST GLUT_LEFT_BUTTON = 0 CONST GLUT_MIDDLE_BUTTON = 1 CONST GLUT_RIGHT_BUTTON = 2 CONST GLUT_DOWN = 0
END IF
SUB mouse(int button, int state, int x, int y) IF button == GLUT_LEFT_BUTTON AND state == GLUT_DOWN THEN PRINT "mouse left click event -mouse at Width ", x, " and Height ", y INK(0,255,0, 255)
Txt$ = "You clicked left button" TEXT(Txt$, 15, 60)
glutSwapBuffers ENDIF
IF button == GLUT_RIGHT_BUTTON AND state == GLUT_DOWN THEN PRINT "mouse right click event -mouse at Width ", x, " and Height ", y INK(255,0,255, 255) Txt$ = "You clicked right button and made a ball" TEXT(Txt$, 10, 105) CIRCLE(x, y, 10, 10,TRUE) glutSwapBuffers ENDIF ENDSUB
width = 640 height = 480 WINDOW("Glut mouse", width, height) INK(0,0,0,255) Txt$ = "Click left or right button on screen" TEXT(Txt$, 15, 15) glutMouseFunc(mouse) WAITKEY
Regards, basica
|
|
|
Post by vovchik on Nov 19, 2015 22:11:01 GMT 1
Dear basica, Very nice work - I once included a primitive mouse quit function in a few demos but your implementation is just what we want, I think. I am now seeing how I can include it in some of my little things to make them interactive. Thanks. Alex has also worked on keyboard controls and has that bit nailed With kind regards, vovchik
|
|
|
Post by alexfish on Nov 19, 2015 23:21:27 GMT 1
Hi Guys.. Thanks.. will be updating the key's shortly, need to cleanup two sides, keyboard + special-keys.. one has keys as in the up ,down, left right. the other passes the value of the char , as in the actual keyboard QWERTY. suppose that depands on the key mapping as well. anyway . Poor Robby the robot , alas could not stand the G forces involved in the Acrobat routines and has met is fate. his bits are now lost in space. using same code and adapted the SIZE next to the BSIZE , think Vovchik may find one bit in there of use.. or more as can see by the screen shot . code has been zipped. Attachment DeletedHave Fun + BR Alex
|
|
|
Post by vovchik on Nov 20, 2015 11:31:41 GMT 1
Dear Alex, Fab ... and only 6.5k when stripped and UPX'd. With kind regards, vovchik
|
|
|
Post by vovchik on Nov 20, 2015 11:46:15 GMT 1
Dear all, This is a brute-force way of doing a radial background without invoking vertices and other GL externals. The disadvantage is that it is relatively slow, since it has to draw a lot of circles. The advantage is that it is rather straightforward. With kind regards, vovchik
|
|
|
Post by alexfish on Nov 20, 2015 15:02:26 GMT 1
Hi all ,
was thinking back , one of the graphics libs had sound based on lib canberra , it was done in protto includes
looks like most modern systems have canberra in on default installs hence sure be able to IMPORT it
Can Try this code below . + change the sound file path to suit
BR Alex
FUNCTION Import_CANBERRA_functions()
LOCAL lib$ LOCAL seq
CATCH GOTO lib_handle_error
lib$ = "libcanberra.so.0"
LABEL lib_import_retry
IMPORT "ca_context_create(void*)" FROM lib$ TYPE int GOTO lib_continue
LABEL lib_handle_error INCR seq IF seq > 100 THEN RETURN FALSE lib$ = LEFT$(lib$, INSTRREV(lib$, ".")) & STR$(seq) GOTO lib_import_retry
LABEL lib_continue
IMPORT ca_context_set_driver(void*, char*) FROM lib$ TYPE int IMPORT ca_context_play(void*, int, char*,char*,...) FROM lib$ TYPE int
RETURN TRUE
END FUNCTION
LOCAL * context TYPE long LOCAL a,b
a = Import_CANBERRA_functions() REM a 0 = success PRINT a IF a THEN a = ca_context_create(&context) REM a 0 = success PRINT a a = ca_context_set_driver(context, "alsa") REM a 0 = success PRINT a REM point the file to a knowen a=ca_context_play(context, 0,"media.filename","/home/pi/python_games/badswap.wav", NULL) IF a != 0 THEN PRINT "Warning : Canberra :: Sound file not exist or invalid type" ELSE PRINT " OK" END IF
ENDIF
|
|
|
Post by vovchik on Nov 20, 2015 15:31:13 GMT 1
Dear Alex, I remember doing the sound bits. They are here.... With kind regards, vovchik PS. You need to change INCLUDE canberra.h to INCLUDE /usr/include/canberra.h to get it to compile and run (and the sound files need to be there).
|
|
|
Post by alexfish on Nov 20, 2015 16:53:37 GMT 1
Hi Vovchik
changed the compiler directives for the canberra devs to
' *********************** ' COMPILER DIRECTIVES ' ***********************
PRAGMA INCLUDE <canberra.h> PRAGMA LDFLAGS canberra
everything works as expected BR Alex
Seems got a problem with a couple of the demo's most notable the last rad grad
Not sure what it be , pi related or glut pi related or glut related stack problem , when going into a loop with a lot of draw routines the screen doe not update
the program runs doing the loops for redraw , but as they say No Cigar or a one not lit . now looking further ..
|
|
|
Post by vovchik on Nov 20, 2015 17:02:48 GMT 1
Dear Alex, Here is a pretty bare-bones demo with wav file included and using your PRAGMA. Works nicely.... With kind regards, vovchik Attachments:canberra-demo.bac.tar.gz (125.26 KB)
|
|
|
Post by vovchik on Nov 22, 2015 11:45:10 GMT 1
Dear All, Just a few demos with a radial band background and orbs drawn using lines. With kind regards, vovchik PS. Added a little animated demo to the archive.
|
|
|
Post by vovchik on Nov 22, 2015 15:50:10 GMT 1
Dear All, Here is a rounded rectangle (and rectangular circle). With kind regards, vovchik
|
|
|
Post by vovchik on Nov 22, 2015 21:20:03 GMT 1
Dear all, This is a little exploration with circles and segments thereof, drawn with lines. The upper left segment should taper off on the left, and I am still looking into why it doesn't. If you have a fix, please post it. With kind regards, vovchik
|
|
|
Post by vovchik on Nov 23, 2015 15:08:21 GMT 1
Dear All, Here is a rather pretty radial band background routine - you can change mode (horizontal, vertical or both) and the two colours. Have fun... With kind regards, vovchik
|
|
|
Post by alexfish on Nov 23, 2015 23:48:58 GMT 1
Hi Vovchik not sure what I be looking in the algo's , all in think looking at circular reference to then , not sure if getting a cut of segment possible . Have done a couple of algo's , algo 2 may help pin point the bit U be looking for, algo 1 will draw a line , triangle , square + any number of sides (scalar polys so to speak) algo 2 the same but will close the lineloop or poly at a prdefined end based on the x cord start and y cord end BR Alex INCLUDE canvas.bac
DECLARE canvas_w, canvas_h canvas_w = 800 canvas_h = 600
SUB MY_ALGO2 (x, y, start_deg, end_deg, xsize, ysize, sides, fill)
LOCAL i , cnt=0 LOCAL xt#, yt#,startX#,startY#,endX#,endY#
CALL Draw_Prepare CALL Check_Scale(x-xsize, y-ysize, xsize, ysize) CALL Check_Rotation(x-xsize, y-ysize, xsize, ysize) CALL Check_Move()
IF fill THEN glBegin(GL_POLYGON) ELSE glBegin(GL_LINE_LOOP) END IF
FOR i = start_deg TO end_deg STEP 360/sides xt# = xsize*COS(RAD(i)) yt# = ysize*SIN(RAD(i)) glVertex2f(x+xt#, y+yt#) IF cnt = 0 THEN startX# = xt# startY# = yt# END IF endX# = xt# endY# = yt# INCR cnt NEXT glVertex2f(x+endX#,y+startY#) glEnd
ENDSUB
SUB MY_ALGO1 (x, y, xsize, ysize, sides, fill)
LOCAL i LOCAL xt#, yt#
CALL Draw_Prepare CALL Check_Scale(x-xsize, y-ysize, xsize, ysize) CALL Check_Rotation(x-xsize, y-ysize, xsize, ysize) CALL Check_Move()
IF fill THEN glBegin(GL_POLYGON) ELSE glBegin(GL_LINE_LOOP) END IF
FOR i = 0 TO 360 STEP 360/sides xt# = xsize*COS(RAD(i)) yt# = ysize*SIN(RAD(i)) glVertex2f(x+xt#, y+yt#) NEXT
glEnd
ENDSUB
WINDOW("Circles & Segments et'all Kitchen Sink ", canvas_w, canvas_h) SYNC INK(0, 0, 0, 230) CLS INK(255, 0, 0, 255) MY_ALGO2 (200,200,180,270, 200,100,60,1) INK(0, 255, 0, 255) MY_ALGO2 (200,400,230,270,200,100,60,1) MY_ALGO2 (400,400,230,310,200,100,60,0) MY_ALGO2 (400,400,0,360,50,50,30,1) MY_ALGO2 (400,200,0,360,50,50,4,1) MY_ALGO2 (400,100,0,360,50,50,3,1) MY_ALGO2 (450,100,0,360,100,100,2,0) SYNC WAITKEY
Picky Attachments:
|
|
|
Post by vovchik on Nov 24, 2015 21:31:06 GMT 1
Dear Alex,
Thanks - was not inet most of the day and only saw your code now. Looks good. Will now start playing.
With kind regards, vovchik
|
|