Annotation of Examples/AppKit/Graph/PointMesh.m, revision 1.1

1.1     ! root        1: 
        !             2: /*
        !             3:     PointMesh.m
        !             4: 
        !             5:     A PointMesh takes an array of points in three dimensional space and renders
        !             6:     them as surface in space space using a Renderman bilinear patch mesh.
        !             7: 
        !             8:     You may freely copy, distribute, and reuse the code in this example.
        !             9:     NeXT disclaims any warranty of any kind, expressed or implied, as to its
        !            10:     fitness for any particular use.
        !            11: */
        !            12: 
        !            13: #import "Graph.h"
        !            14: 
        !            15: @implementation PointMesh
        !            16: 
        !            17: - init {
        !            18:     self = [super init];
        !            19:     color = NX_COLORWHITE;
        !            20:     return self;
        !            21: }
        !            22: 
        !            23: - free {
        !            24:     free(points);
        !            25:     return [super free];
        !            26: }
        !            27: 
        !            28: /*
        !            29:  * This copies ther given points into a 2D array that is formatted correctly
        !            30:  * for the RiPatchMesh() call we use to render the patch (below).
        !            31:  */
        !            32: - setPointsX:(float *)x y:(float *)y z:(float *)z
        !            33:        minX:(float)minX minY:(float)minY minZ:(float)minZ
        !            34:        maxX:(float)maxX maxY:(float)maxY maxZ:(float)maxZ
        !            35:        numU:(int)numU numV:(int)numV {
        !            36:     int i;
        !            37:     int totalPoints = numU * numV;
        !            38: 
        !            39:     uCount = numU;
        !            40:     vCount = numV;
        !            41:     free(points);
        !            42:     points = NXZoneMalloc([self zone], totalPoints * sizeof(RtPoint));
        !            43: 
        !            44:     for (i = 0; i < totalPoints; i++) {
        !            45:        points[i][0] = x[i];
        !            46:        points[i][1] = y[i];
        !            47:        points[i][2] = z[i];
        !            48:     }
        !            49:     return self;
        !            50: }
        !            51: 
        !            52: /*
        !            53:  * This method is called whenever the shape needs to render itself (its
        !            54:  * analogous to View's drawSelf:: method).  The patch renders itself by
        !            55:  * setting the surface type and the color, and then emitting one big bilinear
        !            56:  * patch mesh containing all our data points.
        !            57:  */
        !            58: - renderSelf:(RtToken)context {
        !            59:     static RtColor rgbColor;
        !            60:     
        !            61:     RiSurface("plastic", RI_NULL);
        !            62:     NXConvertColorToRGB(color, &rgbColor[0], &rgbColor[1], &rgbColor[2]);
        !            63:     RiColor(rgbColor);
        !            64:     RiPatchMesh(RI_BILINEAR, uCount, RI_NONPERIODIC, vCount, RI_NONPERIODIC, RI_P, points, RI_NULL);
        !            65:     return self;
        !            66: }
        !            67: 
        !            68: - setColor:(NXColor)newColor {
        !            69:     color = newColor;
        !            70:     return self;
        !            71: }
        !            72: 
        !            73: - (NXColor)color {
        !            74:     return color;
        !            75: }
        !            76: 
        !            77: @end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.