Last active
December 24, 2016 18:29
-
-
Save madelinecr/f6cd572d90286e038dea7d2e6fc4554b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "camera.h" | |
#include "scene.h" | |
#include "primitives.h" | |
#include "color.h" | |
#include "bitmap.h" | |
#include <iostream> | |
#include <fstream> | |
#include <stdlib.h> | |
#include <cstring> | |
extern "C" { | |
#include "lua.h" | |
#include "lualib.h" | |
} | |
#include <luabind/luabind.hpp> | |
using namespace luabind; | |
int main(int argc, char** argv) { | |
if(argc == 2) { | |
lua_State* L = luaL_newstate(); | |
open(L); | |
module(L) [ | |
class_<Color>("Color") | |
.def(constructor<uint16_t,uint16_t,uint16_t>()) | |
.def("r", &Color::r) | |
.def("g", &Color::g) | |
.def("b", &Color::b), | |
class_<Object>("Object") | |
.def(constructor<Vec3, Color>()), | |
class_<Sphere, Object>("Sphere") | |
.def(constructor<Vec3,Color,double>()), | |
class_<light>("light") | |
.def(constructor<Vec3,double>()) | |
.def_readwrite("position", &light::pos) | |
.def_readwrite("intensity", &light::intensity), | |
class_<Vec3>("Vec3") | |
.def(constructor<double,double,double>()) | |
.def_readwrite("x", &Vec3::m_x) | |
.def_readwrite("y", &Vec3::m_y) | |
.def_readwrite("z", &Vec3::m_z), | |
class_<Camera>("Camera") | |
.def(constructor<uint16_t,uint16_t,Scene*>()) | |
.def("render", &Camera::render), | |
class_<Scene>("Scene") | |
.def(constructor<>()) | |
.def("add_object", &Scene::add_object) | |
.def("add_light", &Scene::add_light) | |
]; | |
luaL_openlibs(L); | |
if(luaL_dofile(L, argv[1])) { | |
std::cout << lua_tostring(L, -1) << std::endl; | |
} | |
std::cout << "Execution finished." << std::endl; | |
//lua_close(L); | |
} else { | |
std::cout << "raytrace" << std::endl; | |
std::cout << "Usage: raytrace scenefile.lua" << std::endl << std::endl; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC=clang++ | |
CFLAGS=-g -Wall -pedantic -O0 -std=c++11 | |
# Project configuration | |
SRCDIR=src | |
ODIR=build | |
LIBS=math render scene | |
SOURCES=math/ray.cpp math/vec3.cpp \ | |
render/bitmap.cpp \ | |
scene/camera.cpp scene/color.cpp scene/object.cpp scene/primitives.cpp \ | |
scene/scene.cpp \ | |
main.cpp | |
EXECUTABLE=raytrace | |
# Lua compilation headers | |
CFLAGS+=-I/usr/local/Cellar/lua51/5.1.5_4/include/lua-5.1/ | |
# Luabind compilation headers | |
CFLAGS+=-I/usr/local/Cellar/luabind/0.9.1_1/include | |
CFLAGS+=-I/usr/local/Cellar/boost/1.60.0_2/include | |
# Lua library for linking stage | |
#LINKFLAGS=-llua-5.1 -lluabind | |
LINKFLAGS=-L/usr/local/Cellar/lua51/5.1.5_4/lib/ | |
LINKFLAGS+=-L/usr/local/Cellar/luabind/0.9.1_1/lib/ | |
LINKFLAGS+=-L/usr/local/Cellar/boost/1.60.0_2/lib/ | |
LIBFLAGS=-llua5.1 | |
LIBFLAGS+=-lluabind | |
# Sources with .cpp replaced with .o | |
OBJECTS=$(SOURCES:.cpp=.o) | |
# Library folders with the build dir prepended | |
OLIBDIR=$(addprefix $(ODIR)/, $(LIBS)) | |
all: build $(addprefix $(ODIR)/, $(OBJECTS)) $(EXECUTABLE) | |
debug: CFLAGS += -DDEBUG | |
debug: all | |
$(EXECUTABLE): $(addprefix $(ODIR)/, $(OBJECTS)) | |
$(CC) $(LINKFLAGS) $(addprefix $(ODIR)/, $(OBJECTS)) -o $@ $(LIBFLAGS) | |
$(addprefix $(ODIR)/, %.o): $(SRCDIR)/%.cpp | |
$(CC) $(addprefix -I$(SRCDIR)/, $(LIBS)) $(CFLAGS) -c $^ -o $@ | |
build: | |
mkdir $(ODIR) | |
mkdir $(OLIBDIR) | |
.PHONY: clean | |
clean: | |
rm -r $(ODIR) | |
rm $(EXECUTABLE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment