Category : Files from Magazines
Archive   : DDJ9407C.ZIP
Filename : RAYOBJ.CPP
/*** (C) Copyright A.MANGEN 1994 ***/
/***********************************************************************/
/*** PROJECT : RAY TRACING PROGRAM ***/
/*** PROGRAM NAME: RAYOBJ.CPP ***/
/*** VERSION : 1.1 ***/
/***-----------------------------------------------------------------***/
/*** DESCRIPTION : Ray Tracing Objects ***/
/***********************************************************************/
#include
#include
#include
#include
#include
#include "ray.h"
#include "raysvga.h"
#include "raytga.h"
#include "rayobj.h"
/***********************************************************************/
/*** Error : Standard Error Routine ***/
/***********************************************************************/
#define Here __FILE__,__LINE__
void Error(char *File,int Line,char *Format,...)
{ va_list arg_ptr;
va_start(arg_ptr,Format);
printf("(%s,%d) ",File,Line);
vprintf(Format,arg_ptr);
va_end(arg_ptr);
exit(1);
}
/***********************************************************************/
/*** Color : Base class for color ***/
/***********************************************************************/
int AssociativeAllocated; // Allocation index
char huge AssociativePalette[A+1][A+1][A+1]; // Associative Palette
void Init_AssociativePalette() // Initialize palette
{ AssociativeAllocated=1;
_fmemset(AssociativePalette,0,sizeof(AssociativePalette));
}
Col Color::Associate(int Spread,int Search) // Search a color in palette
{ int C;
int R0=(int) R*(A+1)/256; R0=min(A,R0); R0=max(A0,R0);
int G0=(int) G*(A+1)/256; G0=min(A,G0); G0=max(A0,G0);
int B0=(int) B*(A+1)/256; B0=min(A,B0); B0=max(A0,B0);
if((C=AssociativePalette[R0][Gin(")0); R0int) G*(A+1)/2)color Found an
/**st e
{ ciatiiiireturn(C
}
/lseivePcated=1;
_fmemset=255)itialize pale(")0); is full}
nt for SearR1=R0;R1
/********aleLook an
approxima iatiiiifor R1= if(G0=(-earch a;R1<=R0;R1++)ciatiiiifor SearG1= if(G0G(-earch a;G1
/********aleLook an
approxima iatiiiireturn(0
***/
/**************aleFound nothing iati}}
/lseiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiindex
che a new one}
nt VESA_Loade(intPcated=1;
_fmemse,ciatiiiiatiax(A63,R/4),ax(A63,G/4),ax(A63,B/4)
}
ativePcated=1;
_fmemse%10==1)iiiiiiiiiiindexiativvideo flickering iatiiiiiiiVESA_Ac;
ems ;iiiiiiiiiiiiiiindexc;
ems VGAt C;
iatiiiifor SearR1=R0;R1
/*** Color : Base clPoSear: Generic bolor with linked
***/
/***********************************************************************/
int AssociativePoSear*H =NULL;iiiiiiiiiiiiiiiiiiiiiiiiiiiiiindeLinked L
H ervePoSear*Trail=NULL;iiiiiiiiiiiiiiiiiiiiiiiiiiiiindeLinked L
TrailerveciatiiiiatiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiindePoSearConstructorvePoSea::PoSea(Coord x,Coord y,Coord z,ciatiass foc,ciatrd,ciatrs,ciatrr // Smaxref // Smakeshadowrg_ptrX=x; Y=y; Z=z; C=c
***/
/********aleData Encapsulchar ciatiRd=rd; Rs=rs; Rr=rr; MaxRef=maxref; MakeShadow=makeshadow iatiNext=NULL;iiiiiiiiiiiiiiiiiiiiiiiiiiiiii****aleBuild up linked
ciativePH ==NULL) H =thisociativePTrail!=NULL) Trail->Next=thisociatiPrev=Trail; Trail=thisoci};ciatiiiiatiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiindePoSearDestructorvePoSea::~PoSea(rg_ptrvePH ==this)iiiiiiiiiiiiiiiiiiiiiiiiiiiiiindeClean up linked
ciatiiiiH =NextociativePTrail==this)ciatiiiiTrail=PrevociativePPrev!=NULL)ciatiiiiPrev->Next=NextociativePNext!=NULL)ciatiiiiNext->Prev=Prevoci**************************************************************/
/*** Color : Base clSphLINE: InhLIited PoSear sphLINs ***/
/***********************************************************************/
int AssociativeCoord SphLIN::Intersect(Vector Vrg_ptrVector OC(X,Y,Z,X-V.X,Y-V.Y,Z-V.Z
}
Coord tpp=OC*V
}
Coord tdc2=R*R-(OC*OC-tpp*tppsociativePtdc2>0)iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiindeIs thLINEa hugtersectar ciatiptrtdc2=sqrtPtdc2
}
atiCoord tmax(Atpp-tdc2,tpp+tdc2
}
ativePt>0)ireturn(t
***/
/******ndeIf intfroearof observe ciatiiii/lseireturn(NO_INTERSECing
**ndeElseibehind observe ciati}}
/lseireturn(NO_INTERSECing
** **ndeNohugtersectar foundci};ci***********************************************************/
/*** Color : Base clPlanNE: InhLIited PoSear planNs ***/
/***********************************************************************/
int AssociativeCoord PlanN::Intersect(Vector Vrg_ptrCoord Denom=X*V.dX+Y*V.dY+Z*V.dZociativePDenom==0)ireturn(NO_INTERSECing
ndeNohugtersectar foundci
/lseciatiptrCoord tm-(X*V.X+Y*V.Y+Z*V.Z+D)/Denom
}
ativePt>0)ireturn(t
***/
/******ndeIf intfroearof observe ciatiiii/lseireturn(NO_INTERSECing
**ndeElseibehind observe ciati}}
};ci***********************************************************/
/*** Color : Base clScenNE: ScenNEo ***/
/***---------------*****************************************************/
int AssociativeScenN::ScenN(Coord camerax,Coord cameray,Coord cameraz,ass foambientrg_ptrCameraX=camerax;rCameraY=cameray;rCameraZ=cameraz;*aleData Encapsulchar ciatiAmbient=ambient; NL994 =0;}
};ci**// SecenN::AddL994 (Vector V,ass foIrg_ptrvePNL994
atiNL994 ++ iatiiiireturn(TRUE
}
}}
/lseireturn(FALSE
***/
/********aleToo many l994 s}
}tiiiiatiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiindeSee consta/ SMAX_LIGHTtiveCoord ScenN::ClosestIntersect(Vector V,iiiiiiiindeSe pale thNciatPoSear** Min // SehouldMakeShadow)iiiiiindeeeeclosesthugtersectar ci{rCoord t,tmin=NO_INTERSECing ;ciatPoSear* =H ;ciat* Min=NULL;ciatdociatptrveP!ehouldMakeShadow || ->MakeShadow) iatiii{ t= ->Intersect(V
}
atiivePat
}}
}}
= ->GetNext(
}
} while ( !=NULL)
}
return(tmin)oci*****iativScenN::Ray SearN,Vector V,asord f,ass fo&oIrg_ptPoSear* Min=NULL,* ShadowMin=NULL;ciatCoord tmClosestIntersect(V,& Min
ndeCompu; igtersectar tminciatveP Min!=NULL) iiiiiiiiiiiiiiiiiiiiiiiiindewith closesth Minciatpobj.fdef DiffusNciatiiiVector P=V^t;iiiiiiiiiiiiiiiiiiiiiiiiiiiiindePoSearofhugtersectar ciatiiiVector Un=! Min->GetN
l(P
}
atfor Seari=0;i
}
j.fdef ShadowciatiiiiatCoord tshadowmClosestIntersect((!Us)^0.01,& ShadowMin,TRUE
}
iiiatCoord Dist=Us.Length(
}
iiiatvePa ShadowMin==NULL)||(tshadow>Dist))ci#endifatiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiindeNo othLIEo foundci
atiii{ iCoord Diff=(!Us)*Un;iiiiiiiiiiiiiiiindeeeeon l994 en pathciatiiiiatiiiI=I+ Min->C*f* Min->Rd* if(G0Diff
}
j.fdef Specula ciatiiiiatiiivePaN==0)&&( Min->Rs>0))ciatiiiiatiii{ iVector Ur=Un*2*(Us*Un)-Us
ndeSpecula reflectar ciatiii
iiiatCoord Spec=(!Ur)*(-V
}
atiiiiatiiiI=I+L994 ass f[i]*f* Min->Rs*pow( if(G0Spec),20
}
atiiiiat}ci#endif}
atiii}}
}}
j.fdef Reflectar siiiiiiindeCheckSmaximum numbLIEof reflectar s/refractar s}
vePaN< Min->MaxRef)&&( Min->Rr>0))ciatiii{ iVector Uw=-Un*2*(V*Un)+V
}
atiiiUw=Uw^0.01;iiiiiindexdd some dista/ce along the vector tociatiiiiatiiiiiiiiiiiiiiiiindeaiativigtersectar with the samNEo ciatiiiiatRay N+1,Uw,f* Min->Rr,I
}
at}ci#endif}
#endif}
}ci*****iativScenN::Ray t SearMod *FormGetMaxX*FormGetMaxY*FormBW,ciatiLine,char NamN,Search) // Search ag_ptrveP!VESA_SetMod (Mod *GetMaxX*GetMaxY))ciatiiiie,int _LIN,"Cannot setiVESA mod 0x%x (%dx%d)",Mod *GetMaxX*GetMaxY)
}
switch(BW)ciatiptrcolor0:VESA_LoadBlack ;ib) k
}
aticolor1:VESA_LoadBW ;ib) k
}
}}
VESA_Ac;
ems ;iiiiiiiiiiiiiiilize palette
{ Assscreent C;
iatiePalette() ;iiiiiiiiiiiilize palette
{ Assmemoryt C;
iatiTGAhar iTGA(har NamN,GetMaxX*GetMaxY,BW)ive PalC) t iTARGA far iatifor SearZ=GetMaxY;Z>0;Z--)iiiiiiiiiiiiiiiiiindeScan
all pixels}
nt for SearX=0;X
atiiiiass foI=Ambient
}
atiiiiRay 0,!V,1.0,I
iiiiiiiiiiiiiiiiiiiiiindeCa v ray}
atiiiiswitch(BW)ciatiatiiii{iicolor0:ciatiiiiatiiiiiiiScreenntf([X] =I.pread,int ch) earch a;ciatiiiiatiiiiiiiTGAntf([3*X] max(A255,56; B0I.Ba;ciatiiiiatiiiiiiiTGAntf([3*X+1]max(A255,56; B0I.Ga;ciatiiiiatiiiiiiiTGAntf([3*X+2]max(A255,56; B0I.Ra;ciatiiiiatiiiiiiib) k
}
ati
aticolor1:ciatiiiiatiiiiiiiTGAntf([X]=Screenntf([X]=I.GrayScale(a;ciatiiiiatiiiiiiib) k
}
ati
}}
}}
VESA_WIitePixel(G0GetMaxY-Z,GetMaxX*Screenntf(a;ciatiiiiTGA.WIitePixel(GetMaxX*TGAntf()
}
}}
VESA_Ac;
ems ;iiiiiiiiiiiiiiilize paleFreshensscreent C;
iatiBeep(sociativePhar NamN==NULL)ciati{ (iati) getLine(a;ciatiiiiVESA_Show ;}
}}
VESA_Close((%s,%d) ",File,ass fs used : %d\n",cated;
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
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/