Function:ss2qcf
From S2PLOT
ss2qcf
Query camera focus point and state.
Prototype
void ss2qcf(int *set, XYZ *position, int worldcoords);
Description
Query the camera focus point, and whether it is explicitly set. The return value of set indicates whether focus is "set" or "unset" - see functions ss2scf and ss2ucf. The position of the camera focus point is returned in position. Coordinates will be returned in world coordinates if the worldcoords argument is non-zero.
See Also
ss2scf | Set the camera mid/focus point. |
ss2scf | Unset the camera mid/focus point - return to auto mid-point |
Code Example
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "s2plot.h"
void cb(double *t, int *kc)
{
static int lkc = 0; /* Local state of key press */
XYZ pos, up, vd, foc; /* Camera and focus vectors */
static float dz = +0.05; /* Amount to move camera/focus by */
int wc = 1; /* Use world coordinates */
int set; /* Flag returning focus mode */
ss2qcf(&set, &foc, wc); /* Query camera focus point */
if (set) { /* If set manually */
ss2qc(&pos, &up, &vd, wc); /* Query camera location */
if (pos.z > 5) { /* Check bounds of camera and */
dz = -0.05; /* turn motion around if needed */
} else if (pos.z < 0) {
dz = +0.05;
}
pos.z += dz; /* Update the camera location */
ss2sc(pos, up, vd, wc); /* Set the new camera position */
foc.z += dz; /* Update the focus location */
ss2scf(foc, wc); /* Set the new focus position */
}
if (lkc != *kc) { /* If <spacebar> has been pressed */
if (lkc % 2) { /* since last display, toggle */
ss2scf(foc, wc); /* state of auto motion */
} else {
ss2ucf(); /* Return to auto focus point */
}
}
lkc = *kc; /* Update key press value */
}
int main(int argc, char *argv[])
{
int i, N = 20; /* Loop variables */
float x, y, z; /* Random data */
XYZ focus; /* Point to rotate about */
int wc = 1; /* Use world coordinates */
srand48((long)time(NULL)); /* Seed random numbers */
s2opend("/?",argc, argv); /* Open the display */
s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */
s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */
s2slw(3); /* Set line width */
for (i=0;i<N;i++) {
x = drand48()*2.0 - 1.0; /* Random (x,y,z) */
y = drand48()*2.0 - 1.0;
z = drand48()*2.0 - 1.0;
s2sci(15*drand48() + 1); /* Random colour */
s2pt1(x,y,z,1); /* Plot the point */
}
focus.x = focus.y = focus.z = 0.0; /* Initial camera focus values */
ss2scf(focus, wc); /* Set the camera focus location */
s2textxy(-1,0,0,"Press <space> to toggle motion");
cs2scb(&cb); /* Install dynamic callback */
s2show(1); /* Open the s2plot window */
return 1;
}
Back to S2PLOT function list.