Category : C Source Code
Archive   : DBW_REND.ZIP
Filename : MTH.C

 
Output of file : MTH.C contained in archive : DBW_REND.ZIP
#define MODULE_MATH
#include "ray.h"

void veczero(v)
vector v;
{
v[0] = 0.0;
v[1] = 0.0;
v[2] = 0.0;
}

void veccopy(from,to)
vector from,to;
{
to[0] = from[0];
to[1] = from[1];
to[2] = from[2];
}

void vecdump(v,str)
vector v;
char *str;
{
int i;

printf("%s\t",str);
for (i = 0; i < 3; i++) printf("%15.8f ",v[i]);
printf("\n");
}

static
float hlsvalue(n1,n2,hue)
float n1,n2,hue;
{
while (hue >= 360) hue -= 360;
while (hue < 0) hue += 360;
if (hue < 60) return n1 + ((n2 - n1) * hue / 60);
if (hue < 180) return n2;
if (hue < 240) return n1 + ((n2 - n1) * (240 - hue) / 60);
return n1;
}

void cv(x,y,z,v)
float x,y,z;
vector v;
{
v[0] = x;
v[1] = y;
v[2] = z;
}

void hls(h,l,s,v)
float h,l,s;
vector v;
{
float m1,m2;

if (s == 0) {
CV(l,l,l,v);
}
else {
m2 = (l <= .5) ? l * (1 + s) : l * (1 - s) + s;
m1 = 2 * l - m2;
CV( hlsvalue(m1,m2,h - 120),
hlsvalue(m1,m2,h),
hlsvalue(m1,m2,h + 120),
v);
}
}
void vecsub(v1,v2,r)
vector v1,v2,r;
{
r[0] = v1[0] - v2[0];
r[1] = v1[1] - v2[1];
r[2] = v1[2] - v2[2];
}

void vecsum(v1,v2,r)
vector v1,v2,r;
{
r[0] = v1[0] + v2[0];
r[1] = v1[1] + v2[1];
r[2] = v1[2] + v2[2];
}

void vecmul(v1,v2,r)
vector v1,v2,r;
{
r[0] = v1[0] * v2[0];
r[1] = v1[1] * v2[1];
r[2] = v1[2] * v2[2];
}

void vecdiv(v1,v2,r)
vector v1,v2,r;
{
r[0] = v1[0] / v2[0];
r[1] = v1[1] / v2[1];
r[2] = v1[2] / v2[2];
}

void vecscale(s,v,r)
float s;
vector v,r;
{
r[0] = s * v[0];
r[1] = s * v[1];
r[2] = s * v[2];
}

float norm(v)
vector v;
{
return (float)sqrt((v[0]*v[0]) + (v[1]*v[1]) + (v[2]*v[2]));
}

void normalize(v)
vector v;
{
float n;

n = 1.0 / NORM(v);
VECSCALE(n,v,v);
}

float dot(v1,v2)
vector v1,v2;
{
float result;

result = v1[0] * v2[0];
result += v1[1] * v2[1];
result += v1[2] * v2[2];

return result;
}

void cross(v1,v2,r)
vector v1,v2,r;
{
r[0] = (v1[1]*v2[2]) - (v2[1]*v1[2]);
r[1] = (v1[2]*v2[0]) - (v1[0]*v2[2]);
r[2] = (v1[0]*v2[1]) - (v2[0]*v1[1]);
}

void direction(f,t,d)
vector f,t,d;
{
VECSUB(t,f,d);
normalize(d);
}

long curstack() {
char dummy[5];
return((long)(dummy));
}


  3 Responses to “Category : C Source Code
Archive   : DBW_REND.ZIP
Filename : MTH.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/