Function:ds2bb

From S2PLOT

(Difference between revisions)
Jump to: navigation, search

Revision as of 23:11, 28 October 2007

ds2bb

Draw a (dynamic) billboard: a textured facet that always faces the camera

Prototype

void ds2bb(float x, float y, float z, float str_x, float str_y, float str_z, float isize, 
float r, float g, float b, unsigned int itextid, float alpha, char trans);

Description

Draw a (dynamic) billboard. This is a textured facet (4 vertex) that sits at a given location and always faces the camera. By using small, rotationally symmetric texture maps, the appearance of soft, 3d objects can be produced at low frame-rate cost. This function should only be called from a dynamic callback: billboards cannot be cached static geometry as they typically change with every refresh.

The billboard texture is at coordinates (x,y,z), and can be stretched towards the coordinates (str_x, str_y, str_z) (for no stretching, set these coordinates to 0.0). The overall scale of the billboard texture is controlled by isize.

The RGB texture colour is specified by parameters (r, g, b), and the texture to use is identified by itextid.

Transparency is controlled by the alpha channel, with value in the range [0,1] and trans:

  • trans = 'o' opaque;
  • trans = 't' transparent; and
  • trans = 's' transparency + absorption.


See Also

ds2vbb Draw a (dynamic) billboard: a textured facet that always faces the camera - vector input
ds2tb Draw text that always faces the camera
ds2vtb Draw text that always faces the camera - vector input
ss2lt Load a texture for future (generally repeated) use.
ss2ct Create a texture with specified width and height


Code Example

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

unsigned int tid;

void cb(double *t, int *kc)
{
   float x = 0.0, y = 0.3, z = 0.4;			/* Location */
   float isize = 0.02;					/* Texture scale */
   float str_x = 0.0, str_y = 0.0, str_z = 0.0;		/* No stretch */
   float r = 1.0, g = 1.0, b = 0.0;			/* Yellow */
   float alpha = 0.9; 					/* Alpha channel */
   char trans = 's';					/* Transparency */
   
   ds2bb(x,y,z, str_x,str_y,str_z, isize, r,g,b, 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 */

   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