Function:ns2vplanetx

From S2PLOT

(Difference between revisions)
Jump to: navigation, search
Revision as of 01:50, 6 January 2009
S2plot admin (Talk | contribs)

← Previous diff
Current revision
S2plot admin (Talk | contribs)

Line 1: Line 1:
==ns2vplanetx== ==ns2vplanetx==
 +Draw a planet with texture id.
==Prototype== ==Prototype==
<code><pre> <code><pre>
 +void ns2vplanetx(XYZ iP, float ir, COLOUR icol, unsigned int itextureid,
 + float texture_phase, XYZ axis, float rotation);
</pre></code> </pre></code>
==Description== ==Description==
 +Draw a planet, which is a textured sphere whose texture can be "slid" around the planet, and the planet then rotated about an arbitrary axis. Texture phase is in the range [0..1], while rotation angle is in degrees.
 +
 +==See Also==
 +<table>
 +<tr><td>[[Function:ns2vplanett | ns2vplanett]]</td><td>Draw a planet - vector input.</td></tr>
 +<tr><td>[[Function:ns2vsphere | ns2vsphere ]]</td><td>Draw a sphere, with a given centre, radius and colour - vector input.</td></tr>
 +<tr><td>[[Function:ns2spheret | ns2spheret]]</td><td>Draw a textured sphere, with given centre, radius, colour and texture filename </td></tr>
 +<tr><td>[[Function:ns2vspheret | ns2vspheret]]</td><td>Draw a textured sphere, with given centre, radius, colour and texture filename - vector input.</td></tr>
 +<tr><td>[[Function:ns2spherex| ns2spherex]]</td><td>Draw a textured sphere, with given centre, radius, colour and texture ID</td></tr>
 +<tr><td>[[Function:ns2vspherex | ns2vspherex]]</td><td>Draw a textured sphere, with given centre, radius, colour and texture ID - vector input.</td></tr>
 +<tr><td>[[Function:ns2sphere| ns2sphere]]</td><td>Draw a sphere.</td></tr>
 +</table>
==Code Example== ==Code Example==
<code><pre> <code><pre>
-</pre></code>+#include <stdio.h>
 +#include <stdlib.h>
 +#include "s2plot.h"
-[[S2PLOT:Function List | Back]] to S2PLOT function list.+void cb(double *t, int *kc)
 +{
 + float radius = 0.5; /* Radius of planet */
 + XYZ xyz = { -1.0, 0.0, 0.0 }; /* Location of planet */
 + COLOUR colour = { 1.0, 1.0, 0.0 }; /* Yellow */
 + static int tid = -1; /* Texture id */
 + if (tid < 0) { /* First time through? */
 + tid = ss2lt("firetile2_pow2_rgb.tga"); /* Load texture for re-use */
 + }
 + static float phase = 30.0; /* Set the texture phase */
 + XYZ axis = { 0.0, 0.0, 1.0 }; /* Set the rotation axis */
 + static float rotation = 0.0; /* Set the rotation value */
-__NOTOC__+ ns2vplanetx(xyz, radius, colour, tid, phase, axis, rotation);
-__NOEDITSECTION__+ /* Draw the "planet" */
 + xyz.x = 0.0; /* Shift centre */
 + axis.x = 0.0; axis.y = 1.0; axis.z = 0.0; /* New rotation axis */
 + ns2vplanetx(xyz, radius, colour, tid, phase, axis, rotation);
 + /* Draw the "planet" */
-Back to [[Function:Template | template]] page.+ xyz.x = 1.0; /* Shift centre */
 + axis.x = 1.0; axis.y = 0.0; axis.z = 0.0; /* New rotation axis */
 + ns2vplanetx(xyz, radius, colour, tid, phase, axis, rotation);
 + /* Draw the "planet" */
 + 
 + rotation += 1.0; /* Update rotation in degrees */
 + if (rotation > 360.0) rotation = 0.0; /* Full circle? Reset */
 + 
 + 
 +}
 + 
 +int main(int argc, char *argv[])
 +{
 + 
 + s2opend("/?",argc, argv); /* Open the display */
 + s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */
 + 
 + ss2ssr(32); /* Set the sphere resolution */
 + cs2scb(cb); /* Install dynamic callback */
 + 
 + s2show(1); /* Open the s2plot window */
 + 
 + return 1;
 +}
 +</pre></code>
 + 
 +[[S2PLOT:Function List | Back]] to S2PLOT function list.
 + 
 +__NOTOC__
 +__NOEDITSECTION__

Current revision

ns2vplanetx

Draw a planet with texture id.

Prototype

void ns2vplanetx(XYZ iP, float ir, COLOUR icol, unsigned int itextureid, 
                 float texture_phase, XYZ axis, float rotation);

Description

Draw a planet, which is a textured sphere whose texture can be "slid" around the planet, and the planet then rotated about an arbitrary axis. Texture phase is in the range [0..1], while rotation angle is in degrees.

See Also

ns2vplanettDraw a planet - vector input.
ns2vsphere Draw a sphere, with a given centre, radius and colour - vector input.
ns2spheretDraw a textured sphere, with given centre, radius, colour and texture filename
ns2vspheretDraw a textured sphere, with given centre, radius, colour and texture filename - vector input.
ns2spherexDraw a textured sphere, with given centre, radius, colour and texture ID
ns2vspherexDraw a textured sphere, with given centre, radius, colour and texture ID - vector input.
ns2sphereDraw a sphere.

Code Example

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

void cb(double *t, int *kc)
{
   float radius = 0.5;                          /* Radius of planet */
   XYZ xyz = { -1.0, 0.0, 0.0 };                /* Location of planet */

   COLOUR colour = { 1.0, 1.0, 0.0 };           /* Yellow */
   static int tid = -1;                         /* Texture id */
   if (tid < 0) {                               /* First time through? */
      tid = ss2lt("firetile2_pow2_rgb.tga");    /* Load texture for re-use */
   }

   static float phase = 30.0;                   /* Set the texture phase */
   XYZ axis = { 0.0, 0.0, 1.0 };                /* Set the rotation axis */
   static float rotation = 0.0;                 /* Set the rotation value */

   ns2vplanetx(xyz, radius, colour, tid, phase, axis, rotation);
                                                /* Draw the "planet" */

   xyz.x = 0.0;                                 /* Shift centre */
   axis.x = 0.0; axis.y = 1.0; axis.z = 0.0;    /* New rotation axis */
   ns2vplanetx(xyz, radius, colour, tid, phase, axis, rotation);
                                                /* Draw the "planet" */

   xyz.x = 1.0;                                 /* Shift centre */
   axis.x = 1.0; axis.y = 0.0; axis.z = 0.0;    /* New rotation axis */
   ns2vplanetx(xyz, radius, colour, tid, phase, axis, rotation);
                                                /* Draw the "planet" */

   rotation += 1.0;                             /* Update rotation in degrees */
   if (rotation > 360.0) rotation = 0.0;        /* Full circle? Reset */


}

int main(int argc, char *argv[])
{

   s2opend("/?",argc, argv);                    /* Open the display */
   s2swin(-1.,1., -1.,1., -1.,1.);              /* Set the window coordinates */

   ss2ssr(32);                                  /* Set the sphere resolution */
   cs2scb(cb);                                  /* Install dynamic callback */

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

   return 1;
}

Back to S2PLOT function list.


Personal tools