Commit d78748ad authored by Dave Griffiths's avatar Dave Griffiths
Browse files

Merge branch 'master' of github.com:nebogeo/jellyfish

parents 1dd1cd0c defc708b
......@@ -36,9 +36,11 @@ if platform=='LINUX':
if platform=='RPI':
# raspberry pi
env.Append(LIBS = ['GLESv1_CM', 'EGL', 'bcm_host', 'X11', 'png', 'lo'])
env.Append(LIBS = ['GLESv1_CM', 'EGL', 'bcm_host', 'X11', 'png', 'lo', 'jpeg'])
env.Append(CCFLAGS=' -DFLX_RPI -fpermissive')
env.Append(CPPPATH = '/opt/vc/include/interface/vcos/pthreads/:/opt/vc/include/interface/vmcs_host/linux:/opt/vc/include/:.')
env.Append(LIBPATH = '/opt/vc/lib')
source.append(['rpi/input.cpp'])
env.Program(target=target, source=source)
......@@ -69,17 +69,17 @@
(define (set-remove a l)
(if (null? l)
'()
(if (eq? (car l) a)
(if (eqv? (car l) a)
(set-remove a (cdr l))
(cons (car l) (set-remove a (cdr l))))))
(define (set-add a l)
(if (not (memq a l))
(if (not (memv a l))
(cons a l)
l))
(define (set-contains a l)
(if (not (memq a l))
(if (not (memv a l))
#f
#t))
......@@ -93,7 +93,7 @@
(define (register-down key button special state x y mod)
(when (not (or (number? key) (eq? key -1))) ; ordinary keypress
(set! keys (set-add key keys))
(set! keys (set-add key keys))
(set! keys-this-frame (set-add key keys-this-frame)))
(when (not (= special -1)) ; special keypress
(set! special-keys (set-add special special-keys))
......@@ -146,7 +146,8 @@
(define (fluxus-input-callback key button special state x y mod)
(register-down key button special state x y mod)
(input-camera key button special state x y mod width height))
;(input-camera key button special state x y mod width height)
)
(define (fluxus-input-release-callback key button special state x y mod)
(register-up key button special state x y mod))
......
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; jellyfish livecoding stuff
(define (jelly-compiled code)
(define addr 0)
(for-each
(lambda (v)
(pdata-set! "x" addr v)
(set! addr (+ addr 1)))
code))
(define jellyfish
(define player
(list
(build-jellyfish 512)
(build-jellyfish 512)
(build-jellyfish 512)))
(vector 0 6 0)
0
(with-state
(translate (vector 0 6 0))
(build-cube))))
(define current 0)
(define (player-pos player) (list-ref player 0))
(define (player-modify-pos player v) (list-replace player 0 v))
(define (player-dir player) (list-ref player 1))
(define (player-modify-dir player v) (list-replace player 1 v))
(define (player-root player) (list-ref player 2))
(define (rot2d v a)
(vector (+ (* (vx v) (sin a))
(* (vz v) (cos a)))
(vy v)
(+ (* (vx v) (cos a))
(* (vz v) (- (sin a))))))
(define (update-player player)
(with-primitive
(player-root player)
(identity)
(translate (player-pos player))
(rotate (vector 0 (player-dir player) 0)))
(player-modify-pos
(player-modify-dir
player
(+ (player-dir player)
(cond
((key-pressed "a") -1)
((key-pressed "d") 1)
(else 0))))
(vadd
(player-pos player)
(vmul
(rot2d (vector 0 0 1) (- (player-dir player)))
(cond
((key-pressed "w") 0.2)
((key-pressed "s") -0.2)
(else 0))))))
(define level
(with-state
(texture (load-texture "bg.png"))
(scale (vector 5 5 5))
(load-obj "assets/testlevel.obj")))
(with-primitive
level
(pdata-map!
(lambda (t) (vmul t 5)) "t"))
(lock-camera (player-root player))
(every-frame
(set! player (update-player player))
(with-primitive
(player-root player)
(rotate (vector 0 (if (key-pressed "a") 0.5 0) 0))))
<<<<<<< HEAD
=======
(define (make-jelly speed prim-type code)
(let ((p (list-ref jellyfish current)))
(msg p)
......@@ -65,3 +117,4 @@
(pdata-map! (lambda (t) (vmul t -1)) "t")
(pdata-map! (lambda (c) (vector 1 1 1)) "c")
(pdata-map! (lambda (n) (vector 0 0 0)) "n"))
>>>>>>> c0810fc558c7dd18b7fd92214be0f86de69524b4
......@@ -108,23 +108,6 @@
(else (_ (+ m 1) top))))))
(_ 0 (- (length l) 1)))
; utils funcs for using lists as sets
(define (set-remove a l)
(cond
((null? l) '())
(else
(if (eqv? (car l) a)
(set-remove a (cdr l))
(cons (car l) (set-remove a (cdr l)))))))
(define (set-add a l)
(if (not (memv a l))
(cons a l) l))
(define (set-contains a l)
(if (not (memq a l)) #f #t))
(define (build-list fn n)
(define (_ fn n l)
(cond ((zero? n) l)
......
......@@ -51,6 +51,8 @@ engine::engine()
{
m_sg=new scenegraph();
clear();
m_attached_prim = NULL;
m_attached_id = 0;
m_audio_graph = new Graph(70,16000);
}
......@@ -129,6 +131,12 @@ scenenode *engine::grabbed_node()
return n;
}
void engine::lock_camera(int id)
{
m_attached_id=id;
m_attached_prim=m_sg->find(id);
}
void engine::identity()
{
if (grabbed())
......@@ -370,6 +378,12 @@ void engine::clear()
void engine::destroy(int id)
{
// clear camera attachment if it's this primitive
if (m_attached_id == id) {
m_attached_prim = NULL;
m_attached_id = 0;
}
m_sg->remove(id);
}
......@@ -533,6 +547,11 @@ void engine::render()
glLightxv(GL_LIGHT0, GL_POSITION, (GLfixed *)buf);
glMultMatrixx((GLfixed*)&m_camera_tx.m[0][0]);
if (m_attached_prim!=NULL) {
glMultMatrixx((GLfixed*)&m_attached_prim->m_tx.inverse().m[0][0]);
}
// glMultMatrixf(&m_camera_tx.m[0][0]);
#endif
m_sg->render();
......
......@@ -37,6 +37,7 @@ public:
void pop();
void grab(int id);
void ungrab();
void lock_camera(int id);
void identity();
void translate(float x, float y, float z);
......@@ -126,6 +127,9 @@ private:
Graph *m_audio_graph;
unsigned int m_screen_width;
unsigned int m_screen_height;
// camera attached to primitive...
int m_attached_id;
scenenode *m_attached_prim;
mat44 m_camera_tx;
//mat44 m_inv_camera_tx;
};
......
......@@ -38,6 +38,8 @@ extern "C"
#include <assert.h>
#include "bcm_host.h"
#include "rpi/input.h"
typedef struct
{
uint32_t screen_width;
......@@ -59,6 +61,8 @@ int w,h=0;
int gAppAlive = 1;
int modifiers = 0;
pthread_mutex_t* render_mutex;
static const string INPUT_CALLBACK="fluxus-input-callback";
static const string INPUT_RELEASE_CALLBACK="fluxus-input-release-callback";
// setup the assets location
// on linux, mimic android, otherwise load locally on rpi
......@@ -345,6 +349,44 @@ void DisplayCallback()
} //else { printf("locked\n"); }
}
// pasted from nomadic engine...??
void KeyboardCallback(unsigned char key,int x, int y)
{
char code[256];
#ifdef FLX_RPI
int imod = 0;
sprintf(code,"(%s #\\%c %d %d %d %d %d %d)",INPUT_CALLBACK.c_str(),key,-1,-1,-1,x,y,imod);
appEval(code);
#else
int mod=modifiers;
mod=glutGetModifiers();
if (key > 0 && key<0x80)
{ // key is 0 on ctrl+2 and ignore extended ascii for the time being
int imod = 0;
if (mod & GLUT_ACTIVE_SHIFT)
imod |= 1;
if (mod & GLUT_ACTIVE_CTRL)
imod |= 2;
if (mod & GLUT_ACTIVE_ALT)
imod |= 4;
sprintf(code,"(%s #\\%c %d %d %d %d %d %d)",INPUT_CALLBACK.c_str(),key,-1,-1,-1,x,y,imod);
appEval(code);
}
#endif
}
void KeyboardUpCallback(unsigned char key,int x, int y)
{
char code[256];
if (key > 0 && key<0x80) {
// key is 0 on ctrl+2
sprintf(code,"(%s #\\%c %d %d %d %d %d %d)",INPUT_RELEASE_CALLBACK.c_str(),key,-1,-1,-1,x,y,0);
appEval(code);
}
}
#ifdef FLX_RPI
static void init_ogl_rpi(RPI_STATE_T *state)
......@@ -367,6 +409,7 @@ static void init_ogl_rpi(RPI_STATE_T *state)
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 16,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_NONE
};
......@@ -423,13 +466,13 @@ static void init_ogl_rpi(RPI_STATE_T *state)
assert(EGL_FALSE != result);
// Set background color and clear buffers
glClearColor(0.f, 0.f, 0.f, 0.5f);
/* glClearColor(1.f, 0.f, 0.f, 0.5f);
glClear( GL_COLOR_BUFFER_BIT );
glClear( GL_DEPTH_BUFFER_BIT );
//glShadeModel(GL_FLAT);
// Enable back face culling.
// glEnable(GL_CULL_FACE);
glEnable(GL_CULL_FACE); */
}
#endif
......@@ -523,6 +566,8 @@ int main(int argc, char *argv[])
appLoadTexture("raspberrypi.png",w,h,(char *)tex);
tex=LoadPNG(ASSETS_LOCATION+"stripes.png",w,h);
appLoadTexture("stripes.png",w,h,(char *)tex);
tex=LoadPNG(ASSETS_LOCATION+"bg.png",w,h);
appLoadTexture("bg.png",w,h,(char *)tex);
tex=LoadPNG(ASSETS_LOCATION+"thread.png",w,h);
appLoadTexture("thread.png",w,h,(char *)tex);
......@@ -533,16 +578,23 @@ int main(int argc, char *argv[])
}
// setup the repl thread
render_mutex = new pthread_mutex_t;
render_mutex = new pthread_mutex_t;
pthread_mutex_init(render_mutex,NULL);
pthread_t *repl_thread = new pthread_t;
/*pthread_t *repl_thread = new pthread_t;
pthread_create(repl_thread,NULL,(void*(*)(void*))repl_loop,NULL);
setup_osc_repl();
*/
#ifdef FLX_RPI
getMouse();
getKeys();
while (!terminate_prog)
{
doEvents(state->screen_width, state->screen_height,
KeyboardCallback,
KeyboardUpCallback);
//usleep(5*1000);
DisplayCallback();
}
......
......@@ -209,6 +209,7 @@
_OP_DEF(opexe_6, "grab", 1, 1, 0, OP_GRAB )
_OP_DEF(opexe_6, "ungrab", 0, 0, 0, OP_UNGRAB )
_OP_DEF(opexe_6, "parent", 1, 1, 0, OP_PARENT )
_OP_DEF(opexe_6, "lock-camera", 1, 1, 0, OP_LOCK_CAMERA )
_OP_DEF(opexe_6, "identity", 0, 0, 0, OP_IDENTITY )
_OP_DEF(opexe_6, "translate", 1, 1, 0, OP_TRANSLATE )
_OP_DEF(opexe_6, "rotate", 1, 1, 0, OP_ROTATE )
......
......@@ -4574,6 +4574,8 @@ static pointer opexe_6(scheme *sc, enum scheme_opcodes op) {
engine::get()->ungrab(); s_return(sc,sc->F);
case OP_PARENT:
engine::get()->parent(ivalue(car(sc->args))); s_return(sc,sc->F);
case OP_LOCK_CAMERA:
engine::get()->lock_camera(ivalue(car(sc->args))); s_return(sc,sc->F);
case OP_IDENTITY:
engine::get()->identity(); s_return(sc,sc->F);
case OP_TRANSLATE:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment