ftp.nice.ch/pub/next/graphics/3d/geomview.1.4.1.s.tar.gz#/Geomview/src/bin/example/main.c

This is main.c in view mode; [Download] [Up]

/*
 *      file:   main.c:   
 *      author: Charlie Gunn & Tamara Munzner
 *      date:   September 1, 1992
 *      
 *      simple example of geomview external module and
 *	OOGL graphics library routines.
 *
 *      The main program continually computes a function on a mesh of
 *      (x,y) pairs.  The updated mesh is printed to stdout. When this
 *	program is invoked as a geomview external module, pipes are hooked
 * 	up 
 */

#include <math.h>
#include <stdio.h>
#include "forms.h"
#include "panel.h"
#include "ooglutil.h"

float dt;


/* replace this with your favorite function */
float
myfunc(x,y,t)
     float x,y,t;
{
        float r;
        r = sqrt(x*x+y*y) + .000001;
        return(sin(r + t)*sqrt(r));
}

main(argc, argv)        
     char **argv;
{
        int xdim, ydim, i, j;
        float xmin, xmax, ymin, ymax, xsize, ysize, dx, dy, x, y, t, zscale;
        float *data;
        
        xdim = 24;
        ydim = 24;
        xmin = -5;
        xmax = 5;
        ymin = -5;
        ymax = 5;
        zscale = 2.0;

	dt = .1; /* initial velocity */

	/* geomview communications setup. */

        Begin_OOGL();

	/* If we don't foreground then the process forks and dies
	   as soon as we do graphics. This is bad.
	 */

	foreground();

	/* This routine is defined in the code generated by 
	   the forms designer.
	 */

        create_the_forms();

	/* We set the slider and display the form. */

	fl_set_slider_bounds(VelocitySlider, 0.0, 1.0);
	fl_set_slider_value(VelocitySlider, dt);
	fl_show_form(Example, FL_PLACE_SIZE, TRUE, "Example");

        
        xsize = xmax-xmin;
        ysize = ymax-ymin;
        dx = xsize/(xdim-1);
        dy = ysize/(ydim-1);
        
        data = (float *) OOGLNewN(float, xdim * ydim);
        for (t=0; ; t += dt)
        {
	        /* Let forms library do its thing. */
	        fl_check_forms();

                /* compute mesh of some function value */
                for (j=0, y = -ysize/2; j<ydim; ++j, y += dy)
                {
                        for (i=0, x = -xsize/2; i<xdim; ++i, x += dx)
                        {
                                data[j*xdim + i] = myfunc(x,y,t);
                        }
                }
                
                /* geomview communications update */
                UpdateOOGL(xdim, ydim, zscale, data);
        }
	
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.