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"
using charles::basics::Color;
using charles::basics::Vector4;
@ -19,7 +20,7 @@ PointLight::PointLight(const Vector4& origin,
{ }
Vector4
Vector4&
PointLight::GetOrigin()
{
return mOrigin;

View file

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

View file

@ -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 */

View file

@ -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);
}

View file

@ -9,18 +9,24 @@
#include <cstdlib>
#include <string>
#include "scene.h"
#include "scene.hh"
#include "writer_png.h"
#include "basics/basics.hh"
extern "C" {
#include <png.h>
}
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

View file

@ -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 */

View file

@ -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;
};

View file

@ -10,8 +10,8 @@
#include <string>
#include <vector>
#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<Box>(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<Box>(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<Plane>(mObject)->SetNormal(normal);
mSection = NoSection;
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();
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);

View file

@ -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 */

View file

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