HowToC:FollowAnObject
From S2PLOT
(Difference between revisions)
Revision as of 23:35, 19 August 2008 Dbarnes (Talk | contribs) ← Previous diff |
Revision as of 23:35, 19 August 2008 Dbarnes (Talk | contribs) (→How to follow an object with the camera) Next diff → |
||
Line 5: | Line 5: | ||
1. use a handle callback to register the most recently selected handle: | 1. use a handle callback to register the most recently selected handle: | ||
<code><pre> | <code><pre> | ||
- | // define an S2PLOT OpenGL callback function */ | + | void pickcb(int *id) { |
- | 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(); | + | |
} | } | ||
</pre></code> | </pre></code> |
Revision as of 23:35, 19 August 2008
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:
void pickcb(int *id) {
}