Skip to content

Commit

Permalink
ray4: tweak function separators
Browse files Browse the repository at this point in the history
  • Loading branch information
hollasch committed Oct 31, 2024
1 parent 33a0c31 commit 9674521
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 116 deletions.
18 changes: 9 additions & 9 deletions ray4/src/r4_color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,57 +23,57 @@
#include "r4_color.h"


//__________________________________________________________________________________________________

//==================================================================================================
inline double clamp_double(double x, double min, double max) {
return clamp(x, min, max);
}
//__________________________________________________________________________________________________

//==================================================================================================
bool Color::operator== (const Color& other) const {
return r == other.r && g == other.g && b == other.b;
}
//__________________________________________________________________________________________________

//==================================================================================================
bool Color::operator!= (const Color& other) const {
return !(*this == other);
}
//__________________________________________________________________________________________________

//==================================================================================================
Color& Color::operator*= (double scale) {
r *= scale;
g *= scale;
b *= scale;
return *this;
}
//__________________________________________________________________________________________________

//==================================================================================================
Color& Color::operator*= (const Color& other) {
r *= other.r;
g *= other.g;
b *= other.b;
return *this;
}
//__________________________________________________________________________________________________

//==================================================================================================
Color& Color::operator+= (const Color& other) {
r += other.r;
g += other.g;
b += other.b;
return *this;
}
//__________________________________________________________________________________________________

//==================================================================================================
Color Color::operator* (double scale) const {
return {scale * r, scale * g, scale * b};
}
//__________________________________________________________________________________________________

//==================================================================================================
Color Color::operator* (const Color& other) const {
return {r * other.r, g * other.g, b * other.b};
}
//__________________________________________________________________________________________________

//==================================================================================================
Color Color::clamp(double min, double max) const {
return Color(clamp_double(r, min, max), clamp_double(g, min, max), clamp_double(b, min, max));
}
76 changes: 39 additions & 37 deletions ray4/src/r4_hit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,42 @@



//==================================================================================================
// All intersection functions must behave in the same manner, since they are called as
// object-oriented functions that behave generically for different objects. Each function takes the
// same parameters and returns a boolean value. Operation of each function is as follows:
//
// The functions take the following parameter list:
//
// ObjInfo* objptr : Pointer to the Object Structure
// Ray4 ray : Ray Origin
// double *mindist: Closest Intersection Distance So Far
// Point4 *intr : Intersection Point
// Vector4 *normal : Surface Normal at Intersection Point
//
// If the ray does not intersect the object, the intersection function returns false and does not
// alter `mindist', `intr' or `normal'.
//
// If the mindist parameter is null, then it's assumed that the calling program is not interested in
// the specifics of the intersection; it's only interested in whether the ray intersects the object
// (as in shadow testing). In this case, if the ray does intersect the object, the function
// immediately returns true, but does not alter the `mindist', `intr' or `normal' parameters.
//
// If the ray intersects the object, the intersection function returns true and the `mindist',
// `intr' and `normal' parameters are all set according to the intersection point if the following
// are true:
//
// 1) The initial `mindist' value is -1, or
// 2) The intersection point is a positive (albeit small) epsilon distance along the ray and is
// closer than the initial `mindist' value.
//
// If these conditions are not met, then even if the ray intersects the object, the intersection
// function returns false.
//
// Note that these routines still behave properly if either the `intr' or `normal' parameters are
// null.
//==================================================================================================
//==============================================================================================
// All intersection functions must behave in the same manner, since they are called as
// object-oriented functions that behave generically for different objects. Each function takes
// the same parameters and returns a boolean value. Operation of each function is as follows:
//
// The functions take the following parameter list:
//
// ObjInfo* objptr : Pointer to the Object Structure
// Ray4 ray : Ray Origin
// double *mindist: Closest Intersection Distance So Far
// Point4 *intr : Intersection Point
// Vector4 *normal : Surface Normal at Intersection Point
//
// If the ray does not intersect the object, the intersection function returns false and does
// not alter `mindist', `intr' or `normal'.
//
// If the mindist parameter is null, then it's assumed that the calling program is not
// interested in the specifics of the intersection; it's only interested in whether the ray
// intersects the object (as in shadow testing). In this case, if the ray does intersect the
// object, the function immediately returns true, but does not alter the `mindist', `intr' or
// `normal' parameters.
//
// If the ray intersects the object, the intersection function returns true and the `mindist',
// `intr' and `normal' parameters are all set according to the intersection point if the
// following are true:
//
// 1) The initial `mindist' value is -1, or
// 2) The intersection point is a positive (albeit small) epsilon distance along the ray and
// is closer than the initial `mindist' value.
//
// If these conditions are not met, then even if the ray intersects the object, the intersection
// function returns false.
//
// Note that these routines still behave properly if either the `intr' or `normal' parameters
// are null.
//==============================================================================================



Expand Down Expand Up @@ -126,8 +127,8 @@ bool HitSphere (

return true;
}
//__________________________________________________________________________________________________

//==================================================================================================
bool HitTetPar (
ObjInfo *objptr, // Sphere to Test
const Ray4 &ray, // Trace Ray
Expand Down Expand Up @@ -278,7 +279,8 @@ bool HitTetPar (
return true;
}

//==================================================================================================
//__________________________________________________________________________________________________

bool HitTriangle (
ObjInfo *objptr, // Sphere to Test
const Ray4 &ray, // Trace Ray
Expand Down
15 changes: 8 additions & 7 deletions ray4/src/r4_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ FILE *outstream = nullptr; // Output Stream



//==================================================================================================
//__________________________________________________________________________________________________

void CloseInput () {
// Closes the input stream.

Expand All @@ -48,8 +49,8 @@ void CloseInput () {
fclose (instream);
instream = nullptr;
}
//__________________________________________________________________________________________________

//==================================================================================================
void CloseOutput () {
// Closes the output stream.

Expand All @@ -58,8 +59,8 @@ void CloseOutput () {
fclose (outstream);
outstream = nullptr;
}
//__________________________________________________________________________________________________

//==================================================================================================
const int UNREAD_NONE = -2;
static int unreadChar = UNREAD_NONE;

Expand All @@ -74,16 +75,16 @@ int ReadChar () {
unreadChar = UNREAD_NONE;
return c;
}
//__________________________________________________________________________________________________

//==================================================================================================
void UnreadChar (int c) {
// This routine, together with ReadChar allow to put back a character, which is something
// parsers often need. It cannot unread more than one character at a time though.

unreadChar = c;
}
//__________________________________________________________________________________________________

//==================================================================================================
void OpenInput () {
// This subroutine opens the input file. If no filename was given in the command-line arguments,
// we'll use the standard input stream.
Expand All @@ -93,8 +94,8 @@ void OpenInput () {
else if (! (instream = fopen (infile, "r")))
Halt ("Open failed on input file (%s).", infile);
}
//__________________________________________________________________________________________________

//==================================================================================================
void OpenOutput () {
// This subroutine opens the output file.

Expand All @@ -106,7 +107,7 @@ void OpenOutput () {
Halt ("Open failed on output file (%s).", outfile);
}

//==================================================================================================
//__________________________________________________________________________________________________
void WriteBlock (
void *buff, // Source Buffer
int num) // Number of Bytes to Write
Expand Down
21 changes: 11 additions & 10 deletions ray4/src/r4_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ time_t StartTime; // Timestamp



//==================================================================================================
//__________________________________________________________________________________________________

char *MyAlloc (size_t size) {
// This routine allocates memory using the system malloc() function. If the malloc() call fails
// to allocate the memory, this routine halts the program with an "out of memory" message.
Expand All @@ -129,13 +130,13 @@ char *MyAlloc (size_t size) {

return block;
}
//__________________________________________________________________________________________________

//==================================================================================================
void MyFree (void *addr) {
free (addr);
}
//__________________________________________________________________________________________________

//==================================================================================================
void Halt (const char *message, ...) {
// This procedure replaces printf() to print out an error message, and has the side effect of
// cleaning up before exiting (de-allocating memory, closing open files, and so on).
Expand Down Expand Up @@ -199,8 +200,8 @@ void Halt (const char *message, ...) {

exit ((!message) ? 0 : 1);
}
//__________________________________________________________________________________________________

//==================================================================================================
char *GetField (char *str, ushort *value) {
// These subroutine process the command-line arguments. The first two routines get each field of
// the resolution, aspect ratio, and scan range triples.
Expand All @@ -223,8 +224,8 @@ char *GetField (char *str, ushort *value) {

return (*str == ':') ? (str+1) : str;
}
//__________________________________________________________________________________________________

//==================================================================================================
char *GetRange (
char *str, // Source String
ushort *val1, // First Destination Value of Range
Expand Down Expand Up @@ -271,8 +272,8 @@ char *GetRange (

return (*str == ':') ? (str+1) : str;
}
//__________________________________________________________________________________________________

//==================================================================================================
void ProcessArgs (int argc, char *argv[]) {
// This subroutine grabs the command-line arguments and the environment variable arguments (from
// RAY4) and sets up the raytrace parameters.
Expand Down Expand Up @@ -497,8 +498,8 @@ void WriteInteger32(ulong value) {

WriteBlock(block, 4);
}
//__________________________________________________________________________________________________

//==================================================================================================
void WriteHeader(const ImageHeader& header) {
WriteInteger32(header.magic);
WriteInteger8(header.version);
Expand All @@ -513,8 +514,8 @@ void WriteHeader(const ImageHeader& header) {
for (int i=0; i < 3; ++i)
WriteInteger16(header.end[i]);
}
//__________________________________________________________________________________________________

//==================================================================================================
void CalcRayGrid (void) {
// This procedure calculates the ray-grid basis vectors.

Expand Down Expand Up @@ -568,8 +569,8 @@ void CalcRayGrid (void) {

Gorigin += (Gx/2) + (Gy/2) + (Gz/2);
}
//__________________________________________________________________________________________________

//==================================================================================================
void FireRays () {
// This is the main routine that fires the rays through the ray grid and into the 4D scene.

Expand Down Expand Up @@ -656,8 +657,8 @@ void FireRays () {
if (scancount != 0)
WriteBlock (scanbuff, scanlsize * scancount);
}
//__________________________________________________________________________________________________

//==================================================================================================
int main (int argc, char *argv[]) {
// The following is the entry procedure for the ray4 ray tracer.

Expand Down
Loading

0 comments on commit 9674521

Please sign in to comment.