Function:ds2vbb
From S2PLOT
←Older revision | Newer revision→
ds2vbb
Draw a (dynamic) billboard: a textured facet that always faces the camera - vector input
Prototype
void ds2vbb(XYZ iP, XYZ iStretch, float isize, COLOUR iC, unsigned int itextid, float alpha, char trans);
Description
Draw a (dynamic) billboard using vector inputs. 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 iP, and can be stretched towards the coordinates given by iStretch (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 iC, 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
ds2bb | Draw a (dynamic) billboard: a textured facet that always faces the camera |
ds2vbbr | Draw a (dynamic) billboard texture with specified rotation. |
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 |
struct_COLOUR | Data structure for (r,g,b) colour indices. |
struct_XYZ | Data structure for (x,y,z) coordinates. |
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 */
ds2vbb(xyz, str, isize, 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.