Function:ss2scf

From S2PLOT

(Difference between revisions)
Jump to: navigation, search
Revision as of 05:19, 13 December 2007
S2plot admin (Talk | contribs)

← Previous diff
Revision as of 05:20, 13 December 2007
S2plot admin (Talk | contribs)

Next diff →
Line 15: Line 15:
== See Also == == See Also ==
<table> <table>
 +<tr><td>[[Function:ss2qcf | ss2qcf ]]</td><td>Query camera focus and state. </td></tr>
<tr><td>[[Function:ss2ucf | ss2ucf ]]</td><td>Unset the camera mid/focus point - revert to auto mid-point. </td></tr> <tr><td>[[Function:ss2ucf | ss2ucf ]]</td><td>Unset the camera mid/focus point - revert to auto mid-point. </td></tr>
</table> </table>

Revision as of 05:20, 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

ss2qcf Query camera focus and state.
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.


Personal tools