home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
hensa
/
graphics
/
a150_1
/
!Demo4
/
c
/
plot
< prev
next >
Wrap
Text File
|
1992-02-10
|
3KB
|
113 lines
/******************************************************************************
* *
* plot.c *
* *
******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <swis.h>
#include <os.h>
#include <bbc.h>
#include "GrpLib.h"
#include "extern.h"
int ObjNb=0;
Envi *enviobs;
/*****************************************************************************/
void RotVec(vec3 q,mat33 m,vec3 p)
{
q[0] = ((m[0][0]*p[0] + m[1][0]*p[1] + m[2][0]*p[2])>>14);
q[1] = ((m[0][1]*p[0] + m[1][1]*p[1] + m[2][1]*p[2])>>14);
q[2] = ((m[0][2]*p[0] + m[1][2]*p[1] + m[2][2]*p[2])>>14);
}
/*****************************************************************************/
ObjTab *(*InitPlot(int nb))
{
enviobs = MakeEnvi(1, 0, 0x50);
ObjNb = 0;
return(malloc(nb*sizeof(void *)));
}
/*****************************************************************************/
void AddObject(ObjTab *table[],Object *obj,void (*fp)(),
int (*fc)(),int type,void *desc)
{
ObjTab *cell;
cell = malloc(sizeof(ObjTab));
cell->object = obj;
cell->plot = fp;
cell->collision= fc;
cell->type = type;
cell->desc = desc;
table[ObjNb++] = cell;
}
/*****************************************************************************/
void Plot(ObjTab *table[],Envi *envi,Object *obs)
{
Object *obj;
ObjTab *tmp;
int i,j;
double d;
mat33 inv;
InvMat(inv,obs->Rep);
RotVec(enviobs->DirecSrc[0],inv,envi->DirecSrc[0]);
for (i=0 ; i<ObjNb ; i++) {
obj = table[i]->object;
d = (double)(obj->Org[0] - obs->Org[0]) *
(double)(obj->Org[0] - obs->Org[0]);
d += (double)(obj->Org[1] - obs->Org[1]) *
(double)(obj->Org[1] - obs->Org[1]);
d += (double)(obj->Org[2] - obs->Org[2]) *
(double)(obj->Org[2] - obs->Org[2]);
table[i]->d = d;
}
for (i=0 ; i<ObjNb-1 ; i++)
for (j=i+1 ; j<ObjNb ; j++)
if (table[i]->d < table[j]->d) {
tmp = table[i];
table[i] = table[j];
table[j] = tmp;
}
for (i=0 ; i<ObjNb ; i++)
if (obs != table[i]->object)
switch (table[i]->type) {
case 0 : (*table[i]->plot)(enviobs,obs,table[i]->object); break;
case 1 : (*table[i]->plot)(enviobs,obs,table[i]->object,table[i]->desc);
break;
}
}
/*****************************************************************************/
int Collision(ObjTab *table[],Object *obs)
{
int i,c,cmax=0;
for (i=0 ; i<ObjNb ; i++)
if (obs != table[i]->object)
if (*table[i]->collision != NULL) {
switch (table[i]->type) {
case 0 : c = (*table[i]->collision)(obs,table[i]->object); break;
case 1 : c = (*table[i]->collision)(obs,table[i]->object,table[i]->desc);
break;
}
if (c>=cmax) cmax=c;
}
return(cmax);
}