Commit 31bf2ee1 authored by Dave Griffiths's avatar Dave Griffiths
Browse files

more sb fixes/additions - eg concat

parent 99ffd7c3
......@@ -71,6 +71,7 @@
(define (mouse-x) (vector-ref mouse 0))
(define (mouse-y) (vector-ref mouse 1))
(define (mouse-wheel) mouse-wheel-v)
;;(define (mouse-button n)
;; (if _touching
......@@ -522,7 +523,7 @@
;; detach and retain original transform
(define (detach-parent)
(let ((m (get-global-transform)))
(parent 1) ;; reparent to root
(parent 0) ;; reparent to root
(identity)
(concat m)))
......
......@@ -512,8 +512,8 @@
(with-primitive
(brick-id b)
(recalc-bb)
(if (bb/point-intersect? pos 0.1) b #f)
#f)
(get-global-transform)
(if (eqv? (bb/point-intersect? pos 0.1) 1) b #f))
hit)))
(define (brick-intersect-no-atoms b pos)
......@@ -527,8 +527,7 @@
(with-primitive
(brick-id b)
(recalc-bb)
(if (bb/point-intersect? pos 0.1) b #f)
#f)
(if (eqv? (bb/point-intersect? pos 0.1) 1) b #f))
hit))
#f))
......@@ -920,31 +919,33 @@
b)))
(define (bricks-do-mouse-wheel b pos)
(let ((over (bricks-get-over b pos)))
(when over
(let ((root (bricks-root-search b (brick-id over))))
(if (brick-locked root) ;; it's the palette, translate
(with-primitive
(brick-id root)
(when (or (< (mouse-wheel) 0) (key-special-pressed 103))
(translate (vector 0 6 0)))
(when (or (> (mouse-wheel) 0) (key-special-pressed 101))
(translate (vector 0 -6 0))))
(with-primitive ;; it's a normal brick, scale
(brick-id root)
(let* ((t (get-transform))
(d (vsub pos (vtransform (vector 0 0 0) (get-transform))))
(d2 (vmul d (/ 1 (vector-ref (get-transform) 0)))))
(when (or (< (mouse-wheel) 0) (key-special-pressed 103))
(translate d2)
(scale (vector 0.9 0.9 0.9))
(translate (vmul d2 -1)))
(when (or (> (mouse-wheel) 0) (key-special-pressed 101))
(translate d2)
(scale (vector 1.1 1.1 1.1))
(translate (vmul d2 -1))
))))))
b))
(if (zero? (mouse-wheel))
b
(let ((over (bricks-get-over b pos)))
(when over
(let ((root (bricks-root-search b (brick-id over))))
(if (brick-locked root) ;; it's the palette, translate
(with-primitive
(brick-id root)
(when (or (< (mouse-wheel) 0) (key-special-pressed 103))
(translate (vector 0 6 0)))
(when (or (> (mouse-wheel) 0) (key-special-pressed 101))
(translate (vector 0 -6 0))))
(with-primitive ;; it's a normal brick, scale
(brick-id root)
(let* ((t (get-transform))
(d (vsub pos (vtransform (vector 0 0 0) (get-transform))))
(d2 (vmul d (/ 1 (vector-ref (get-transform) 0)))))
(when (or (< (mouse-wheel) 0) (key-special-pressed 103))
(translate d2)
(scale (vector 0.9 0.9 0.9))
(translate (vmul d2 -1)))
(when (or (> (mouse-wheel) 0) (key-special-pressed 101))
(translate d2)
(scale (vector 1.1 1.1 1.1))
(translate (vmul d2 -1))
))))))
b)))
(define (bricks-do-input b pos)
(bricks-do-mouse-wheel
......@@ -1111,7 +1112,7 @@
;; keep the children visible
(with-primitive (brick-id palette)
(translate (vector 25 10 0))
(scale 0.7)
;(scale 0.7)
;(opacity 0)
(hint-nozwrite))
(with-primitive (brick-depth palette)
......@@ -1139,13 +1140,18 @@
(when sound-fac (set! b (bricks-load b "ambstart.scm")))
;(set! b (bricks-load b "click.scm"))
(define ttt (with-state (translate (vector 4 4 0)) (build-cube)))
(with-primitive ttt (apply-transform) (recalc-bb))
(set! b (let ((brick
(code->brick '(ONE green (blue 1 2 3) red))))
(bricks-add-root b brick)))
(every-frame
(begin
(with-primitive pointer
(identity)
(translate (get-point-from-mouse))
(scale 0.1))
(scale 1))
(set! b (bricks-update! b))
(with-primitive t (rotate (vector 1 2 3)))))
......@@ -79,9 +79,8 @@
(identity)
(define a (build-cube))
(define b (with-state (parent a) (build-cube)))
(define c (build-cube))
(with-primitive b (parent c))
;; check intersections
(with-primitive
a
(recalc-bb)
......@@ -90,3 +89,13 @@
(translate (vector 10 0 0))
(msg "bb/point-intersect? 1=" (bb/point-intersect? (vector 10 0 0) 0))
)
;; check bb/point intersect works in global coords
(define c (build-cube))
(with-primitive b (translate (vector 10 0 0)))
(with-primitive c (parent b))
(with-primitive
c
(recalc-bb)
(msg "bb/point-intersect? 1=" (bb/point-intersect? (vector 20 0 0) 0)))
......@@ -183,6 +183,18 @@ void engine::rotate(float x, float y, float z)
}
}
void engine::concat(mat44 m)
{
if (grabbed())
{
grabbed_node()->m_tx*=m;
}
else
{
state_top()->m_tx*=m;
}
}
void engine::colour(float r, float g, float b, float a)
{
if (grabbed())
......@@ -526,7 +538,7 @@ bool engine::bb_point_intersect(const vec3 &p, flx_real threshold)
scenenode *n = grabbed_node();
if (n && n->m_primitive!=NULL)
{
vec3 pt=n->m_tx.inverse().transform(p);
vec3 pt=m_sg->get_global_transform(n).inverse().transform(p);
return n->m_primitive->intersect_bb(pt,threshold);
}
}
......
......@@ -42,6 +42,7 @@ public:
void scale(float x, float y, float z);
void rotate(float x, float y, float z);
void colour(float r, float g, float b, float a);
void concat(mat44 m);
void hint(u32 hint);
void line_width(u32 w);
void texture(u32 id);
......
......@@ -193,6 +193,10 @@ void primitive::recalc_bb()
bool primitive::intersect_bb(const vec3 &p, flx_real threshold)
{
// cerr<<(float)p.x<<" "<<(float)p.y<<" "<<(float)p.z<<endl;
// cerr<<(float)m_bbmin.x<<" "<<(float)m_bbmin.y<<" "<<(float)m_bbmin.z<<endl;
// cerr<<(float)m_bbmax.x<<" "<<(float)m_bbmax.y<<" "<<(float)m_bbmax.z<<endl;
return intersect_point_bb(p, m_bbmin, m_bbmax, threshold);
}
......
......@@ -143,7 +143,6 @@ void MouseCallback(int button, int state, int x, int y)
char code[256];
snprintf(code,256,"(%s %d %d %d %d %d %d %d)",INPUT_CALLBACK.c_str(),0,button,-1,state,x,y,0);
appEval(code);
cerr<<code<<endl;
}
void MotionCallback(int x, int y)
......
......@@ -220,6 +220,7 @@
_OP_DEF(opexe_6, "translate", 1, 1, 0, OP_TRANSLATE )
_OP_DEF(opexe_6, "rotate", 1, 1, 0, OP_ROTATE )
_OP_DEF(opexe_6, "scale", 1, 1, 0, OP_SCALE )
_OP_DEF(opexe_6, "concat", 1, 1, 0, OP_CONCAT )
_OP_DEF(opexe_6, "colour", 1, 1, 0, OP_COLOUR )
_OP_DEF(opexe_6, "hint", 1, 1, 0, OP_HINT )
_OP_DEF(opexe_6, "line-width", 1, 1, 0, OP_LINE_WIDTH )
......
......@@ -4583,6 +4583,28 @@ static pointer opexe_6(scheme *sc, enum scheme_opcodes op) {
rvalue(vector_elem(car(sc->args),1)),
rvalue(vector_elem(car(sc->args),2)));
s_return(sc,sc->F);
case OP_CONCAT:
{
mat44 t = mat44(rvalue(vector_elem(car(sc->args),0)),
rvalue(vector_elem(car(sc->args),1)),
rvalue(vector_elem(car(sc->args),2)),
rvalue(vector_elem(car(sc->args),3)),
rvalue(vector_elem(car(sc->args),4)),
rvalue(vector_elem(car(sc->args),5)),
rvalue(vector_elem(car(sc->args),6)),
rvalue(vector_elem(car(sc->args),7)),
rvalue(vector_elem(car(sc->args),8)),
rvalue(vector_elem(car(sc->args),9)),
rvalue(vector_elem(car(sc->args),10)),
rvalue(vector_elem(car(sc->args),11)),
rvalue(vector_elem(car(sc->args),12)),
rvalue(vector_elem(car(sc->args),13)),
rvalue(vector_elem(car(sc->args),14)),
rvalue(vector_elem(car(sc->args),15)));
t.transpose();
engine::get()->concat(t);
s_return(sc,sc->F);
}
case OP_COLOUR:
engine::get()->colour(rvalue(vector_elem(car(sc->args),0)),
rvalue(vector_elem(car(sc->args),1)),
......
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