More compiler fixups

This commit is contained in:
Eryn Wells 2014-08-09 21:23:11 -07:00
parent 43c8bd95c6
commit bf91fff5a2
11 changed files with 79 additions and 66 deletions

View file

@ -6,6 +6,7 @@
#include "lightPoint.hh" #include "lightPoint.hh"
using charles::basics::Color;
using charles::basics::Vector4; using charles::basics::Vector4;
@ -19,7 +20,7 @@ PointLight::PointLight(const Vector4& origin,
{ } { }
Vector4 Vector4&
PointLight::GetOrigin() PointLight::GetOrigin()
{ {
return mOrigin; return mOrigin;

View file

@ -11,7 +11,7 @@
#include "object.hh" #include "object.hh"
#include "material.h" #include "material.hh"
#include "basics/basics.hh" #include "basics/basics.hh"

View file

@ -58,6 +58,7 @@ private:
}; };
#endif #endif
namespace charles {
ssize_t ssize_t
YAMLReader::read_file(const std::string& filename) YAMLReader::read_file(const std::string& filename)
@ -152,3 +153,5 @@ error:
yaml_parser_delete(&parser); yaml_parser_delete(&parser);
return success; return success;
} }
} /* namespace charles */

View file

@ -12,7 +12,6 @@
#include "scene.hh" #include "scene.hh"
#include "basics.h"
#include "light.hh" #include "light.hh"
#include "log.hh" #include "log.hh"
#include "object.hh" #include "object.hh"
@ -39,7 +38,7 @@ Scene::Scene()
mCamera(new PerspectiveCamera()), mCamera(new PerspectiveCamera()),
mMaxDepth(5), mMaxDepth(5),
mMinWeight(1e-6), mMinWeight(1e-6),
mAmbient(), mAmbient(Color(1, 1, 1), 0.2),
mObjects(), mObjects(),
mLights(), mLights(),
mStats(), mStats(),
@ -285,7 +284,7 @@ Scene::TraceRay(const Ray &ray,
Ray shadowRay; Ray shadowRay;
for (PointLight *l : mLights) { for (PointLight *l : mLights) {
lightDirection = (l->GetOrigin() - intersection).normalize(); lightDirection = basics::Normalized(l->GetOrigin() - intersection);
ldotn = lightDirection.Dot(normal); ldotn = lightDirection.Dot(normal);
/* /*
@ -319,7 +318,7 @@ Scene::TraceRay(const Ray &ray,
/* /*
* Compute basic Lambert diffuse shading for this object. * Compute basic Lambert diffuse shading for this object.
*/ */
outColor += shapeColor * ( ambientLevel * mAmbient.compute_color_contribution() outColor += shapeColor * ( ambientLevel * mAmbient.Contribution()
+ diffuseLevel * ldotn); + diffuseLevel * ldotn);
} }

View file

@ -9,18 +9,24 @@
#include <cstdlib> #include <cstdlib>
#include <string> #include <string>
#include "scene.h" #include "scene.hh"
#include "writer_png.h" #include "writer_png.h"
#include "basics/basics.hh"
extern "C" { extern "C" {
#include <png.h> #include <png.h>
} }
using charles::basics::Color;
static void png_user_error(png_structp png, png_const_charp msg); static void png_user_error(png_structp png, png_const_charp msg);
static void png_user_warning(png_structp png, png_const_charp msg); static void png_user_warning(png_structp png, png_const_charp msg);
namespace charles {
/* /*
* PNGWriter::write_scene -- * PNGWriter::write_scene --
* *
@ -29,7 +35,7 @@ static void png_user_warning(png_structp png, png_const_charp msg);
int int
PNGWriter::write_scene(const Scene &scene, const std::string &filename) PNGWriter::write_scene(const Scene &scene, const std::string &filename)
{ {
if (!scene.is_rendered()) { if (!scene.IsRendered()) {
return -1; return -1;
} }
@ -62,7 +68,7 @@ PNGWriter::write_scene(const Scene &scene, const std::string &filename)
* - No compression * - No compression
*/ */
png_set_IHDR(png, png_info, png_set_IHDR(png, png_info,
scene.get_width(), scene.get_height(), scene.GetWidth(), scene.GetHeight(),
8, PNG_COLOR_TYPE_RGB, 8, PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_COMPRESSION_TYPE_DEFAULT,
@ -75,21 +81,20 @@ PNGWriter::write_scene(const Scene &scene, const std::string &filename)
png_write_info(png, png_info); png_write_info(png, png_info);
// Write it! // Write it!
const Color *pixels = scene.get_pixels(); const Color* pixels = scene.GetPixels();
png_byte *row = NULL; png_byte *row = NULL;
int nbytes = 0; int nbytes = 0;
for (int y = 0; y < scene.get_height(); y++) { for (UInt y = 0; y < scene.GetHeight(); y++) {
row = new png_byte[scene.get_width() * 3]; row = new png_byte[scene.GetWidth() * 3];
if (row == NULL) { if (row == NULL) {
// TODO: DANGER! WILL ROBINSON! // TODO: DANGER! WILL ROBINSON!
} }
for (int x = 0; x < scene.get_width(); x++) { for (UInt x = 0; x < scene.GetWidth(); x++) {
Color c = pixels[y * scene.get_width() + x]; Color c = pixels[y * scene.GetWidth() + x];
row[x*3+0] = 0xff * c.red; row[x*3+0] = 0xff * c.red;
row[x*3+1] = 0xff * c.green; row[x*3+1] = 0xff * c.green;
row[x*3+2] = 0xff * c.blue; row[x*3+2] = 0xff * c.blue;
nbytes += 3; nbytes += 3;
} }
png_write_row(png, row); png_write_row(png, row);
delete[] row; delete[] row;
@ -103,6 +108,8 @@ PNGWriter::write_scene(const Scene &scene, const std::string &filename)
return nbytes; return nbytes;
} }
} /* namespace charles */
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter" #pragma clang diagnostic ignored "-Wunused-parameter"

View file

@ -10,6 +10,9 @@
#include "yaml/vectorParser.hh" #include "yaml/vectorParser.hh"
using charles::basics::Vector4;
namespace charles { namespace charles {
namespace yaml { namespace yaml {
@ -87,13 +90,13 @@ CameraParser::HandleDirectionEvent(yaml_event_t& event)
return; return;
} }
auto onDone = [this](Vector3 origin) { auto onDone = [this](Vector4 direction) {
mCamera->set_direction(origin); mCamera->SetDirection(direction);
mSection = NoSection; mSection = NoSection;
SetShouldExpectKey(true); SetShouldExpectKey(true);
}; };
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone)); GetParsers().push(new Vector4Parser(GetScene(), GetParsers(), onDone));
} }
@ -106,13 +109,13 @@ CameraParser::HandleLookAtEvent(yaml_event_t& event)
return; return;
} }
auto onDone = [this](Vector3 lookAt) { auto onDone = [this](Vector4 lookAt) {
mCamera->LookAt(lookAt); mCamera->LookAt(lookAt);
mSection = NoSection; mSection = NoSection;
SetShouldExpectKey(true); SetShouldExpectKey(true);
}; };
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone)); GetParsers().push(new Vector4Parser(GetScene(), GetParsers(), onDone));
} }
@ -125,13 +128,13 @@ CameraParser::HandleOriginEvent(yaml_event_t& event)
return; return;
} }
auto onDone = [this](Vector3 origin) { auto onDone = [this](Vector4 origin) {
mCamera->SetOrigin(origin); mCamera->SetOrigin(origin);
mSection = NoSection; mSection = NoSection;
SetShouldExpectKey(true); SetShouldExpectKey(true);
}; };
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone)); GetParsers().push(new Vector4Parser(GetScene(), GetParsers(), onDone));
} }
@ -144,13 +147,13 @@ CameraParser::HandleRightEvent(yaml_event_t& event)
return; return;
} }
auto onDone = [this](Vector3 right) { auto onDone = [this](Vector4 right) {
mCamera->SetRight(right); mCamera->SetRight(right);
mSection = NoSection; mSection = NoSection;
SetShouldExpectKey(true); SetShouldExpectKey(true);
}; };
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone)); GetParsers().push(new Vector4Parser(GetScene(), GetParsers(), onDone));
} }
@ -166,18 +169,14 @@ CameraParser::HandleTypeEvent(yaml_event_t& event)
event.data.scalar.length); event.data.scalar.length);
if (value == "perspective") { if (value == "perspective") {
if (mType == TypeOrthographic) { if (mType == TypeOrthographic) {
Camera *newCamera = new PerspectiveCamera(*mCamera); mCamera.reset(new PerspectiveCamera(*mCamera));
delete mCamera; GetScene().SetCamera(mCamera);
mCamera = newCamera;
GetScene().SetCamera(newCamera);
} }
} }
else if (value == "orthographic") { else if (value == "orthographic") {
if (mType == TypePerspective) { if (mType == TypePerspective) {
Camera *newCamera = new OrthographicCamera(*mCamera); mCamera.reset(new OrthographicCamera(*mCamera));
delete mCamera; GetScene().SetCamera(mCamera);
mCamera = newCamera;
GetScene().SetCamera(newCamera);
} }
} }
else { else {
@ -198,13 +197,13 @@ CameraParser::HandleUpEvent(yaml_event_t& event)
return; return;
} }
auto onDone = [this](Vector3 origin) { auto onDone = [this](Vector4 origin) {
mCamera->SetUp(origin); mCamera->SetUp(origin);
mSection = NoSection; mSection = NoSection;
SetShouldExpectKey(true); SetShouldExpectKey(true);
}; };
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone)); GetParsers().push(new Vector4Parser(GetScene(), GetParsers(), onDone));
} }
} /* namespace yaml */ } /* namespace yaml */

View file

@ -48,7 +48,7 @@ private:
void HandleTypeEvent(yaml_event_t& event); void HandleTypeEvent(yaml_event_t& event);
void HandleUpEvent(yaml_event_t& event); void HandleUpEvent(yaml_event_t& event);
Camera *mCamera; Camera::Ptr mCamera;
Section mSection; Section mSection;
Type mType; Type mType;
}; };

View file

@ -10,8 +10,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "material.h" #include "material.hh"
#include "object.h" #include "object.hh"
#include "objectBox.hh" #include "objectBox.hh"
#include "objectPlane.hh" #include "objectPlane.hh"
#include "objectSphere.hh" #include "objectSphere.hh"
@ -19,6 +19,10 @@
#include "yaml/vectorParser.hh" #include "yaml/vectorParser.hh"
using charles::basics::Color;
using charles::basics::Vector4;
namespace charles { namespace charles {
namespace yaml { namespace yaml {
@ -41,7 +45,7 @@ ObjectParser::ObjectParser(Scene& scene,
} else { } else {
assert(false); assert(false);
} }
GetScene().add_shape(mObject); GetScene().AddObject(mObject);
} }
@ -169,13 +173,16 @@ ObjectParser::HandleOriginEvent(yaml_event_t& event)
return; return;
} }
auto onDone = [this](Vector3 origin) { auto onDone = [this](Vector4 origin) {
/* TODO: Once Place() and Move() are implemented on Object, use that. */
#if 0
mObject->SetOrigin(origin); mObject->SetOrigin(origin);
mSection = NoSection; mSection = NoSection;
SetShouldExpectKey(true); SetShouldExpectKey(true);
#endif
}; };
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone)); GetParsers().push(new Vector4Parser(GetScene(), GetParsers(), onDone));
} }
@ -209,13 +216,13 @@ ObjectParser::HandleNearEvent(yaml_event_t& event)
return; return;
} }
auto onDone = [this](Vector3 near) { auto onDone = [this](Vector4 near) {
std::dynamic_pointer_cast<Box>(mObject)->SetNear(near); std::dynamic_pointer_cast<Box>(mObject)->SetNear(near);
mSection = NoSection; mSection = NoSection;
SetShouldExpectKey(true); SetShouldExpectKey(true);
}; };
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone)); GetParsers().push(new Vector4Parser(GetScene(), GetParsers(), onDone));
} }
@ -228,13 +235,13 @@ ObjectParser::HandleFarEvent(yaml_event_t& event)
return; return;
} }
auto onDone = [this](Vector3 far) { auto onDone = [this](Vector4 far) {
std::dynamic_pointer_cast<Box>(mObject)->SetFar(far); std::dynamic_pointer_cast<Box>(mObject)->SetFar(far);
mSection = NoSection; mSection = NoSection;
SetShouldExpectKey(true); SetShouldExpectKey(true);
}; };
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone)); GetParsers().push(new Vector4Parser(GetScene(), GetParsers(), onDone));
} }
@ -247,13 +254,13 @@ ObjectParser::HandleNormalEvent(yaml_event_t& event)
return; return;
} }
auto onDone = [this](Vector3 normal) { auto onDone = [this](Vector4 normal) {
std::dynamic_pointer_cast<Plane>(mObject)->SetNormal(normal); std::dynamic_pointer_cast<Plane>(mObject)->SetNormal(normal);
mSection = NoSection; mSection = NoSection;
SetShouldExpectKey(true); SetShouldExpectKey(true);
}; };
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone)); GetParsers().push(new Vector4Parser(GetScene(), GetParsers(), onDone));
} }

View file

@ -96,8 +96,8 @@ SceneParser::HandleDimensionsEvent(yaml_event_t& event)
} }
Scene& sc = GetScene(); Scene& sc = GetScene();
sc.set_width(dimensions.at(0)); sc.SetWidth(dimensions.at(0));
sc.set_height(dimensions.at(1)); sc.SetHeight(dimensions.at(1));
mSection = NoSection; mSection = NoSection;
SetShouldExpectKey(true); SetShouldExpectKey(true);

View file

@ -8,10 +8,14 @@
#include "yaml/vectorParser.hh" #include "yaml/vectorParser.hh"
using charles::basics::Color;
using charles::basics::Vector4;
namespace charles { namespace charles {
namespace yaml { namespace yaml {
Vector3Parser::Vector3Parser(Scene& scene, Vector4Parser::Vector4Parser(Scene& scene,
ParserStack& parsers, ParserStack& parsers,
CallbackFunction onDone) CallbackFunction onDone)
: ScalarSequenceParser(scene, parsers) : ScalarSequenceParser(scene, parsers)
@ -21,16 +25,12 @@ Vector3Parser::Vector3Parser(Scene& scene,
assert(seq.size() != 3); assert(seq.size() != 3);
return; return;
} }
onDone(Vector3(seq[0], seq[1], seq[2])); onDone(Vector4(seq[0], seq[1], seq[2]));
}; };
SetCallback(onSeqDone); SetCallback(onSeqDone);
} }
Vector3Parser::~Vector3Parser()
{ }
ColorParser::ColorParser(Scene& scene, ColorParser::ColorParser(Scene& scene,
ParserStack& parsers, ParserStack& parsers,
CallbackFunction onDone) CallbackFunction onDone)
@ -51,9 +51,5 @@ ColorParser::ColorParser(Scene& scene,
SetCallback(onSeqDone); SetCallback(onSeqDone);
} }
ColorParser::~ColorParser()
{ }
} /* namespace yaml */ } /* namespace yaml */
} /* namespace charles */ } /* namespace charles */

View file

@ -14,6 +14,7 @@
#include <vector> #include <vector>
#include "parsers.hh" #include "parsers.hh"
#include "basics/basics.hh"
namespace charles { namespace charles {
@ -83,20 +84,20 @@ private:
}; };
struct Vector3Parser struct Vector4Parser
: ScalarSequenceParser<double> : ScalarSequenceParser<Double>
{ {
typedef std::function<void (Vector3)> CallbackFunction; typedef std::function<void (basics::Vector4)> CallbackFunction;
Vector3Parser(Scene& scene, ParserStack& parsers, CallbackFunction onDone); Vector4Parser(Scene& scene, ParserStack& parsers, CallbackFunction onDone);
~Vector3Parser(); ~Vector4Parser();
}; };
struct ColorParser struct ColorParser
: ScalarSequenceParser<double> : ScalarSequenceParser<Double>
{ {
typedef std::function<void (Color)> CallbackFunction; typedef std::function<void (basics::Color)> CallbackFunction;
ColorParser(Scene& scene, ParserStack& parsers, CallbackFunction onDone); ColorParser(Scene& scene, ParserStack& parsers, CallbackFunction onDone);
~ColorParser(); ~ColorParser();