Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dave Griffiths
jellyfish
Commits
c5c85eae
Commit
c5c85eae
authored
Jan 19, 2015
by
dave griffiths
Browse files
pi changes from something
parent
98d641bb
Changes
9
Hide whitespace changes
Inline
Side-by-side
SConstruct
View file @
c5c85eae
...
...
@@ -23,7 +23,9 @@ source = ['main.cpp',
'engine/texture.cpp'
,
'engine/nomadic.cpp'
,
'jellyfish/jellyfish_primitive.cpp'
,
'jellyfish/jellyfish.cpp'
'jellyfish/jellyfish.cpp'
,
'rpi/input.cpp'
]
if
platform
==
'LINUX'
:
...
...
assets/boot.scm
View file @
c5c85eae
...
...
@@ -69,17 +69,17 @@
(
define
(
set-remove
a
l
)
(
if
(
null?
l
)
'
()
(
if
(
eq?
(
car
l
)
a
)
(
if
(
eq
v
?
(
car
l
)
a
)
(
set-remove
a
(
cdr
l
))
(
cons
(
car
l
)
(
set-remove
a
(
cdr
l
))))))
(
define
(
set-add
a
l
)
(
if
(
not
(
mem
q
a
l
))
(
if
(
not
(
mem
v
a
l
))
(
cons
a
l
)
l
))
(
define
(
set-contains
a
l
)
(
if
(
not
(
mem
q
a
l
))
(
if
(
not
(
mem
v
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
))
...
...
assets/jellyfish.scm
View file @
c5c85eae
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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
(
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
))))
(
define
current
0
)
(
define
(
make-jelly
speed
prim-type
code
)
(
let
((
p
(
list-ref
jellyfish
current
)))
(
msg
p
)
(
with-primitive
p
(
let
((
c
(
compile-program
speed
prim-type
1
code
)))
;; (disassemble c)
(
jelly-compiled
c
))
(
set!
current
(
modulo
(
+
current
1
)
(
length
jellyfish
)))
p
)))
(
with-primitive
(
make-jelly
10000
prim-triangles
'
(
let
((
vertex
positions-start
)
(
flingdamp
(
vector
50
-20
0
))
(
world
(
vector
0
0
0
))
(
t
0
))
(
define
recycle
(
lambda
(
dir
)
;; shift along x and y coordinates:
;; set z to zero for each vertex
(
write!
vertex
(
+
(
*v
(
read
vertex
)
(
vector
1
1
0
))
dir
)
(
+
(
*v
(
read
(
+
vertex
1
))
(
vector
1
1
0
))
dir
)
(
+
(
*v
(
read
(
+
vertex
2
))
(
vector
1
1
0
))
dir
))
;; get the perlin noise values for each vertex
(
let
((
a
(
noise
(
*
(
-
(
read
vertex
)
world
)
0.2
)))
(
b
(
noise
(
*
(
-
(
read
(
+
vertex
1
))
world
)
0.2
)))
(
c
(
noise
(
*
(
-
(
read
(
+
vertex
2
))
world
)
0.2
))))
;; set the z coordinate for height
(
write-add!
vertex
(
+
(
*v
a
(
vector
0
0
8
))
(
vector
0
0
-4
))
(
+
(
*v
b
(
vector
0
0
8
))
(
vector
0
0
-4
))
(
+
(
*v
c
(
vector
0
0
8
))
(
vector
0
0
-4
)))
;; recalculate normals
(
define
n
(
normalise
(
cross
(
-
(
read
vertex
)
(
read
(
+
vertex
1
)))
(
-
(
read
vertex
)
(
read
(
+
vertex
2
))))))
;; write to normal data
(
write!
(
+
vertex
512
)
n
n
n
)
;; write the z height as texture coordinates
(
write!
(
+
vertex
1536
)
(
*v
(
swizzle
zzz
a
)
(
vector
0
4
0
))
(
*v
(
swizzle
zzz
b
)
(
vector
0
4
0
))
(
*v
(
swizzle
zzz
c
)
(
vector
0
4
0
))))))
;; forever
(
forever
(
define
vel
(
*
flingdamp
0.002
))
;; update the world coordinates
(
set!
world
(
+
world
vel
))
(
set!
t
(
+
t
0.1
))
;; for each vertex
(
loop
(
<
vertex
(
-
positions-end
3
))
;; update the vertex position
(
write-add!
vertex
vel
vel
vel
)
;; check for out of area polygons to recycle
(
cond
((
>
(
read
vertex
)
5.0
)
(
recycle
(
vector
-10
0
0
)))
((
<
(
read
vertex
)
-5.0
)
(
recycle
(
vector
10
0
0
))))
(
cond
((
>
(
swizzle
yzz
(
read
vertex
))
4.0
)
(
recycle
(
vector
0
-8
0
)))
((
<
(
swizzle
yzz
(
read
vertex
))
-4.0
)
(
recycle
(
vector
0
8
0
))))
(
set!
vertex
(
+
vertex
3
)))
(
set!
vertex
positions-start
))))
(
pdata-map!
(
lambda
(
n
)
(
vmul
(
vector
(
crndf
)
(
crndf
)
0
)
0.001
))
"n"
)
(
pdata-map!
(
lambda
(
c
)
(
vector
1
1
1
))
"c"
)
(
texture
(
load-texture
"stripes.png"
))
(
translate
(
vector
-1
2
0
))
(
rotate
(
vector
-45
0
0
))
; (rotate (vector 0 0 100))
(
scale
(
vector
1.5
1.5
1.5
))
(
let
((
tsize
1
)
(
twidth
8
))
(
pdata-index-map!
(
lambda
(
i
p
)
(
let*
((
tpos
(
modulo
i
3
))
(
tri
(
quotient
i
3
))
(
flip
(
modulo
tri
2
))
(
quad
(
quotient
tri
2
))
(
col
(
modulo
quad
twidth
))
(
row
(
quotient
quad
twidth
)))
(
vadd
(
vector
(
+
(
*
row
tsize
)
10
)
(
*
col
tsize
)
0
)
(
vmul
(
if
(
zero?
flip
)
(
cond
((
eqv?
tpos
0
)
(
vector
0
0
0
))
((
eqv?
tpos
1
)
(
vector
tsize
0
0
))
((
eqv?
tpos
2
)
(
vector
tsize
tsize
0
)))
(
cond
((
eqv?
tpos
0
)
(
vector
0
0
0
))
((
eqv?
tpos
1
)
(
vector
tsize
tsize
0
))
((
eqv?
tpos
2
)
(
vector
0
tsize
0
))))
1
))))
"p"
))
(
pdata-map!
(
lambda
(
t
)
(
vector
0
0
0
))
"t"
)
)
assets/lib.scm
View file @
c5c85eae
...
...
@@ -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
)
...
...
engine/engine.cpp
View file @
c5c85eae
...
...
@@ -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
();
...
...
engine/engine.h
View file @
c5c85eae
...
...
@@ -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;
};
...
...
main.cpp
View file @
c5c85eae
...
...
@@ -32,6 +32,7 @@
#ifdef FLX_RPI
#include <assert.h>
#include "bcm_host.h"
#include "rpi/input.h"
typedef
struct
{
...
...
@@ -54,6 +55,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
...
...
@@ -235,6 +238,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
)
...
...
@@ -257,6 +298,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
};
...
...
@@ -313,13 +355,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.5
f
);
/*
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
...
...
@@ -413,20 +455,29 @@ 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
);
appEval
((
char
*
)
LoadFile
(
ASSETS_LOCATION
+
"jellyfish.scm"
).
c_str
());
// 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
();
}
...
...
scheme/opdefines.h
View file @
c5c85eae
...
...
@@ -207,6 +207,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
)
...
...
scheme/scheme.cpp
View file @
c5c85eae
...
...
@@ -4442,6 +4442,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
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment