Function:ss2c3dt
From S2PLOT
(Difference between revisions)
| Revision as of 23:02, 7 January 2009 S2plot admin (Talk | contribs) ← Previous diff |
Revision as of 05:29, 29 August 2011 S2plot admin (Talk | contribs) Next diff → |
||
| Line 1: | Line 1: | ||
| ==ss2c3dt== | ==ss2c3dt== | ||
| - | Create an empty 3D texture. | + | Create an empty 3d texture. |
| ==Prototype== | ==Prototype== | ||
| Line 13: | Line 13: | ||
| ==See Also== | ==See Also== | ||
| <table> | <table> | ||
| - | <tr><td>[[Function:ss2g3dt |ss2g3dt]]</td><td> Fetch pointer to 3D texture.</td></tr> | + | <tr><td>[[Function:ss2g3dt |ss2g3dt]]</td><td> Fetch pointer to 3d texture.</td></tr> |
| + | <tr><td>[[Function:ns2texpoly3d |ns2texpoly3d]]</td><td> Draw a 3d texture.</td></tr> | ||
| <table> | <table> | ||
| Line 19: | Line 20: | ||
| <code><pre> | <code><pre> | ||
| + | #include <stdio.h> | ||
| + | #include <stdlib.h> | ||
| + | #include "s2plot.h" | ||
| + | |||
| + | 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 */ | ||
| + | |||
| + | iP[0].x = iP[3].x = -1.0; /* Define polygon vertices */ | ||
| + | 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; | ||
| + | |||
| + | 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> | </pre></code> | ||
Revision as of 05:29, 29 August 2011
ss2c3dt
Create an empty 3d texture.
Prototype
unsigned int ss2c3dt(int width, int height, int depth);
Description
Create an empty 3D texture.
See Also
| ss2g3dt | Fetch pointer to 3d texture. |
| ns2texpoly3d | Draw a 3d texture. |
