HowToC:FollowAnObject

From S2PLOT

Revision as of 23:35, 19 August 2008; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

How to follow an object with the camera

Using handles, you can easily detect when an object has been right-clicked. With two pretty simple bits of code, you can then make the camera keep focussed on that object.

1. use a handle callback to register the most recently selected handle:

// define an S2PLOT OpenGL callback function */
void openglcb(void) {
  // store the state
  glPushAttrib(GL_ALL_ATTRIB_BITS);

  // turn on blending
  glEnable(GL_BLEND);
  glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

  // draw a transparent orange quad
  glBegin(GL_QUADS);
  glColor4f(0.8, 0.3, 0.0, 0.5);
  glVertex3f(-3., -3., -3.);
  glVertex3f(-3.,  3., -3.);
  glVertex3f( 3.,  3., -3.);
  glVertex3f( 3., -3., -3.);
  glEnd();

  // restore the state
  glPopAttrib();
}
Personal tools