Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Makefile, fix broken C. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.xcodeproj
old
gloss
.*.d
4 changes: 2 additions & 2 deletions Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ typedef struct {
float red, green, blue;
} Color;

Color makeColorWhite();
Color makeColorBlack();
Color makeColorWhite(void);
Color makeColorBlack(void);
Color makeColorLightness(const float l);
Color makeColor(const float red, const float green, const float blue);

Expand Down
1 change: 1 addition & 0 deletions Container.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type * lowercaseType##ContainerAddValue(type##Container *container, const type v
assert(0); \
} \
} \
__attribute__((noreturn)) \
void lowercaseType##ContainerAddValues(type##Container *container, const type##Container values) { \
/* TODO: Actually implement. */ \
assert(0); \
Expand Down
84 changes: 84 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
.SUFFIXES:

CC := $(CROSS_COMPILE)gcc

FAST := -flto -fwhole-program \
-msse4.2 -ftree-vectorize \
-mtune=corei7 -march=corei7 \
-ffast-math

EXTRA_DEFS := -D_FILE_OFFSET_BITS=64
CFLAGS := -g -pipe -O2 -Wall \
$(FAST) \
-Wsign-compare -Wcast-align \
-Wstrict-prototypes \
-Wmissing-prototypes \
-Wmissing-declarations \
-Wmissing-noreturn \
-finline-functions \
-Wmissing-format-attribute \
-Wno-cast-align \
-I. -I/usr/include/SDL \
-std=gnu99 \
$(EXTRA_DEFS)

GLOSS_BIN := gloss
GLOSS_LIBS := -lSDL -lm
GLOSS_OBJ = \
Box.o \
Color.o \
Intersection.o \
main.o \
Material.o \
MaterialContainer.o \
Matrix.o \
Photon.o \
PhotonContainer.o \
PhotonEndPoint.o \
PhotonEndPointContainer.o \
Plane.o \
randf.o \
Ray.o \
Scene.o \
SceneObjectBox.o \
SceneObject.o \
SceneObjectContainer.o \
SceneObjectPlane.o \
SceneObjectSphere.o \
SceneObjectUnitPlane.o \
Sphere.o \
Vector.o

ALL_BIN := $(GLOSS_BIN)
ALL_OBJ := $(GLOSS_OBJ)
ALL_DEP := $(patsubst %.o, .%.d, $(ALL_OBJ))
ALL_TARGETS := $(ALL_BIN)

TARGET: all

.PHONY: all clean

all: $(ALL_BIN)

ifeq ($(filter clean, $(MAKECMDGOALS)),clean)
CLEAN_DEP := clean
else
CLEAN_DEP :=
endif

%.o %.d: %.c $(CLEAN_DEP) $(CONFIG_MAK) Makefile
@echo " [C] $<"
@$(CC) $(CFLAGS) -MMD -MF $(patsubst %.o, .%.d, $@) \
-MT $(patsubst .%.d, %.o, $@) \
-c -o $(patsubst .%.d, %.o, $@) $<

$(GLOSS_BIN): $(GLOSS_OBJ)
@echo " [LINK] $@"
@$(CC) $(CFLAGS) -o $@ $(GLOSS_OBJ) $(GLOSS_LIBS)

clean:
rm -f $(ALL_TARGETS) $(ALL_OBJ) $(ALL_DEP)

ifneq ($(MAKECMDGOALS),clean)
-include $(ALL_DEP)
endif
53 changes: 29 additions & 24 deletions Matrix.c
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
#include "Matrix.h"
#include <math.h>

__attribute__((const))
Matrix makeMatrixZero() {

return (Matrix) {
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0
};
return (Matrix) {{
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
}};
}

__attribute__((const))
Matrix makeMatrixIdentity() {

return (Matrix) {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
};
return (Matrix) {{
{1, 0, 0, 0},
{0, 1, 0, 0},
{0, 0, 1, 0},
{0, 0, 0, 1}
}};
}

__attribute__((const))
Matrix makeMatrixTranslation(const Vector v) {

return (Matrix) {
1, 0, 0, v.x,
0, 1, 0, v.y,
0, 0, 1, v.z,
0, 0, 0, 1
};
return (Matrix) {{
{1, 0, 0, v.x},
{0, 1, 0, v.y},
{0, 0, 1, v.z},
{0, 0, 0, 1},
}};
}

__attribute__((const))
Matrix makeMatrixAxisAngle(const Vector axis, const float angle) {

float length = vLength(axis);
if(length < 0.0005){

Expand All @@ -59,16 +62,17 @@ Matrix makeMatrixAxisAngle(const Vector axis, const float angle) {
return matrix;
}

__attribute__((const))
bool mEqual(const Matrix a, const Matrix b) {

for (int i=0; i<4; i++)
for (int j=0; j<4; j++)
if (a.values[i][j] + vEpsilon < b.values[i][j] || b.values[i][j] + vEpsilon < a.values[i][j])
return false;

return true;
}

__attribute__((const))
Matrix mMul(const Matrix a, const Matrix b) {

Matrix matrix = makeMatrixZero();
Expand All @@ -81,6 +85,7 @@ Matrix mMul(const Matrix a, const Matrix b) {
return matrix;
}

__attribute__((const))
Vector mvMul(const Matrix matrix, const Vector vector) {

Vector newVector = mvMulDir(matrix, vector);
Expand All @@ -94,6 +99,7 @@ Vector mvMul(const Matrix matrix, const Vector vector) {
return newVector;
}

__attribute__((const))
Vector mvMulDir(const Matrix matrix, const Vector vector) {

Vector newVector = makeVector(0, 0, 0);
Expand All @@ -109,11 +115,13 @@ Vector mvMulDir(const Matrix matrix, const Vector vector) {
return newVector;
}

__attribute__((const))
Ray mrMul(const Matrix matrix, const Ray ray) {

return makeRay(mvMul(matrix, ray.origin), vNormalized(mvMulDir(matrix, ray.direction)));
}

__attribute__((const))
Matrix mInversed(const Matrix matrix) {
float* m = (float*)&matrix.values[0][0];
Matrix returnValue;
Expand Down Expand Up @@ -289,6 +297,3 @@ Matrix mInversed(const Matrix matrix) {

return returnValue;
}



16 changes: 13 additions & 3 deletions Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,30 @@ typedef struct {
float values[4][4];
} Matrix;

Matrix makeMatrixZero();
Matrix makeMatrixIdentity();
__attribute__((const))
Matrix makeMatrixZero(void);
__attribute__((const))
Matrix makeMatrixIdentity(void);
__attribute__((const))
Matrix makeMatrixTranslation(const Vector v);
__attribute__((const))
Matrix makeMatrixAxisAngle(const Vector axis, const float angle);

__attribute__((const))
bool mEqual(const Matrix a, const Matrix b);

__attribute__((const))
Matrix mMul(const Matrix a, const Matrix b);

__attribute__((const))
Vector mvMul (const Matrix Matrix, const Vector Vector);
__attribute__((const))
Vector mvMulDir(const Matrix Matrix, const Vector Vector);

__attribute__((const))
Ray mrMul(const Matrix matrix, const Ray ray);

Matrix mInversed();
__attribute__((const))
Matrix mInversed(const Matrix);

#endif // MATRIX_H
5 changes: 3 additions & 2 deletions Scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "Matrix.h"
#include "Color.h"
#include "Intersection.h"
#include "PhotonEndpoint.h"
#include "PhotonEndPoint.h"
#include "PhotonEndPointContainer.h"
#include "PhotonContainer.h"
#include "pi.h"
Expand Down Expand Up @@ -256,7 +256,8 @@ void buildCornellBox(Scene *scene) {



void buildSpherePhotonSpawnTest(Scene *scene) {
__attribute__((unused))
static void buildSpherePhotonSpawnTest(Scene *scene) {

// Camera
scene->cameraOrientation = makeMatrixTranslation(makeVector(0, 0, 3.8));
Expand Down
2 changes: 1 addition & 1 deletion Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef struct {
} Scene;


Scene makeScene();
Scene makeScene(void);

Color sceneTraceRayAtPixel(const Scene *scene, const int currentPixel, const int width, const int height, const int numCameraRayBounces);
void sceneGeneratePhotons(Scene *scene, const int lightRayBounces, const int numPhotonsPerLightSource);
Expand Down
2 changes: 1 addition & 1 deletion SceneObjectBox.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "randf.h"
#include <math.h>

const SceneObjectVTable sceneObjectBoxVTable = (SceneObjectVTable) {
const SceneObjectVTable sceneObjectBoxVTable = {
&sceneObjectBoxIntersectRay,
&sceneObjectBoxEmitPhotons
};
Expand Down
2 changes: 1 addition & 1 deletion SceneObjectPlane.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "SceneObjectPlane.h"

const SceneObjectVTable sceneObjectPlaneVTable = (SceneObjectVTable) {
const SceneObjectVTable sceneObjectPlaneVTable = {
&sceneObjectPlaneIntersectRay,
&sceneObjectPlaneEmitPhotons
};
Expand Down
2 changes: 1 addition & 1 deletion SceneObjectSphere.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "pi.h"
#include <stdio.h>

const SceneObjectVTable sceneObjectSphereVTable = (SceneObjectVTable) {
const SceneObjectVTable sceneObjectSphereVTable = {
&sceneObjectSphereIntersectRay,
&sceneObjectSphereEmitPhotons
};
Expand Down
2 changes: 1 addition & 1 deletion SceneObjectUnitPlane.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "randf.h"
#include <math.h>

const SceneObjectVTable sceneObjectUnitPlaneVTable = (SceneObjectVTable) {
const SceneObjectVTable sceneObjectUnitPlaneVTable = {
&sceneObjectUnitPlaneIntersectRay,
&sceneObjectUnitPlaneEmitPhotons
};
Expand Down
2 changes: 1 addition & 1 deletion Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ typedef struct {
} Vector;

Vector makeVector(const float x, const float y, const float z);
Vector makeVectorOrigo();
Vector makeVectorOrigo(void);

bool vEqual(const Vector a, const Vector b);

Expand Down
4 changes: 2 additions & 2 deletions randf.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _randf_
#define _randf_

float randf();
float randf(void);

#endif
#endif