Skip to content
Snippets Groups Projects
Gview.cc 27.9 KiB
Newer Older
teuben's avatar
teuben committed
		dp.x[0],dp.x[1],dp.x[2],
		dq.q[0],dq.q[1],dq.q[2],dq.q[3]);
teuben's avatar
teuben committed
    }

    Matrix newTobj2w;
    mconjugate( &newTobj2w, &evTobj2w_, &Tincr,
		Tf2w, Tw2f, pcenterw, NULL );
    float scaling = vlength( (Point *)&evTobj2w_.m[0] );
    if(fabs(scaling - 1) < .01) {
teuben's avatar
teuben committed
	vgettranslation( &p, &newTobj2w );
	tfm2quat( &q, &newTobj2w );
	quat2tfm( &newTobj2w, &q );
	vscale( (Point *)&newTobj2w.m[0], scaling, (Point *)&newTobj2w.m[0] );
	vscale( (Point *)&newTobj2w.m[4], scaling, (Point *)&newTobj2w.m[4] );
	vscale( (Point *)&newTobj2w.m[8], scaling, (Point *)&newTobj2w.m[8] );
	vsettranslation( &newTobj2w, &p );
    }

    To2w( mytarget, &newTobj2w );
    redraw();
  }
}

void Fl_Gview::picksize( float width, float height )
{
  pickwidth_ = width;
  pickheight_ = height;
}

void Fl_Gview::pickbuffer( int nents, GLuint *buf )
{
  picknents_ = nents;
  pickbuf_ = buf;
}

slevy's avatar
slevy committed
void Fl_Gview::picker( void (*pickcb)(Fl_Gl_Window *, int, int, GLuint *, void *), void *arg )
teuben's avatar
teuben committed
{
  pickcb_ = pickcb;
  pickarg_ = arg;
}

slevy's avatar
slevy committed
void (*Fl_Gview::picker(void **argp))(Fl_Gl_Window *, int, int, GLuint *, void *)
teuben's avatar
teuben committed
{
  if(argp) *argp = pickarg_;
  return pickcb_;
}

int Fl_Gview::pickresults( int *nentp, GLuint **bufp )
{
  if(nentp) *nentp = picknents_;
  if(bufp) *bufp = pickbuf_;
  return pickhits_;
}

int Fl_Gview::do_pick( float xpick, float ypick )
{
  make_current();
  glSelectBuffer( picknents_, pickbuf_ );
  int ok = glRenderMode( GL_SELECT );
  if(ok != 0) {
    fprintf(stderr, "Trouble in do_pick: glRenderMode( GL_SELECT ) = %d\n", ok);
    ok = glRenderMode( GL_SELECT );
    fprintf(stderr, "Retry: %d\n", ok);
  }
  glPushName(0);

  inpick_ = 1;
  pickx_ = xpick;
  picky_ = ypick;
  draw();
  inpick_ = 0;

  glPopName();
  pickhits_ = glRenderMode( GL_RENDER );
  if(pickcb_)
    (*pickcb_)( this, pickhits_, picknents_, pickbuf_, pickarg_ );
  valid(0);
  return pickhits_;
}

Stuart Levy's avatar
Stuart Levy committed
const char *Fl_Gview::dname( int id ) {
teuben's avatar
teuben committed
  static char name[32];
  if(id < 0) return "[c0]";
  int dno = withid( id );
  if(dno >= 0) {
    sprintf(name, drawers_[dno].name ? "[g%d %.22s]" : "[g%d]",
	id, drawers_[dno].name);
  } else {
    sprintf(name, "[g%d?]", id);
  }
  return name;
}

void Fl_Gview::initfrom( Fl_Gview *v ) {
    msg = v->msg;
    eventhook = v->eventhook;
    predraw = v->predraw;
    postdraw = v->postdraw;
    ndrawers_ = v->ndrawers_;
    maxdrawers_ = v->maxdrawers_;
    drawers_ = (drawer *)malloc(maxdrawers_ * sizeof(drawer));
    memcpy(drawers_, v->drawers_, ndrawers_ * sizeof(drawer));
    owncoords_ = v->owncoords_;
    persp_ = v->persp_;
    stereo_ = v->stereo_;
slevy's avatar
slevy committed
    pixelaspect_ = v->pixelaspect_;
    stereooff_ = v->stereooff_;
    aspect_ = v->aspect_;
    stereosep_ = v->stereosep_;
    target_ = v->target_;
    movingtarget_ = v->movingtarget_;
    focallen_ = v->focallen_;
    halfyfov_ = v->halfyfov_;
    near_ = v->near_;
    far_ = v->far_;
    zspeed = v->zspeed;
    inpick_ = v->inpick_;
    pickwidth_ = v->pickwidth_, pickheight_ = v->pickheight_;
    picknents_ = v->picknents_;
    pickbuf_ = v->pickbuf_;
    pickarg_ = v->pickarg_;
slevy's avatar
slevy committed
    pickcb_ = v->pickcb_;
    notify_ = v->notify_;
    notifyarg_ = v->notifyarg_;
    pcenw_ = v->pcenw_;
    bgcolor_ = v->bgcolor_;
    nullthresh_ = v->nullthresh_;
    hasfocus_ = 0;
    use_subc_ = v->use_subc_;
    Tc2subc_ = v->Tc2subc_;
slevy's avatar
slevy committed
    pickcb_ = v->pickcb_;
    for(int i = 0; i < 4; i++)
	subclrbt_[i] = v->subclrbt_[i];
    nav( v->nav() );
slevy's avatar
slevy committed
    inertia_ = v->inertia_;
    drifting_ = 0;
    driftrate_.x = driftrate_.y = driftrate_.t = 0;
    nms_ = 0;