HowToC:GetStarted

From S2PLOT

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

← Previous diff
Revision as of 05:01, 30 October 2007
S2plot admin (Talk | contribs)

Next diff →
Line 44: Line 44:
<code><pre> <code><pre>
s2box("BCDE",0,0,"BCDE",0,0,"BCDE",0,0); /* Draw a coordinate box */ s2box("BCDE",0,0,"BCDE",0,0,"BCDE",0,0); /* Draw a coordinate box */
-</code></pre>+</pre></code>
Save, compile with <tt>cbuild.csh</tt> and run again. This time, you should see a white box representing the coordinate system. Save, compile with <tt>cbuild.csh</tt> and run again. This time, you should see a white box representing the coordinate system.
Line 53: Line 53:
* Press +/- to move the camera towards/away from the centre of the box. * Press +/- to move the camera towards/away from the centre of the box.
* Press the <tt>a</tt> key to toggle autospin * Press the <tt>a</tt> key to toggle autospin
-For full details on interaction, see [[+For full details on interaction, see [[S2Plot:Controls | here]].

Revision as of 05:01, 30 October 2007

Getting started

An S2PLOT program typically has four separate parts:

  1. Commands to open S2PLOT display and set-up the environment
  2. Commands to prepare static geometry, which is generated once and then drawn on all future screen refreshes
  3. Commands to prepare dynamic geometry (ie. callbacks), which are update on every screen refresh
  4. A command to hand over control to the OpenGL GLUT event loop, which controls interactivity such as mouse and keyboard controls

To begin with, we will just consider steps 1 and 4.

Copy and paste the following code, and save the file as s2example.c

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

int main(int argc, char *argv[])
{
   float xmin = -1, xmax = +1;          /* X data range */
   float ymin = -1, ymax = +1;          /* Y data range */
   float zmin = -1, zmax = +1;          /* Z data range */

   s2opend("/?",argc,argv);             /* Which S2PLOT device to open? */
   s2swin(xmin, xmax, ymin, ymax, zmin, zmax);  /* Set the display coordinates */

   s2show(1);                           /* Hand over to the display */

   return 1;
}

Compile using: cbuild.csh s2example<tt> and then run by typing <tt>s2example at the command prompt.

You will be prompted for a device type - for the moment, just press return to choose the default for your system.

A black screen should appear - not very exciting, but you have successfully started up the S2PLOT display and handed control to GLUT.

Next, we should start adding some static geometry.

Add the following line below the s2swin command:

s2box("BCDE",0,0,"BCDE",0,0,"BCDE",0,0);     /* Draw a coordinate box */

Save, compile with cbuild.csh and run again. This time, you should see a white box representing the coordinate system.

You can now begin to test the interactive aspects of S2PLOT:

  • Press and hold the left mouse button and move the mouse to control rotation.
  • Press and hole the middle or right mouse buttons to see what affect they have.
  • Press +/- to move the camera towards/away from the centre of the box.
  • Press the a key to toggle autospin

For full details on interaction, see here.

Personal tools