Fixing up CameraParser

- Compiler errors
- Coulple name tweaks
- Headers
This commit is contained in:
Eryn Wells 2014-07-19 20:59:48 -07:00
parent 3ec5b20f16
commit e2b5ffaf6c
2 changed files with 56 additions and 12 deletions

View file

@ -3,7 +3,11 @@
* Eryn Wells <eryn@erynwells.me>
*/
#include "cameraParser.hh"
#include <cassert>
#include "camera.h"
#include "yaml/cameraParser.hh"
#include "yaml/vectorParser.hh"
namespace yaml {
@ -11,7 +15,9 @@ namespace yaml {
CameraParser::CameraParser(Scene& scene,
ParserStack& parsers)
: ScalarMappingParser(scene, parsers),
mCamera(new PerspectiveCamera())
mCamera(new PerspectiveCamera()),
mSection(NoSection),
mType(TypePerspective)
{
GetScene().SetCamera(mCamera);
}
@ -25,11 +31,11 @@ void
CameraParser::HandleKeyEvent(const std::string& key)
{
static const std::map<std::string, Section> sSections = {
{"direction": DirectionSection},
{"origin": OriginSection},
{"right": RightSection},
{"type": TypeSection},
{"up": UpSection},
{"direction", DirectionSection},
{"origin", OriginSection},
{"right", RightSection},
{"type", TypeSection},
{"up", UpSection},
};
if (sSections.count(key) > 0) {
@ -42,7 +48,7 @@ CameraParser::HandleKeyEvent(const std::string& key)
void
ObjectParser::HandleValueEvent(yaml_event_t& event)
CameraParser::HandleValueEvent(yaml_event_t& event)
{
switch (mSection) {
case DirectionSection:
@ -114,8 +120,8 @@ CameraParser::HandleRightEvent(yaml_event_t& event)
return;
}
auto onDone = [this](Vector3 origin) {
mCamera->SetRight(origin);
auto onDone = [this](Vector3 right) {
mCamera->SetRight(right);
mSection = NoSection;
SetShouldExpectKey(true);
};
@ -124,6 +130,38 @@ CameraParser::HandleRightEvent(yaml_event_t& event)
}
void
CameraParser::HandleTypeEvent(yaml_event_t& event)
{
if (event.type != YAML_SCALAR_EVENT) {
assert(event.type != YAML_SCALAR_EVENT);
return;
}
std::string value = std::string((char*)event.data.scalar.value,
event.data.scalar.length);
if (value == "perspective") {
if (mType == TypeOrthographic) {
Camera *newCamera = new PerspectiveCamera(*mCamera);
delete mCamera;
mCamera = newCamera;
GetScene().SetCamera(newCamera);
}
}
else if (value == "orthographic") {
if (mType == TypePerspective) {
Camera *newCamera = new OrthographicCamera(*mCamera);
delete mCamera;
mCamera = newCamera;
GetScene().SetCamera(newCamera);
}
}
else {
assert(false);
}
}
void
CameraParser::HandleUpEvent(yaml_event_t& event)
{

View file

@ -34,14 +34,20 @@ private:
UpSection
};
Camera *mCamera;
Section mSection;
enum Type {
TypePerspective,
TypeOrthographic
};
void HandleDirectionEvent(yaml_event_t& event);
void HandleOriginEvent(yaml_event_t& event);
void HandleRightEvent(yaml_event_t& event);
void HandleTypeEvent(yaml_event_t& event);
void HandleUpEvent(yaml_event_t& event);
Camera *mCamera;
Section mSection;
Type mType;
};
} /* namespace yaml */