From bf91fff5a2a8f13fd3b20562ec21dcbfd1a96db6 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 9 Aug 2014 21:23:11 -0700 Subject: [PATCH] More compiler fixups --- src/lightPoint.cc | 3 ++- src/object.cc | 2 +- src/reader_yaml.cc | 3 +++ src/scene.cc | 7 +++---- src/writer_png.cc | 27 +++++++++++++++++---------- src/yaml/cameraParser.cc | 37 ++++++++++++++++++------------------- src/yaml/cameraParser.hh | 2 +- src/yaml/objectParser.cc | 29 ++++++++++++++++++----------- src/yaml/sceneParser.cc | 4 ++-- src/yaml/vectorParser.cc | 16 ++++++---------- src/yaml/vectorParser.hh | 15 ++++++++------- 11 files changed, 79 insertions(+), 66 deletions(-) diff --git a/src/lightPoint.cc b/src/lightPoint.cc index dd52a3c..2a1021a 100644 --- a/src/lightPoint.cc +++ b/src/lightPoint.cc @@ -6,6 +6,7 @@ #include "lightPoint.hh" +using charles::basics::Color; using charles::basics::Vector4; @@ -19,7 +20,7 @@ PointLight::PointLight(const Vector4& origin, { } -Vector4 +Vector4& PointLight::GetOrigin() { return mOrigin; diff --git a/src/object.cc b/src/object.cc index 3537d49..c3f6bce 100644 --- a/src/object.cc +++ b/src/object.cc @@ -11,7 +11,7 @@ #include "object.hh" -#include "material.h" +#include "material.hh" #include "basics/basics.hh" diff --git a/src/reader_yaml.cc b/src/reader_yaml.cc index 4df4f32..a7924f8 100644 --- a/src/reader_yaml.cc +++ b/src/reader_yaml.cc @@ -58,6 +58,7 @@ private: }; #endif +namespace charles { ssize_t YAMLReader::read_file(const std::string& filename) @@ -152,3 +153,5 @@ error: yaml_parser_delete(&parser); return success; } + +} /* namespace charles */ \ No newline at end of file diff --git a/src/scene.cc b/src/scene.cc index 49d1aea..a48ec14 100644 --- a/src/scene.cc +++ b/src/scene.cc @@ -12,7 +12,6 @@ #include "scene.hh" -#include "basics.h" #include "light.hh" #include "log.hh" #include "object.hh" @@ -39,7 +38,7 @@ Scene::Scene() mCamera(new PerspectiveCamera()), mMaxDepth(5), mMinWeight(1e-6), - mAmbient(), + mAmbient(Color(1, 1, 1), 0.2), mObjects(), mLights(), mStats(), @@ -285,7 +284,7 @@ Scene::TraceRay(const Ray &ray, Ray shadowRay; for (PointLight *l : mLights) { - lightDirection = (l->GetOrigin() - intersection).normalize(); + lightDirection = basics::Normalized(l->GetOrigin() - intersection); ldotn = lightDirection.Dot(normal); /* @@ -319,7 +318,7 @@ Scene::TraceRay(const Ray &ray, /* * Compute basic Lambert diffuse shading for this object. */ - outColor += shapeColor * ( ambientLevel * mAmbient.compute_color_contribution() + outColor += shapeColor * ( ambientLevel * mAmbient.Contribution() + diffuseLevel * ldotn); } diff --git a/src/writer_png.cc b/src/writer_png.cc index 3001159..6a04187 100644 --- a/src/writer_png.cc +++ b/src/writer_png.cc @@ -9,18 +9,24 @@ #include #include -#include "scene.h" +#include "scene.hh" #include "writer_png.h" +#include "basics/basics.hh" extern "C" { #include } +using charles::basics::Color; + + static void png_user_error(png_structp png, png_const_charp msg); static void png_user_warning(png_structp png, png_const_charp msg); +namespace charles { + /* * PNGWriter::write_scene -- * @@ -29,7 +35,7 @@ static void png_user_warning(png_structp png, png_const_charp msg); int PNGWriter::write_scene(const Scene &scene, const std::string &filename) { - if (!scene.is_rendered()) { + if (!scene.IsRendered()) { return -1; } @@ -62,7 +68,7 @@ PNGWriter::write_scene(const Scene &scene, const std::string &filename) * - No compression */ png_set_IHDR(png, png_info, - scene.get_width(), scene.get_height(), + scene.GetWidth(), scene.GetHeight(), 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, @@ -75,21 +81,20 @@ PNGWriter::write_scene(const Scene &scene, const std::string &filename) png_write_info(png, png_info); // Write it! - const Color *pixels = scene.get_pixels(); + const Color* pixels = scene.GetPixels(); png_byte *row = NULL; int nbytes = 0; - for (int y = 0; y < scene.get_height(); y++) { - row = new png_byte[scene.get_width() * 3]; + for (UInt y = 0; y < scene.GetHeight(); y++) { + row = new png_byte[scene.GetWidth() * 3]; if (row == NULL) { // TODO: DANGER! WILL ROBINSON! } - for (int x = 0; x < scene.get_width(); x++) { - Color c = pixels[y * scene.get_width() + x]; + for (UInt x = 0; x < scene.GetWidth(); x++) { + Color c = pixels[y * scene.GetWidth() + x]; row[x*3+0] = 0xff * c.red; row[x*3+1] = 0xff * c.green; row[x*3+2] = 0xff * c.blue; nbytes += 3; - } png_write_row(png, row); delete[] row; @@ -103,6 +108,8 @@ PNGWriter::write_scene(const Scene &scene, const std::string &filename) return nbytes; } +} /* namespace charles */ + #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-parameter" @@ -130,4 +137,4 @@ png_user_warning(png_structp png, png_const_charp msg) { } -#pragma clang diagnostic pop +#pragma clang diagnostic pop \ No newline at end of file diff --git a/src/yaml/cameraParser.cc b/src/yaml/cameraParser.cc index 34e8328..2db4cdc 100644 --- a/src/yaml/cameraParser.cc +++ b/src/yaml/cameraParser.cc @@ -10,6 +10,9 @@ #include "yaml/vectorParser.hh" +using charles::basics::Vector4; + + namespace charles { namespace yaml { @@ -87,13 +90,13 @@ CameraParser::HandleDirectionEvent(yaml_event_t& event) return; } - auto onDone = [this](Vector3 origin) { - mCamera->set_direction(origin); + auto onDone = [this](Vector4 direction) { + mCamera->SetDirection(direction); mSection = NoSection; 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; } - auto onDone = [this](Vector3 lookAt) { + auto onDone = [this](Vector4 lookAt) { mCamera->LookAt(lookAt); mSection = NoSection; 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; } - auto onDone = [this](Vector3 origin) { + auto onDone = [this](Vector4 origin) { mCamera->SetOrigin(origin); mSection = NoSection; 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; } - auto onDone = [this](Vector3 right) { + auto onDone = [this](Vector4 right) { mCamera->SetRight(right); mSection = NoSection; 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); if (value == "perspective") { if (mType == TypeOrthographic) { - Camera *newCamera = new PerspectiveCamera(*mCamera); - delete mCamera; - mCamera = newCamera; - GetScene().SetCamera(newCamera); + mCamera.reset(new PerspectiveCamera(*mCamera)); + GetScene().SetCamera(mCamera); } } else if (value == "orthographic") { if (mType == TypePerspective) { - Camera *newCamera = new OrthographicCamera(*mCamera); - delete mCamera; - mCamera = newCamera; - GetScene().SetCamera(newCamera); + mCamera.reset(new OrthographicCamera(*mCamera)); + GetScene().SetCamera(mCamera); } } else { @@ -198,13 +197,13 @@ CameraParser::HandleUpEvent(yaml_event_t& event) return; } - auto onDone = [this](Vector3 origin) { + auto onDone = [this](Vector4 origin) { mCamera->SetUp(origin); mSection = NoSection; SetShouldExpectKey(true); }; - GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone)); + GetParsers().push(new Vector4Parser(GetScene(), GetParsers(), onDone)); } } /* namespace yaml */ diff --git a/src/yaml/cameraParser.hh b/src/yaml/cameraParser.hh index 2578da0..13223ff 100644 --- a/src/yaml/cameraParser.hh +++ b/src/yaml/cameraParser.hh @@ -48,7 +48,7 @@ private: void HandleTypeEvent(yaml_event_t& event); void HandleUpEvent(yaml_event_t& event); - Camera *mCamera; + Camera::Ptr mCamera; Section mSection; Type mType; }; diff --git a/src/yaml/objectParser.cc b/src/yaml/objectParser.cc index eba3e6e..614a9d5 100644 --- a/src/yaml/objectParser.cc +++ b/src/yaml/objectParser.cc @@ -10,8 +10,8 @@ #include #include -#include "material.h" -#include "object.h" +#include "material.hh" +#include "object.hh" #include "objectBox.hh" #include "objectPlane.hh" #include "objectSphere.hh" @@ -19,6 +19,10 @@ #include "yaml/vectorParser.hh" +using charles::basics::Color; +using charles::basics::Vector4; + + namespace charles { namespace yaml { @@ -41,7 +45,7 @@ ObjectParser::ObjectParser(Scene& scene, } else { assert(false); } - GetScene().add_shape(mObject); + GetScene().AddObject(mObject); } @@ -169,13 +173,16 @@ ObjectParser::HandleOriginEvent(yaml_event_t& event) 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); mSection = NoSection; 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; } - auto onDone = [this](Vector3 near) { + auto onDone = [this](Vector4 near) { std::dynamic_pointer_cast(mObject)->SetNear(near); mSection = NoSection; 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; } - auto onDone = [this](Vector3 far) { + auto onDone = [this](Vector4 far) { std::dynamic_pointer_cast(mObject)->SetFar(far); mSection = NoSection; 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; } - auto onDone = [this](Vector3 normal) { + auto onDone = [this](Vector4 normal) { std::dynamic_pointer_cast(mObject)->SetNormal(normal); mSection = NoSection; SetShouldExpectKey(true); }; - GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone)); + GetParsers().push(new Vector4Parser(GetScene(), GetParsers(), onDone)); } diff --git a/src/yaml/sceneParser.cc b/src/yaml/sceneParser.cc index 6b99230..e206cc6 100644 --- a/src/yaml/sceneParser.cc +++ b/src/yaml/sceneParser.cc @@ -96,8 +96,8 @@ SceneParser::HandleDimensionsEvent(yaml_event_t& event) } Scene& sc = GetScene(); - sc.set_width(dimensions.at(0)); - sc.set_height(dimensions.at(1)); + sc.SetWidth(dimensions.at(0)); + sc.SetHeight(dimensions.at(1)); mSection = NoSection; SetShouldExpectKey(true); diff --git a/src/yaml/vectorParser.cc b/src/yaml/vectorParser.cc index 3a33577..3283fdf 100644 --- a/src/yaml/vectorParser.cc +++ b/src/yaml/vectorParser.cc @@ -8,10 +8,14 @@ #include "yaml/vectorParser.hh" +using charles::basics::Color; +using charles::basics::Vector4; + + namespace charles { namespace yaml { -Vector3Parser::Vector3Parser(Scene& scene, +Vector4Parser::Vector4Parser(Scene& scene, ParserStack& parsers, CallbackFunction onDone) : ScalarSequenceParser(scene, parsers) @@ -21,16 +25,12 @@ Vector3Parser::Vector3Parser(Scene& scene, assert(seq.size() != 3); return; } - onDone(Vector3(seq[0], seq[1], seq[2])); + onDone(Vector4(seq[0], seq[1], seq[2])); }; SetCallback(onSeqDone); } -Vector3Parser::~Vector3Parser() -{ } - - ColorParser::ColorParser(Scene& scene, ParserStack& parsers, CallbackFunction onDone) @@ -51,9 +51,5 @@ ColorParser::ColorParser(Scene& scene, SetCallback(onSeqDone); } - -ColorParser::~ColorParser() -{ } - } /* namespace yaml */ } /* namespace charles */ diff --git a/src/yaml/vectorParser.hh b/src/yaml/vectorParser.hh index 4e5374e..8c237b8 100644 --- a/src/yaml/vectorParser.hh +++ b/src/yaml/vectorParser.hh @@ -14,6 +14,7 @@ #include #include "parsers.hh" +#include "basics/basics.hh" namespace charles { @@ -83,20 +84,20 @@ private: }; -struct Vector3Parser - : ScalarSequenceParser +struct Vector4Parser + : ScalarSequenceParser { - typedef std::function CallbackFunction; + typedef std::function CallbackFunction; - Vector3Parser(Scene& scene, ParserStack& parsers, CallbackFunction onDone); - ~Vector3Parser(); + Vector4Parser(Scene& scene, ParserStack& parsers, CallbackFunction onDone); + ~Vector4Parser(); }; struct ColorParser - : ScalarSequenceParser + : ScalarSequenceParser { - typedef std::function CallbackFunction; + typedef std::function CallbackFunction; ColorParser(Scene& scene, ParserStack& parsers, CallbackFunction onDone); ~ColorParser();