Function:ss2scf
From S2PLOT
(Difference between revisions)
Revision as of 01:26, 30 October 2007 S2plot admin (Talk | contribs) ← Previous diff |
Revision as of 05:19, 13 December 2007 S2plot admin (Talk | contribs) Next diff → |
||
Line 26: | Line 26: | ||
#include "s2plot.h" | #include "s2plot.h" | ||
- | void numcb(int *N) | + | void cb(double *t, int *kc) |
{ | { | ||
- | if (*N != 1) return; | + | static int lkc = 0; /* Local state of key press */ |
- | ss2ucf(); /* Go back to rotating around centre */ | + | 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 main(int argc, char *argv[]) | ||
{ | { | ||
- | int i, N = 20; /* Loop variables */ | + | int i, N = 20; /* Loop variables */ |
- | float x, y, z; /* Random data */ | + | float x, y, z; /* Random data */ |
- | XYZ focus; /* Point to rotate about */ | + | XYZ focus; /* Point to rotate about */ |
- | int wc = 1; /* Use world coordinates */ | + | int wc = 1; /* Use world coordinates */ |
- | srand48((long)time(NULL)); /* Seed random numbers */ | + | srand48((long)time(NULL)); /* Seed random numbers */ |
- | s2opend("/?",argc, argv); /* Open the display */ | + | s2opend("/?",argc, argv); /* Open the display */ |
- | s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */ | + | s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */ |
- | s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */ | + | s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */ |
- | s2slw(3); /* Set line width */ | + | s2slw(3); /* Set line width */ |
for (i=0;i<N;i++) { | for (i=0;i<N;i++) { | ||
- | x = drand48()*2.0 - 1.0; /* Random (x,y,z) */ | + | x = drand48()*2.0 - 1.0; /* Random (x,y,z) */ |
y = drand48()*2.0 - 1.0; | y = drand48()*2.0 - 1.0; | ||
z = drand48()*2.0 - 1.0; | z = drand48()*2.0 - 1.0; | ||
- | s2sci(15*drand48() + 1); /* Random colour */ | + | s2sci(15*drand48() + 1); /* Random colour */ |
- | s2pt1(x,y,z,1); /* Plot the point */ | + | s2pt1(x,y,z,1); /* Plot the point */ |
} | } | ||
+ | focus.x = focus.y = focus.z = 0.0; /* Initial camera focus values */ | ||
- | focus.x = drand48()*2.0 - 1.0; /* Random rotation point */ | + | ss2scf(focus, wc); /* Set the camera focus location */ |
- | focus.y = drand48()*2.0 - 1.0; | + | s2textxy(-1,0,0,"Press <space> to toggle motion"); |
- | focus.z = drand48()*2.0 - 1.0; | + | |
- | ss2scf(focus, wc); /* Set the rotation point */ | + | |
- | s2sch(0.7); /* Set text height */ | + | cs2scb(&cb); /* Install dynamic callback */ |
- | s2textxy(-1,0,0,"Rotate camera - then press 1 followed by +"); | + | |
- | cs2sncb(&numcb); /* Install number callback */ | + | s2show(1); /* Open the s2plot window */ |
- | s2show(1); /* Open the s2plot window */ | ||
- | |||
return 1; | return 1; | ||
} | } | ||
+ | |||
</pre></code> | </pre></code> | ||
[[S2PLOT:Function List | Back]] to S2PLOT function list. | [[S2PLOT:Function List | Back]] to S2PLOT function list. | ||
__NOTOC__ | __NOTOC__ | ||
__NOEDITSECTION__ | __NOEDITSECTION__ |
Revision as of 05:19, 13 December 2007
ss2scf
Set the camera mid/focus point.
Prototype
void ss2scf(XYZ position, int worldcoords);
Description
Set the camera mid/focus point. If this is set, then rotation will be about the provided point (position). Use ss2ucf to revert to "auto" mid point. If worldcoords > 0 then caller has given world coordinates, otherwise they are viewport-relative coordinates.
See Also
ss2ucf | Unset the camera mid/focus point - revert 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.