Function:ns2vplanetx
From S2PLOT
(Difference between revisions)
Revision as of 03:21, 27 January 2009 S2plot admin (Talk | contribs) ← Previous diff |
Current revision S2plot admin (Talk | contribs) |
||
Line 26: | Line 26: | ||
<code><pre> | <code><pre> | ||
+ | #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; | ||
+ | } | ||
</pre></code> | </pre></code> | ||
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
ns2vplanett | Draw a planet - vector input. |
ns2vsphere | Draw a sphere, with a given centre, radius and colour - vector input. |
ns2spheret | Draw a textured sphere, with given centre, radius, colour and texture filename |
ns2vspheret | Draw a textured sphere, with given centre, radius, colour and texture filename - vector input. |
ns2spherex | Draw a textured sphere, with given centre, radius, colour and texture ID |
ns2vspherex | Draw a textured sphere, with given centre, radius, colour and texture ID - vector input. |
ns2sphere | Draw 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.