Function:ss2sc

From S2PLOT

(Difference between revisions)
Jump to: navigation, search
Revision as of 01:24, 30 October 2007
S2plot admin (Talk | contribs)

← Previous diff
Revision as of 06:25, 6 March 2008
S2plot admin (Talk | contribs)

Next diff →
Line 24: Line 24:
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
 +#include <time.h>
#include "s2plot.h" #include "s2plot.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
- XYZ pos; /* Camera position */+ XYZ pos; /* Camera position */
- XYZ up; /* Camera up vector */+ XYZ up; /* Camera up vector */
- XYZ view; /* Camera view vector */+ XYZ view; /* Camera view vector */
- int wc = 1; /* Use world coordinates */+ int wc = 1; /* Use world coordinates */
- int i, N = 20; /* Loop variables */+ int i, N = 20; /* Loop variables */
- float x, y, z; /* Temporary data */+ float x, y, z; /* Temporary data */
- +
- 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 */+ 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++) { for (i=0;i<N;i++) {
- x = drand48()*2.0 - 1.0; /* Random positions */+ x = drand48()*2.0 - 1.0; /* Random positions */
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); s2pt1(x, y, z, 1);
} }
Line 52: Line 55:
view.x = 0.0; view.y = 0.0; view.z = -1.0; view.x = 0.0; view.y = 0.0; view.z = -1.0;
- ss2sc(pos, up, view, wc); /* Set new camera position */+ ss2sc(pos, up, view, wc); /* Set new camera position */
 + 
 + 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 06:25, 6 March 2008

ss2sc

Set the camera position, up vector and view direction.

Prototype

void ss2sc(XYZ position, XYZ up, XYZ vdir, int worldcoords);

Description

Set the camera position, up vector and view direction (vdir). If worldcoords > 0 then caller has given world coordinates, otherwise they are viewport-relative coordinates.

See Also

ss2qc Query the camera position, up vector and view direction.
ss2tc Enable/disable (1,0) camera translation.


Code Example

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "s2plot.h"

int main(int argc, char *argv[])
{
   XYZ pos;                                     /* Camera position */
   XYZ up;                                      /* Camera up vector */
   XYZ view;                                    /* Camera view vector */
   int wc = 1;                                  /* Use world coordinates */
   int i, N = 20;                               /* Loop variables */
   float x, y, z;                               /* Temporary data */

   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 positions */
      y = drand48()*2.0 - 1.0;
      z = drand48()*2.0 - 1.0;
      s2sci(15*drand48()+1);                    /* Random colour */
      s2pt1(x, y, z, 1);
   }

   pos.x  = 0.0; pos.y  = 0.0; pos.z  = 10.0;
   up.x   = 0.5; up.y   = 0.5; up.z   = 0.0;
   view.x = 0.0; view.y = 0.0; view.z = -1.0;

   ss2sc(pos, up, view, wc);            /* Set new camera position */

   s2show(1);                                   /* Open the s2plot window */

   return 1;
}

Back to S2PLOT function list.


Personal tools