Function:ds2vbbr

From S2PLOT

(Difference between revisions)
Jump to: navigation, search
Revision as of 03:35, 10 March 2008
S2plot admin (Talk | contribs)

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

Line 20: Line 20:
==Code Example== ==Code Example==
<code><pre> <code><pre>
 +#include <stdio.h>
 +#include <stdlib.h>
 +#include <time.h>
 +#include "s2plot.h"
 +
 +unsigned int tid;
 +
 +void cb(double *t, int *kc)
 +{
 + XYZ xyz = {0.0, 0.3, 0.4}; /* Location */
 + float isize = 0.02; /* Texture scale */
 + XYZ str = { 0.0, 0.0, 0.0}; /* No stretch */
 + COLOUR col = { 1.0, 1.0, 0.0 }; /* Yellow */
 + float alpha = 0.9; /* Alpha channel */
 + char trans = 's'; /* Transparency */
 + float pangle = 45.0; /* Rotation angle - degrees */
 +
 + ds2vbbr(xyz, str, isize, pangle, col, tid, alpha, trans); /* Draw the billboard */
 +}
 +
 +int main(int argc, char *argv[])
 +{
 + int width = 16, height = 16; /* Dimensions of texture */
 + int i, j; /* Loop variables */
 + int idx; /* Index into texture array */
 + char *tex; /* Array of texture values */
 +
 + srand48((long)time(NULL)); /* Seed random numbers */
 + s2opend("/?",argc,argv); /* Open the display */
 + s2svp(-1.0,1.0, -1.0,1.0, -1.0,1.0); /* Set the viewport coords */
 + s2swin(-1.0,1.0, -1.0,1.0, -1.0,1.0); /* Set the window coordinates */
 + s2box("BCDE",0,0,"BCDE",0,0,"BCDE",0,0); /* Draw a bounding box */
 +
 + tid = ss2ct(width, height); /* Create a new texture */
 + tex = ss2gt(tid, &width, &height); /* Get the texture */
 +
 + for (j=0;j<height;j++) {
 + for (i=0;i<width;i++) {
 + idx = (j*width + i) * 4; /* Stored as (r,g,b,alpha) */
 + tex[idx ] = 127*drand48()+128; /* Randomish red */
 + tex[idx+1] = 0; /* Green */
 + tex[idx+2] = 0; /* Blue */
 + /* Do nothing to alpha */
 + }
 + }
 + ss2pt(tid); /* Push texture for usage */
 +
 + cs2scb(&cb); /* Install a callback */
 +
 + s2show(1); /* Open the s2plot window */
 +
 + 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__

Current revision

ds2vbbr

Draw a (dynamic) billboard texture with specified rotation.

Prototype

void ds2vbbr(XYZ iP, XYZ iStretch, float isize, float ipangle, COLOUR iC, 
unsigned int itexid, float alpha, char trans);

Description

Draw a (dynamic) "billboard", with rotation ipangle (in degrees) of the texture about the view direction

See Also

ds2bbDraw a (dynamic) billboard: a textured facet that always faces the camera.
ds2vbbDraw a (dynamic) billboard: a textured facet that always faces the camera.

Code Example

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

unsigned int tid;

void cb(double *t, int *kc)
{
   XYZ xyz = {0.0, 0.3, 0.4};                           /* Location */
   float isize = 0.02;                                  /* Texture scale */
   XYZ str = { 0.0, 0.0, 0.0};                          /* No stretch */
   COLOUR col = { 1.0, 1.0, 0.0 };                      /* Yellow */
   float alpha = 0.9;                                   /* Alpha channel */
   char trans = 's';                                    /* Transparency */
   float pangle = 45.0;                                 /* Rotation angle - degrees */

   ds2vbbr(xyz, str, isize, pangle, col, tid, alpha, trans);    /* Draw the billboard */
}

int main(int argc, char *argv[])
{
   int width = 16, height = 16;         /* Dimensions of texture */
   int i, j;                            /* Loop variables */
   int idx;                             /* Index into texture array */
   char *tex;                           /* Array of texture values */

   srand48((long)time(NULL));                   /* Seed random numbers */
   s2opend("/?",argc,argv);                     /* Open the display */
   s2svp(-1.0,1.0, -1.0,1.0, -1.0,1.0);         /* Set the viewport coords */
   s2swin(-1.0,1.0, -1.0,1.0, -1.0,1.0);        /* Set the window coordinates */
   s2box("BCDE",0,0,"BCDE",0,0,"BCDE",0,0);     /* Draw a bounding box */

   tid = ss2ct(width, height);          /* Create a new texture */
   tex = ss2gt(tid, &width, &height);   /* Get the texture */

   for (j=0;j<height;j++) {
      for (i=0;i<width;i++) {
         idx = (j*width + i) * 4;               /* Stored as (r,g,b,alpha) */
         tex[idx  ] = 127*drand48()+128;        /* Randomish red */
         tex[idx+1] = 0;                        /* Green */
         tex[idx+2] = 0;                        /* Blue */
                                                /* Do nothing to alpha */
      }
   }
   ss2pt(tid);                          /* Push texture for usage */

   cs2scb(&cb);                         /* Install a callback */

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

   return 1;
}

Back to S2PLOT function list.


Personal tools