Function:ds2ahx
From S2PLOT
ds2ahx
Add a handle with a specified texture
Prototype
void ds2ahx(XYZ iP, float size, int itex, int ihitex, COLOUR icol, COLOUR ihilite,
int iid, int iselected);
Description
Add a handle to object at location iP. The handle size is set by size, with colour icol when the handle is not selected and ihilite when it is selected. iid is the id of the current handle and iselected gives its selection status. The texture maps to use for the unselected (itex) and selected (ihitex) modes must be specified.
To use handles, press Shift-s (show handles) and Shift-c (show cross-hairs). Note that selecting handles in a stereoscopic environment requires you to click on the point between the left and right eye views.
See Also
ds2ah | Add a handle to allow interactive picking of objects |
cs2shcb | Set the handle callback function for when a handle is (de)selected |
cs2th | Toggle the state of a named (dynamic) handle |
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"
#define N 100 /* Number of points */
XYZ xyz[N]; /* Global variable: positions */
COLOUR col[N]; /* Colour of the point */
int sel[N]; /* Global varibale: selected data */
int itex, hitex; /* Texture ids for de/selected textures */
void pick(int *id)
/* Callback when an item is clicked */
{
sel[*id] = (sel[*id]+1)%2; /* Toggle the selection */
cs2th(*id); /* Update handle list */
}
void cb(double *t, int *kc)
{
COLOUR normal = { 1.0, 1.0, 1.0 };
COLOUR hilite = { 1.0, 1.0, 1.0 }; /* Highlight colour */
float hsize = 0.02; /* Size of handle */
int i; /* Loop variable */
for (i=0;i<N;i++) {
ns2vthpoint(xyz[i], col[i], 3); /* Draw thick point */
ds2ahx(xyz[i], hsize, itex, hitex, normal, hilite, i, sel[i]);
/* Draw handles with special textures */
}
}
int main(int argc, char *argv[])
{
int i, j; /* Loop varibale */
srand48((long)time(NULL)); /* Seed random numbers */
fprintf(stderr,"Shift-s to toggle handles\nShift-c to toggle crosshair\n");
fprintf(stderr,"Right mouse select\n");
s2opend("/?",argc, argv); /* Open the display */
s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */
s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */
for (i=0;i<N;i++) { /* Set-up globals */
xyz[i].x = drand48()*2.0 - 1.0; /* Random position */
xyz[i].y = drand48()*2.0 - 1.0;
xyz[i].z = drand48()*2.0 - 1.0;
col[i].r = drand48(); /* Random colour */
col[i].g = drand48();
col[i].b = drand48();
sel[i] = 0; /* Not currently selected */
}
itex = ss2ct(16,16); /* Create a new texture */
hitex = ss2ct(16,16); /* Create a new texture */
int width, height; /* Texture size */
char *tex1 = ss2gt(itex, &width, &height); /* Get texture memory */
char *tex2 = ss2gt(hitex, &width, &height); /* Get texture memory */
int iid; /* Index into texture arrays */
for (j=0;j<height;j++) {
for (i=0;i<width;i++) {
iid = (j*width + i)*4; /* Stored as (r, g, b, alpha) */
tex1[iid ] = drand48()*255; /* Randomish Red */
tex1[iid+1] = 0; /* Green */
tex1[iid+2] = 0; /* Blue */
tex1[iid+3] = 100; /* Alpha channel: 100/255 */
tex2[iid ] = 0; /* Red */
tex2[iid+1] = drand48()*255; /* Randomish Green */
tex2[iid+2] = 0; /* Blue */
tex2[iid+3] = 100; /* Alpha channel: 100/255 */
}
}
ss2pt(itex); /* Push back textures for use */
ss2pt(hitex);
cs2thv(1); /* Make sure handles are visible */
cs2scb(&cb); /* Install dynamic callback */
cs2shcb(&pick); /* Install handle callback */
s2show(1); /* Open the s2plot window */
return 1;
}
Back to S2PLOT function list.