本文整理汇总了C++中vcg::Trackball类的典型用法代码示例。如果您正苦于以下问题:C++ Trackball类的具体用法?C++ Trackball怎么用?C++ Trackball使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Trackball类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessClick
void ProcessClick(int button, int state, int x, int y){
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
track.MouseDown(x,glutGet(GLUT_WINDOW_HEIGHT)-y,vcg::Trackball::BUTTON_LEFT);
if(button == GLUT_LEFT_BUTTON && state == GLUT_UP)
track.MouseUp(x,glutGet(GLUT_WINDOW_HEIGHT)-y,vcg::Trackball::BUTTON_LEFT);
if (button == 3 && state == GLUT_DOWN) //wheel up
track.MouseWheel(0.8);
else if (button == 4 && state == GLUT_DOWN) //wheel down
track.MouseWheel(-0.8);
}
示例2: main
int main(int argc, char *argv[]) {
// Generic loading of the mesh from disk
if(vcg::tri::io::Importer<CMesh>::Open(mesh,argv[1])!=0) {
fprintf(stderr,"Error reading file %s\n",argv[1]);
exit(0);
}
// Initialize the mesh itself
vcg::tri::UpdateBounding<CMesh>::Box(mesh); // update bounding box
//vcg::tri::UpdateNormals<CMesh>::PerVertexNormalizePerFaceNormalized(mesh); // update Normals
vcg::tri::UpdateNormals<CMesh>::PerVertexPerFace(mesh); // update Normals
// Initialize the wrapper
glWrap.m = &mesh;
glWrap.Update();
SetTrackball(trackballMode);
// we will do exaclty an animation step every 1000/FPS msecs.
track.SetFixedTimesteps(true);
initSDL("SDL_minimal_viewer");
initGL();
sdlLoop();
exit(0);
}
示例3: mode
/* Sets the trackball in a new mode:
standard mode (rotate object in front of camera)
or Navigation mode (navigate around/inside object)
*/
void SetTrackball(int mode){
// we define all possible trackModes that we could be using (static)
static vcg::PolarMode polarMode;
static vcg::SphereMode sphereMode;
static vcg::NavigatorWasdMode navigatorMode;
static vcg::InactiveMode inactiveMode;
static vcg::ScaleMode scaleMode;
static vcg::PanMode panMode;
static vcg::ZMode zMode;
// customize navigation mode...
navigatorMode.SetTopSpeedsAndAcc(1.2f,0.6f,6);
// this adds a neat human stepping effect
navigatorMode.SetStepOnWalk(0.5f,0.015f);
track.modes.clear();
track.Reset();
switch (mode) {
case 1:
// switch to navigator mode
track.modes[vcg::Trackball::BUTTON_NONE] = NULL;
track.modes[vcg::Trackball::WHEEL] =
track.modes[vcg::Trackball::BUTTON_LEFT] =
track.idle_and_keys_mode = &navigatorMode;
track.inactive_mode = NULL; // nothing to draw when inactive
track.SetPosition( observerPos );
break;
default:
// sweitch to default trackmode -- this is equivalent to a call to track->SetDefault()
track.modes[vcg::Trackball::BUTTON_NONE] = NULL;
track.modes[vcg::Trackball::BUTTON_LEFT] = &sphereMode;
track.modes[vcg::Trackball::BUTTON_LEFT | vcg::Trackball::KEY_CTRL] =
track.modes[vcg::Trackball::BUTTON_MIDDLE] = &panMode;
track.modes[vcg::Trackball::WHEEL] =
track.modes[vcg::Trackball::BUTTON_LEFT | vcg::Trackball::KEY_SHIFT] = &scaleMode;
track.modes[vcg::Trackball::BUTTON_LEFT | vcg::Trackball::KEY_ALT] = &zMode;
track.modes[vcg::Trackball::BUTTON_MIDDLE | vcg::Trackball::KEY_ALT] =
track.idle_and_keys_mode = &sphereMode;
track.inactive_mode = &inactiveMode; // draw a sphere when inactive
track.SetPosition( objectPos );
}
}
示例4: sdlLoop
/* The main event Loop */
int sdlLoop() {
bool quit=false;
bool redraw_needed = false; // true whan a scene needs a redraw
SDL_Event event;
while( !quit ) {
SDL_WaitEvent(&event);
switch( event.type ) {
case SDL_QUIT: quit = true; break;
case SDL_VIDEORESIZE : myReshapeFunc(event.resize.w,event.resize.h); break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_ESCAPE: exit(0); break;
case SDLK_F1: drawMode= (drawMode+1)%5; printf("Current Mode %i\n",drawMode); break;
case SDLK_HOME: track.Reset(); break;
case SDLK_SPACE:
trackballMode= (trackballMode+1)%2; printf("Trackball Mode %i\n",drawMode);
SetTrackball(trackballMode);
break;
default: track.ButtonDown( SDL2VCG( event.key.keysym.sym) );
}
redraw_needed = true;
break;
case SDL_KEYUP:
track.ButtonUp( SDL2VCG( event.key.keysym.sym) ); break;
case SDL_MOUSEBUTTONDOWN:
switch(event.button.button) {
case SDL_BUTTON_WHEELUP: track.MouseWheel( 1); redraw_needed = true; break;
case SDL_BUTTON_WHEELDOWN: track.MouseWheel(-1); redraw_needed = true; break;
default: track.MouseDown(event.button.x, (height - event.button.y), SDL2VCG(event.button.button) ); break;
} break;
case SDL_MOUSEBUTTONUP:
track.MouseUp(event.button.x, (height - event.button.y), SDL2VCG(event.button.button) ); break;
break;
case SDL_MOUSEMOTION:
while(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_MOUSEMOTIONMASK));
track.MouseMove(event.button.x, (height - event.button.y));
redraw_needed = true;
break;
case SDL_TIMER:
if (onTimer()) redraw_needed = true;
if (redraw_needed) sendRedraw(); // justs sends a redraw event!
redraw_needed = false;
break;
case SDL_VIDEOEXPOSE:
// any rendering is done ONLY here.
display();
drainRedrawEvents();
break;
default: break;
}
}
SDL_Quit();
return -1;
}
示例5: getDirFromTrackball
Point3f getDirFromTrackball(vcg::Trackball &tb){
glPushMatrix();
gluLookAt(1,-3,-5, 0,0,0, 0,1,0);
tb.center=Point3f(0, 0, 0);
tb.radius= 1;
tb.GetView();
tb.Apply(false);
float pos[4]={0.0f,0.0f,-1.0f,0.0f};
float d[16];
glGetFloatv(GL_MODELVIEW_MATRIX,d);
glPopMatrix();
Point3f res(-d[8],-d[9],-d[10]);
res.Normalize();
return res;
}
示例6: sdl_idle
// The Event Loop Processor
int sdl_idle() {
bool quit=false;
SDL_Event event;
while( !quit ) {
SDL_WaitEvent(&event);
switch( event.type ) {
case SDL_QUIT: quit = true; break;
case SDL_VIDEORESIZE : myReshapeFunc(event.resize.w,event.resize.h); break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym) {
case SDLK_RCTRL:
case SDLK_LCTRL: track.ButtonDown(vcg::Trackball::KEY_CTRL); break;
case SDLK_q: exit(0); break;
case SDLK_SPACE: drawMode=((drawMode+1)%6); printf("Current Mode %i\n",drawMode); break;
} break;
case SDL_KEYUP:
switch(event.key.keysym.sym) {
case SDLK_RCTRL:
case SDLK_LCTRL: track.ButtonUp(vcg::Trackball::KEY_CTRL); break;
} break;
case SDL_MOUSEBUTTONDOWN:
switch(event.button.button) {
case SDL_BUTTON_WHEELUP: track.MouseWheel( 1); break;
case SDL_BUTTON_WHEELDOWN: track.MouseWheel(-1); break;
case SDL_BUTTON_LEFT: track.MouseDown(event.button.x, (height - event.button.y), vcg::Trackball::BUTTON_LEFT); break;
case SDL_BUTTON_RIGHT: track.MouseDown(event.button.x, (height - event.button.y), vcg::Trackball::BUTTON_RIGHT);break;
} break;
case SDL_MOUSEBUTTONUP:
switch(event.button.button) {
case SDL_BUTTON_LEFT: track.MouseUp(event.button.x, (height - event.button.y), vcg::Trackball::BUTTON_LEFT); break;
case SDL_BUTTON_RIGHT: track.MouseUp(event.button.x, (height - event.button.y), vcg::Trackball::BUTTON_RIGHT);break;
} break;
case SDL_MOUSEMOTION:
while(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_MOUSEMOTIONMASK));
track.MouseMove(event.button.x, (height - event.button.y));
break;
case SDL_VIDEOEXPOSE:
default: break;
}
display();
}
SDL_Quit();
return -1;
}
示例7: drawFrame
void drawFrame() {
cgSettings.MakeShaders();
if (mol.DoingAO()) {
// do at least one more step per rendering
mol.PrepareAOstep(1);
// continue until decent
while (!mol.DecentAO()) mol.PrepareAOstep(1);
}
/*if (cgSettings.UseHalo()>0) {
// write depth in HaloTexture
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, haloFrame);
} else {
// write depth in depthbuffer
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}*/
mainCanvas.SetAsOutput();
if (cgSettings.doingAlphaSnapshot)
glClearColor( cgSettings.P_halo_col, cgSettings.P_halo_col, cgSettings.P_halo_col, 0.0f);
else
glClearColor( cgSettings.P_bg_color_R, cgSettings.P_bg_color_G, cgSettings.P_bg_color_B, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Point3f lightDir;
if ( cgSettings.P_sem_effect // fixed light dir sem effect
// || mol.sticks // quick Hack: fixed light dir when bonds
)
lightDir= Point3f(0,0,1);
else
lightDir=getDirFromTrackball(lightTrack);
setLightDir( lightDir );
// gluLookAt(0,0,-3, 0,0,0, 0,1,0); original
// gluLookAt(0,0,-3, 0,0,0, 0,1,0); ok for tra
if (mol.hasDefaultView())
gluLookAt(0,0, 40, 0,0,0, 0,1,0);
else
gluLookAt(0,0,-40, 0,0,0, 0,1,0);
if(MovingLightMode)
drawLightDir();
glColor3f(1,1,1);
if (mol.hasDefaultView()) {
float angle, axisX, axisY, axisZ;
mol.getDefaultViewRotation(&angle, &axisX, &axisY, &axisZ);
glRotatef(angle, axisX, axisY, axisZ);
}
if (1) {
//track.center=Point3f(0, 0, 0);
//track.radius= 1;
//setProjection();
if (aniStep>=0) // BH: Doesn't normally seem to be aniStep>=0
{
double extraRot=360.0*aniStep;
// set extra rotation for GIF animation:
switch (hardSettings.GIF_ANIMATION_MODE) {
default:
case 0:
glRotated(-hardSettings.GIF_ROT_SIDEVIEW_ANGLE,1,0,0);
glRotated(extraRot,0,1,0);
break;
case 1:
glRotated(-extraRot,0,0,1);
glRotated(hardSettings.GIF_INSP_ANGLE,0,1,0);
glRotated(extraRot,0,0,1);
break;
case 2:{
double substep[6];
for (int i=0; i<6; i++) {
substep[i]=(aniStep*6-i)*90.0;
if (substep[i]<0) substep[i]=0;
if (substep[i]>90.0) substep[i]=90.0;
}
glRotated(-substep[5], 1,0,0);
glRotated(-substep[4], 0,1,0);
glRotated(-substep[3], 0,1,0);
glRotated(-substep[2], 1,0,0);
glRotated(-substep[1], 0,1,0);
glRotated(-substep[0], 0,1,0);
}break;
//.........这里部分代码省略.........
示例8: display
/* Response to a redraw event: renders the scene */
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40, width/(float)height, 0.01, 10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslate( -observerPos );
track.GetView();
track.Apply(false);
glPushMatrix();
float d=mesh.bbox.Diag();
glScale(1.5f/d);
Point3f p = glWrap.m->bbox.Center();
p[1] = glWrap.m->bbox.min[1];
glTranslate(-p);
// the trimesh drawing calls
switch(drawMode)
{
case 0: glWrap.Draw<vcg::GLW::DMSmooth, vcg::GLW::CMNone,vcg::GLW::TMNone> ();break;
case 1: glWrap.Draw<vcg::GLW::DMWire, vcg::GLW::CMNone,vcg::GLW::TMNone> ();break;
case 2: glWrap.Draw<vcg::GLW::DMFlatWire, vcg::GLW::CMNone,vcg::GLW::TMNone> ();break;
case 3: glWrap.Draw<vcg::GLW::DMHidden, vcg::GLW::CMNone,vcg::GLW::TMNone> ();break;
case 4: glWrap.Draw<vcg::GLW::DMFlat, vcg::GLW::CMNone,vcg::GLW::TMNone> ();break;
default: break;
}
glPopMatrix();
RenderFloor();
track.DrawPostApply();
SDL_GL_SwapBuffers();
}
示例9: display
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40, width/(float)height, 0.1, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,5, 0,0,0, 0,1,0);
track.center=Point3f(0, 0, 0);
track.radius= 1;
track.GetView();
track.Apply();
glPushMatrix();
float d=1.0f/mesh.bbox.Diag();
glScale(d);
glTranslate(-glWrap.m->bbox.Center());
// the trimesh drawing calls
switch(drawMode)
{
case 0: glWrap.Draw<vcg::GLW::DMSmooth, vcg::GLW::CMNone,vcg::GLW::TMNone> ();break;
case 1: glWrap.Draw<vcg::GLW::DMPoints, vcg::GLW::CMNone,vcg::GLW::TMNone> ();break;
case 2: glWrap.Draw<vcg::GLW::DMWire, vcg::GLW::CMNone,vcg::GLW::TMNone> ();break;
case 3: glWrap.Draw<vcg::GLW::DMFlatWire, vcg::GLW::CMNone,vcg::GLW::TMNone> ();break;
case 4: glWrap.Draw<vcg::GLW::DMHidden, vcg::GLW::CMNone,vcg::GLW::TMNone> ();break;
case 5: glWrap.Draw<vcg::GLW::DMFlat, vcg::GLW::CMNone,vcg::GLW::TMNone> ();break;
default: break;
}
glPopMatrix();
track.DrawPostApply();
SDL_GL_SwapBuffers();
}
示例10: keyReleaseEvent
void GLWidget::keyReleaseEvent (QKeyEvent * e)
{
e->ignore ();
if (e->key () == Qt::Key_Control) track.ButtonUp (QT2VCG (Qt::NoButton, Qt::ControlModifier));
if (e->key () == Qt::Key_Shift) track.ButtonUp (QT2VCG (Qt::NoButton, Qt::ShiftModifier));
if (e->key () == Qt::Key_Alt) track.ButtonUp (QT2VCG (Qt::NoButton, Qt::AltModifier));
updateGL ();
}
示例11: onTimer
// - retunrs true if anything changed.
bool onTimer(){
int res = false;
if ( track.IsAnimating() ) {
track.Animate(1000/FPS);
res = true;
}
// insert any other animation processing here
return res;
}
示例12: keyPressEvent
void GLWidget::keyPressEvent (QKeyEvent * e)
{
e->ignore ();
if (e->key () == Qt::Key_Control) track.ButtonDown (QT2VCG (Qt::NoButton, Qt::ControlModifier));
if (e->key () == Qt::Key_Shift) track.ButtonDown (QT2VCG (Qt::NoButton, Qt::ShiftModifier));
if (e->key () == Qt::Key_Alt) track.ButtonDown (QT2VCG (Qt::NoButton, Qt::AltModifier));
TwKeyPressQt(e);
updateGL ();
}
示例13: mouseMoveEvent
void GLWidget::mouseMoveEvent (QMouseEvent * e)
{
if (e->buttons ()) {
track.MouseMove (e->x (), height () - e->y ());
updateGL ();
}
TwMouseMotion(e->x (), e->y ());
}
示例14: mousePressEvent
void GLWidget::mousePressEvent (QMouseEvent * e)
{
if(!TwMousePressQt(e))
{
e->accept ();
setFocus ();
track.MouseDown (e->x (), height () - e->y (), QT2VCG (e->button (), e->modifiers ()));
}
updateGL ();
}
示例15: drawLightDir
void drawLightDir()
{
glPushMatrix();
lightTrack.GetView();
lightTrack.Apply(false);
#if 0
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT);
glColor3f(1,1,0);
glDisable(GL_LIGHTING);
const int lineNum=3;
glBegin(GL_LINES);
for(unsigned int i=0;i<=lineNum;++i)
for(unsigned int j=0;j<=lineNum;++j) {
glVertex3f(-1.0f+i*2.0/lineNum,-1.0f+j*2.0/lineNum,-2);
glVertex3f(-1.0f+i*2.0/lineNum,-1.0f+j*2.0/lineNum, 2);
}
glEnd();
glPopAttrib();
#endif
glPopMatrix();
}