Function:ds2tb
From S2PLOT
(Difference between revisions)
Revision as of 01:06, 30 October 2007
ds2tb
Draw text that always faces the camera
Prototype
void ds2tb(float x, float y, float z, float x_off, float y_off, char *text, int scaletext);
Description
Draw text at position (x,y,z) that always faces the camera. Use this function only from within a dynamic callback. offset is in character units along Right and Up vectors - use this to displace labels in screen coordinates. If scaletext is true (non-zero), then text further from the camera will be made larger so that labels are equally legible for all distances.
NOTE: this function uses the S2PLOT attributes for character height (size) and colour.
See Also
ds2bb | Draw a (dynamic) billboard: a textured facet that always faces the camera |
ds2vbb | Draw a (dynamic) billboard: a textured facet that always faces the camera - vector input |
ds2vtb | Draw text that always faces the camera - vector input |
s2sci | Set the pen colour by index. |
s2sch | Set the character height in "arbitrary" units. |
Code Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "s2plot.h"
float *x, *y, *z; /* Global arrays - text positions */
int N; /* Number of text labels */
void cb(double *t, int *kc)
/* A dynamic callback */
{
int i; /* Loop variable */
float xoff = 0.01; /* Small offsets - must be non-zero */
float yoff = 0.01; /* for text to appear */
s2sch(0.2); /* Set the text height */
for (i=0;i<N;i++) { /* Draw the billboard labels */
ds2tb(x[i], y[i], z[i], xoff, yoff, "S2PLOT", 1);
}
}
int main(int argc, char *argv[])
{
int i; /* Loop variable */
srand48((long)time(NULL)); /* Seed random numbers */
s2opend("/S2MONO",argc,argv); /* Open the display */
s2swin(-1.5,1.5, -1.5,1.5, -1.5,1.5);
s2box("BCDE",0,0,"BCDE",0,0,"BCDE",0,0); /* Draw coord box */
N = 20; /* Number of labels to draw */
x = (float *)calloc(N, sizeof(float));
y = (float *)calloc(N, sizeof(float));
z = (float *)calloc(N, sizeof(float));
for (i=0;i<N;i++) { /* Create N random (x,y,z) values */
x[i] = drand48()*2.0 - 1.0;
y[i] = drand48()*2.0 - 1.0;
z[i] = drand48()*2.0 - 1.0;
}
s2scb(cb); /* Install a dynamic callback */
s2show(1); /* Open the s2plot window */
return 1;
}
Back to S2PLOT function list.