#include <math.h>
#include <stdlib.h>
Go to the source code of this file.
Data Structures | |
struct | s_tuple |
Tuple means a list of ordered things. The struct t_tuple stores coordinates for a left-handed coordinate system, i.e, the thumb of your left hand points to x in the right direction, the fingers point to y and curling the fingers towards the palm point to z. More... | |
struct | s_color |
The struct s_color stores the color values of ray tracing. It contains a field for red, green and blue values. If all components are 1, the final color is white. Otherwise, if all of them are 0, the resulting color is black. Therefore, each field has a range between 0 and 1. More... | |
Typedefs | |
typedef struct s_tuple | t_tuple |
Tuple means a list of ordered things. The struct t_tuple stores coordinates for a left-handed coordinate system, i.e, the thumb of your left hand points to x in the right direction, the fingers point to y and curling the fingers towards the palm point to z. More... | |
typedef t_tuple | t_point |
The type t_point is a syntatic sugar for any structure t_tuple whose w's field equals to 1, i.e., the tuple is a point. | |
typedef t_tuple | t_vector |
The type t_point is a syntatic sugar for any structure t_tuple whose w's field equals to 0, i.e., the tuple is a vector. | |
typedef struct s_color | t_color |
The struct s_color stores the color values of ray tracing. It contains a field for red, green and blue values. If all components are 1, the final color is white. Otherwise, if all of them are 0, the resulting color is black. Therefore, each field has a range between 0 and 1. More... | |
Functions | |
t_tuple | tuple (double x, double y, double z, double w) |
The function tuple() instances a new material of struct type t_tuple with the given values passed as parameter. More... | |
t_tuple | point (double x, double y, double z) |
This function is a simplification of the function tuple(). It will create a point with the given coordinates passed as parameter and set the field w to 1. More... | |
t_tuple | vector (double x, double y, double z) |
This function is a simplification of the function tuple(). It will create a point with the given coordinates passed as parameter and set the field w to 0. More... | |
t_tuple | add (t_tuple a, t_tuple b) |
The add() function sums two tuples. A vector plus a point results in a point (w values: 1 + 0 = 1). A point plus a point results in a point (w values: 0 + 0 = 0). A tuple plus a tuple results in neither a vector or a point (w values: 1 + 1 = 2). More... | |
t_tuple | subtract (t_tuple a, t_tuple b) |
The subtract() function subtract two tuples. A vector minus a point results in a point (w values: 1 - 0 = 1). A point minus a point results in a point (w values: 0 - 0 = 0). A tuple minus a tuple results in a tuple with a w of 0, which is another vector representing the change in direction between the two vectors. A point minus a vector results in a w of -1 (0 - 1 = 1), which is neither a point or a vector. When this case happens, it's necessary to use counterpart function negate(). More... | |
t_tuple | negate (t_tuple a) |
The function negate() returns the opposite vector of a given vector passed as parameter. If a vector poins from a surface toward a light source, the opposite vector points from the light source back to the surface. More... | |
t_tuple | multiply (t_tuple a, double scalar) |
The function multiply() multiplies a vector by a scalar value, i.e., it changes the vector length uniformly. More... | |
t_tuple | divide (t_tuple a, double scalar) |
The function divide() divides a vector by a scalar value, i.e., it changes the vector length uniformly. More... | |
double | magnitude (t_tuple vector) |
The function magnitude() gets the magnitude or length of a given vector passed as parameter. Vectors with magnitudes of 1 are called unit vectors or direction vectors. More... | |
t_tuple | normalize (t_tuple vector) |
The function normalize() takes an arbitrary vector and converts it into a unit vector. It keeps the calculations anchored relative to a common scale, i.e., keeps all vectors speaking the same language. More... | |
double | dot (t_tuple a, t_tuple b) |
The function dot() computes the sum of the products of the corresponding components of each vector. The smaller the dot product, the larger the angle between the vectors. A dot product of 1 means the vectors are identical and a dot product of -1 means they point in opposite directions. Thus, if the two vectors are unit vectors, the dot product is the cosine of them. More... | |
t_tuple | cross (t_tuple a, t_tuple b) |
The function cross() multiplies vectors, instead of tuples. After all, the ray traces only needs a three-dimensional value anyway. The order of the operands matters and the result is a vector perpendicular to both of the original vectors. Changes to the operand order changes the direction of the resulting perpendicular vector. More... | |
t_tuple | reflect (t_tuple in, t_tuple normal) |
This function returns the result of reflecting the in vector around the normal vector. More... | |
t_color | new_color (double red, double green, double blue) |
The function new_color() instances a new color of struct type s_color with the given values passed as parameter. More... | |
t_color | add_color (t_color a, t_color b) |
The function add_color() combines the intensity of each RGB color component of a and b. Adding (1, 0, 0) to (0, 1, 0) results in (1, 1, 0), i.e., adding red to green results in yellow. More... | |
t_color | subtract_color (t_color a, t_color b) |
The function subtract_color() decreases the intensity of each RGB color component of a and b. Subtracting (1, 0, 0) to (0, 1, 0) results in (1, 0, 0), i.e., subtracting red from green results in red. More... | |
t_color | multiply_color (t_color color, double scalar) |
The function multiply_color() scales the intensities of each RGB color component of the parameter color by a constant parameter scalar. For example, multiplying (1, 0, 0) by 0.5 or 1.5 result in (0.5, 0, 0) or (1.5, 0, 0). In other words, the red components were halved or doubled. More... | |
t_color | hadamard_product (t_color a, t_color b) |
The function hadamard_product() blends two color together by multiplying corresponding components of each color. This process is known as Hadamard product or Schur product. For example, to view a yellow-green surface under reddish-purple light would result in a red-like color because the red component would be highest among the RGB values. More... | |
The struct s_color stores the color values of ray tracing. It contains a field for red, green and blue values. If all components are 1, the final color is white. Otherwise, if all of them are 0, the resulting color is black. Therefore, each field has a range between 0 and 1.
red | Represents the red value of the RGB scale. |
green | Represents the green value of the RGB scale. |
blue | Represents the blue value of the RGB scale. |
Tuple means a list of ordered things. The struct t_tuple stores coordinates for a left-handed coordinate system, i.e, the thumb of your left hand points to x in the right direction, the fingers point to y and curling the fingers towards the palm point to z.
x | Represents the value of the x-axis coordinate. |
y | Represents the value of the y-axis coordinate. |
z | Represents the value of the z-axis coordinate. |
w | Distinguishes the t_tuple between a vector or a point. If w = 0, then the tuple is a vector. Otherwise, if w = 1, the tuple is a point. |
The add() function sums two tuples. A vector plus a point results in a point (w values: 1 + 0 = 1). A point plus a point results in a point (w values: 0 + 0 = 0). A tuple plus a tuple results in neither a vector or a point (w values: 1 + 1 = 2).
a | Receives the first tuple to sum. |
b | Receives the second tuple to sum. |
The function add_color() combines the intensity of each RGB color component of a and b. Adding (1, 0, 0) to (0, 1, 0) results in (1, 1, 0), i.e., adding red to green results in yellow.
a | Receives the first color to sum. |
b | Receives the second color to sum. |
The function cross() multiplies vectors, instead of tuples. After all, the ray traces only needs a three-dimensional value anyway. The order of the operands matters and the result is a vector perpendicular to both of the original vectors. Changes to the operand order changes the direction of the resulting perpendicular vector.
a | Receives the first vector to be multiplied. |
b | Receives the second vector to be multiplied. |
The function divide() divides a vector by a scalar value, i.e., it changes the vector length uniformly.
a | Receives the t_tuple vector to be scaled by division. |
scalar | Receives a double value to shrink the vector. |
The function dot() computes the sum of the products of the corresponding components of each vector. The smaller the dot product, the larger the angle between the vectors. A dot product of 1 means the vectors are identical and a dot product of -1 means they point in opposite directions. Thus, if the two vectors are unit vectors, the dot product is the cosine of them.
a | Receives the first vector for the dot product. |
b | Receives the second vector for the dot product. |
The function hadamard_product() blends two color together by multiplying corresponding components of each color. This process is known as Hadamard product or Schur product. For example, to view a yellow-green surface under reddish-purple light would result in a red-like color because the red component would be highest among the RGB values.
a | Receives the first color to be blended. |
b | Receives the second color to be blended. |
double magnitude | ( | t_tuple | vector | ) |
The function magnitude() gets the magnitude or length of a given vector passed as parameter. Vectors with magnitudes of 1 are called unit vectors or direction vectors.
vector | Receives the vector to its magnitude value. |
The function multiply() multiplies a vector by a scalar value, i.e., it changes the vector length uniformly.
a | Receives the t_tuple vector to be scaled by multiplication. |
scalar | Receives a double value to stretch out the vector. |
The function multiply_color() scales the intensities of each RGB color component of the parameter color by a constant parameter scalar. For example, multiplying (1, 0, 0) by 0.5 or 1.5 result in (0.5, 0, 0) or (1.5, 0, 0). In other words, the red components were halved or doubled.
color | Receives the color to be scaled. |
scalar | Receives the scale factor to be applied for each color value. |
The function negate() returns the opposite vector of a given vector passed as parameter. If a vector poins from a surface toward a light source, the opposite vector points from the light source back to the surface.
a | Receives the vector to be negated. |
t_color new_color | ( | double | red, |
double | green, | ||
double | blue | ||
) |
The function new_color() instances a new color of struct type s_color with the given values passed as parameter.
red | Receives a red color value for the RGB scale. |
green | Receives a green color value for the RGB scale. |
blue | Receives a blue color value for the RGB scale. |
The function normalize() takes an arbitrary vector and converts it into a unit vector. It keeps the calculations anchored relative to a common scale, i.e., keeps all vectors speaking the same language.
vector | Receives the vector to be normalized to a unit vector. |
t_tuple point | ( | double | x, |
double | y, | ||
double | z | ||
) |
This function is a simplification of the function tuple(). It will create a point with the given coordinates passed as parameter and set the field w to 1.
x | Receives a value for x-axis coordinate. |
y | Receives a value for y-axis coordinate. |
z | Receives a value for z-axis coordinate. |
This function returns the result of reflecting the in vector around the normal vector.
in | A struct of type t_tuple containing the vector to be reflected. |
normal | A struct of type t_tuple storing the normal vector to be used as reference for the reflection of the in vector. |
The subtract() function subtract two tuples. A vector minus a point results in a point (w values: 1 - 0 = 1). A point minus a point results in a point (w values: 0 - 0 = 0). A tuple minus a tuple results in a tuple with a w of 0, which is another vector representing the change in direction between the two vectors. A point minus a vector results in a w of -1 (0 - 1 = 1), which is neither a point or a vector. When this case happens, it's necessary to use counterpart function negate().
a | Receives the first tuple to subtract. |
b | Receives the second tuple to subtract. |
The function subtract_color() decreases the intensity of each RGB color component of a and b. Subtracting (1, 0, 0) to (0, 1, 0) results in (1, 0, 0), i.e., subtracting red from green results in red.
a | Receives the first color to decrease. |
b | Receives the second color to decrease. |
t_tuple tuple | ( | double | x, |
double | y, | ||
double | z, | ||
double | w | ||
) |
The function tuple() instances a new material of struct type t_tuple with the given values passed as parameter.
x | Receives a value for x-axis coordinate. |
y | Receives a value for y-axis coordinate. |
z | Receives a value for z-axis coordinate. |
w | Receives 1 if the tuple is point or 0 if the tuple is a vector. |
t_tuple vector | ( | double | x, |
double | y, | ||
double | z | ||
) |
This function is a simplification of the function tuple(). It will create a point with the given coordinates passed as parameter and set the field w to 0.
x | Receives a value for x-axis coordinate. |
y | Receives a value for y-axis coordinate. |
z | Receives a value for z-axis coordinate. |