Mail Archives: djgpp/1994/03/15/03:59:03
I have a program that compilers and runs successfully as a .C program. I
changed it to a .CC program, and tried -lgr_p as a guess, but then I get
undefined reference to 'mcount' lots of times.
Any ideas what I am doing wrong? Also, getkey() isn't accepted any more as a
statement.
(Program appended as a freebie.)
Mike Piff
/* Auto-stereo program---Mike Piff*/
#include <stdlib.h>
#include <stdio.h>
#include <graphics.h>
#include <math.h>
#define EYES 180
#define GROUND (EYES/2)
int WIDTH, HEIGHT,RADIUS;
int same[2000],colour[2000];
int nrfcolours;
int randomColour()
{
  return (int)((16.0*(float)random())/((float)RAND_MAX))%nrfcolours;
}
int ancestor(int i)
{
   if(same[i]==i)
      return i;
   else return ancestor(same[i]);
}
draw3D(int (*z)(int,int))
{
   int x,y,i,j,sep;
   for(y=0;y<HEIGHT;y++){
      for(x=0;x<=WIDTH;x++)same[x]=x;
      for (x=0;x<=WIDTH;x++){
        sep=z(x,y);
        if (((sep%2)==1) && ((y%2)==1)) i=x-((sep + 1)/2);
        else i=x-(sep/2);
        j=i+sep;
        if((i>=0)&&(j<WIDTH))
        {
          i=ancestor(i); j=ancestor(j);
          if(i<j) same[i]=j;
          else same[j]=i;
        };
      };
      for(x=WIDTH-1;x>=0;x--)
      {
        if(same[x]==x) colour[x]=randomColour();
        else colour[x]=colour[ancestor(x)];
        GrPlot(x,y,colour[x]);
      };
   }
}
int sphere(int x,int y)
{
  int r,R,a,b;
  a=WIDTH/2; b=HEIGHT/2;
  x=x-a; y=y-b;
  r=(x*x+y*y); R=RADIUS*RADIUS;
  if(r<R) return (0.9*GROUND - sqrt(R-r)/10);
  else return GROUND;
}
main (int argc, char *argv[])
{
  /* srandom(time());*/
  char buf[100];
  char **tmp;
  if (argc==1) nrfcolours=2;
  else {
    nrfcolours=(int)strtol(argv[1],tmp,10);
    if(nrfcolours<2) nrfcolours=2;
  }
  GrSetMode(GR_default_graphics);
  WIDTH = GrSizeX();
  HEIGHT = GrSizeY();
  RADIUS=HEIGHT/2;
  draw3D(sphere);
  getkey();
  GrSetMode(GR_default_text);
  /*printf("WIDTH=%d, HEIGHT=%d\n",WIDTH,HEIGHT);*/
}
- Raw text -