Function:cs2scb
From S2PLOT
(Difference between revisions)
Revision as of 23:32, 27 November 2007 S2plot admin (Talk | contribs) ← Previous diff |
Current revision S2plot admin (Talk | contribs) |
||
Line 28: | Line 28: | ||
<tr><td>[[Function:cs2socb | cs2socb ]]</td><td>Register function that will draw direct OpenGL graphics when called. </td></tr> | <tr><td>[[Function:cs2socb | cs2socb ]]</td><td>Register function that will draw direct OpenGL graphics when called. </td></tr> | ||
<tr><td>[[Function:cs2shcb | cs2shcb ]]</td><td>Set the handle callback function for when a handle is (de)selected </td></tr> | <tr><td>[[Function:cs2shcb | cs2shcb ]]</td><td>Set the handle callback function for when a handle is (de)selected </td></tr> | ||
- | <tr><td>[[Function:cs2scbx | cs2cbx]]</td><td></td></tr> | + | <tr><td>[[Function:cs2scbx | cs2cbx]]</td><td>Set dynamic callback with initialisation data.</td></tr> |
</table> | </table> | ||
Current revision
cs2scb
Set the callback function; can be null to cancel callback.
Prototype
void cs2scb(void *cbfn);
Description
Set the dynamic geometry callback function; use NULL argument to cancel callback. The callback function must be of the form:
void cbfn(double *time, int *keycount)
where time is the current system time and keycount records the number of times that the space bar has been pressed.
The callback function can be toggled on/off by pressing the z key.
See Also
cs2ecb | Animation state - Enable callback. |
cs2dcb | Animation state - Disable callback. |
cs2tcb | Animation state - Toggle callback. |
cs2sncb | Set the function to call when number-keys pressed. |
cs2socb | Register function that will draw direct OpenGL graphics when called. |
cs2shcb | Set the handle callback function for when a handle is (de)selected |
cs2cbx | Set dynamic callback with initialisation data. |
Code Example
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "s2plot.h"
/* Spacebar: toggle between two different colours */
/* Press 1: to turn off callback */
/* Press 2: to turn on callback */
/* Press 3: to select a different colour set to toggle between */
/* Press 4: to select a different colour set to toggle between */
/* Press 5: toggle callback - same as pressing 1 then 2 */
int colour = 1; /* Global variable: colour index for callback */
void ncb(int *N)
/* Callback for pressing number keys */
{
if (*N > 5) return; /* Do nothing! */
switch (*N) {
case 1 : cs2dcb(); /* Turn off callback */
break;
case 2 : cs2ecb(); /* Turn on callback */
break;
case 3 : colour = 3; /* Change the colour that alternates */
break;
case 4 : colour = 5; /* Change the colour that alternates */
break;
case 5 : cs2tcb(); /* Toggle callback on/off */
break;
}
}
void cb(double *t, int *kc)
/* A dynamic callback - jitter particle positions each time through */
{
static int flag = 0; /* Flag on whether first time through */
static float x[20], y[20], z[20]; /* Dynamic geometry */
int i, N = 20;
if (flag == 0) { /* First time only */
for (i=0;i<N;i++) {
x[i] = drand48()*2.0-1.0; /* Random positions */
y[i] = drand48()*2.0-1.0;
z[i] = drand48()*2.0-1.0;
}
flag = 1; /* Set the flag - don't need this loop again */
}
for (i=0;i<N;i++) {
x[i] += (drand48()*0.1-0.05); /* Apply a jitter each time in callback */
y[i] += (drand48()*0.1-0.05);
z[i] += (drand48()*0.1-0.05);
}
s2sci((*kc % 2) + colour);
/* Set colour on number of times space is pressed - uses global */
s2slw(3); /* Set the line width */
s2pt(N, x, z, y, 1); /* Draw the points */
}
int main(int argc, char *argv[])
{
int i, N = 20;
float x[20], y[20], z[20]; /* Static geometry */
srand48((long)time(NULL)); /* Seed random numbers */
for (i=0;i<N;i++) {
x[i] = drand48()*4.0-2.0; /* Random positions */
y[i] = drand48()*4.0-2.0;
z[i] = drand48()*4.0-2.0;
}
s2opend("/?",argc, argv); /* Open the display */
s2swin(-2.,2., -2.,2., -2.,2.); /* Set the window coordinates */
s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */
cs2scb(&cb); /* Install the callback */
cs2sncb(&ncb); /* Install number callback */
s2slw(4); /* Set line width */
s2sci(S2_PG_YELLOW);
s2pt(N,x,y,z,1); /* Draw static data */
s2slw(1);
s2show(1); /* Open the s2plot window */
return 1;
}
Back to S2PLOT function list.