Function:ss2g3dt
From S2PLOT
(Difference between revisions)
Revision as of 23:14, 6 January 2009 S2plot admin (Talk | contribs) ← Previous diff |
Current revision S2plot admin (Talk | contribs) |
||
Line 12: | Line 12: | ||
==See Also== | ==See Also== | ||
+ | <table> | ||
+ | <tr><td>[[Function:ss2c3dt |ss2c3dt]]</td><td> Create an empty 3D texture.</td></tr> | ||
+ | <tr><td>[[Function:ns2texpoly3d |ns2texpoly3d]]</td><td> Draw a 3d texture.</td></tr> | ||
+ | <table> | ||
==Code Example== | ==Code Example== | ||
<code><pre> | <code><pre> | ||
- | </pre></code> | + | #include <stdio.h> |
+ | #include <stdlib.h> | ||
+ | #include "s2plot.h" | ||
- | [[S2PLOT:Function List | Back]] to S2PLOT function list. | + | unsigned int texid; /* 3D Texture ID */ |
+ | void cb(double *t, int *kc) | ||
+ | { | ||
+ | int nverts = 4; /* Number of vertices in polygon */ | ||
+ | char trans = 't'; /* 3d texture transparency */ | ||
+ | float alpha = 0.7; /* Alpha channel value */ | ||
+ | XYZ iP[4]; /* Array of polygon vertices */ | ||
+ | XYZ iTC[4]; /* Array of texture coordinates */ | ||
+ | static float texidx = 0.0; /* Current z-texture coordinate */ | ||
- | __NOTOC__ | + | iP[0].x = iP[3].x = -1.0; /* Define polygon vertices */ |
- | __NOEDITSECTION__ | + | iP[1].x = iP[2].x = +1.0; |
+ | iP[0].y = iP[1].y = +1.0; | ||
+ | iP[2].y = iP[3].y = -1.0; | ||
+ | iP[0].z = iP[1].z = iP[2].z = iP[3].z = texidx*2.0 - 1.0; | ||
+ | iTC[0].x = iTC[3].x = 0; /* Define texture coordinates */ | ||
+ | iTC[1].x = iTC[2].x = 1; | ||
+ | iTC[0].y = iTC[1].y = 1; | ||
+ | iTC[2].y = iTC[3].y = 0; | ||
+ | iTC[0].z = iTC[1].z = iTC[2].z = iTC[3].z = texidx; | ||
- | Back to [[Function:Template | template]] page. | + | COLOUR col = { 1,1,1 }; /* Draw the polygon boundaries */ |
+ | ns2vline(iP[0],iP[1],col); | ||
+ | ns2vline(iP[1],iP[2],col); | ||
+ | ns2vline(iP[2],iP[3],col); | ||
+ | ns2vline(iP[3],iP[0],col); | ||
+ | |||
+ | ns2texpoly3d(iP, iTC, nverts, texid, trans, alpha); /* Draw 3D texture */ | ||
+ | |||
+ | texidx += (1.0/320.0); /* Choose next z-texture coordinate */ | ||
+ | if (texidx > 1.0) texidx = 0.0; | ||
+ | } | ||
+ | |||
+ | int main(int argc, char *argv[]) | ||
+ | { | ||
+ | int Nx = 32, Ny = 32, Nz = 32; /* Texture dimensions */ | ||
+ | int w,h,d; /* Returned dimensions */ | ||
+ | |||
+ | s2opend("/?",argc,argv); /* Open the s2plot display device */ | ||
+ | s2swin(-1,1,-1,1,-1,1); /* Set the world coordinates */ | ||
+ | s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); | ||
+ | |||
+ | texid = ss2c3dt(Nx, Ny, Nz); /* Create a new 3d texture */ | ||
+ | unsigned char *bits = (unsigned char *)ss2g3dt(texid, &w, &h, &d); | ||
+ | /* Get the texture data for modification */ | ||
+ | int i, j, k; | ||
+ | long idx; | ||
+ | float x,y,z; | ||
+ | for (i=0;i<Nx;i++) { | ||
+ | x = -1.0 + i*(2.0/(float)(Nx-1)); | ||
+ | for (j=0;j<Ny;j++) { | ||
+ | y = -1.0 + j*(2.0/(float)(Ny-1)); | ||
+ | for (k=0;k<Nz;k++) { | ||
+ | z = -1.0 + k*(2.0/(float)(Nz-1)); | ||
+ | idx = ((i*Ny + j)*Nz + k)*4; | ||
+ | if ((x*x + y*y + z*z) < 1.0) { /* 3D solid red sphere */ | ||
+ | bits[idx + 1 ] = 255; | ||
+ | ns2point(x,y,z,1,1,1); /* Plot point in sphere */ | ||
+ | } else { | ||
+ | bits[idx + 0 ] = 0; | ||
+ | } | ||
+ | |||
+ | bits[idx + 1 ] = 0; /* Blue channel */ | ||
+ | bits[idx + 2 ] = 0; /* Green channel */ | ||
+ | bits[idx + 3 ] = 255; /* Alpha channel */ | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | fprintf(stderr, "3d texture IS %d x %d x %d\n", w, h, d); | ||
+ | ss2pt(texid); /* Push back the texture */ | ||
+ | |||
+ | cs2scb(cb); /* Install a dynamic callback */ | ||
+ | |||
+ | s2show(1); /* Display the geometry */ | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </pre></code> | ||
+ | |||
+ | [[S2PLOT:Function List | Back]] to S2PLOT function list. | ||
+ | |||
+ | __NOTOC__ | ||
+ | __NOEDITSECTION__ |
Current revision
ss2g3dt
Fetch pointer to 3D texture.
Prototype
unsigned char *ss2g3dt(unsigned int itextureID, int *width, int *height, int *depth);
Description
Fetch pointer to 3D texture.
See Also
ss2c3dt | Create an empty 3D texture. |
ns2texpoly3d | Draw a 3d texture. |