HowToC:GetStarted

From S2PLOT

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

← Previous diff
Revision as of 05:05, 30 October 2007
S2plot admin (Talk | contribs)
(Labelling the coordinates)
Next diff →
Line 59: Line 59:
===Labelling the coordinates=== ===Labelling the coordinates===
 +
 +Add the following code under the <tt>s2box</tt> command in s2example.c
 +
 +<code><pre>
 +s2lab("X-axis","Y-axis","Z-axis","Adding some labels");
 +</pre></code>
 +
 +This will create labels for the x, y and z axes, plus an overall label for the plot. If you do not want a particular axis label to be visible, you can use <tt>""</tt>.
 +
 +Save, compile and run.

Revision as of 05:05, 30 October 2007

Contents

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.

First example

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.

Drawing a bounding box

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.

Testing S2PLOT interaction

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.

Labelling the coordinates

Add the following code under the s2box command in s2example.c

s2lab("X-axis","Y-axis","Z-axis","Adding some labels");

This will create labels for the x, y and z axes, plus an overall label for the plot. If you do not want a particular axis label to be visible, you can use "".

Save, compile and run.

Personal tools