Add CameraParser
This commit is contained in:
parent
76a13e61de
commit
b03ad0ac2d
2 changed files with 195 additions and 0 deletions
|
@ -0,0 +1,145 @@
|
|||
/* camera_parser.cc
|
||||
* vim: set tw=80:
|
||||
* Eryn Wells <eryn@erynwells.me>
|
||||
*/
|
||||
|
||||
#include "cameraParser.hh"
|
||||
|
||||
|
||||
namespace yaml {
|
||||
|
||||
CameraParser::CameraParser(Scene& scene,
|
||||
ParserStack& parsers)
|
||||
: ScalarMappingParser(scene, parsers),
|
||||
mCamera(new PerspectiveCamera())
|
||||
{
|
||||
GetScene().SetCamera(mCamera);
|
||||
}
|
||||
|
||||
|
||||
CameraParser::~CameraParser()
|
||||
{ }
|
||||
|
||||
|
||||
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},
|
||||
};
|
||||
|
||||
if (sSections.count(key) > 0) {
|
||||
mSection = sSections.at(key);
|
||||
}
|
||||
else {
|
||||
mSection = NoSection;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ObjectParser::HandleValueEvent(yaml_event_t& event)
|
||||
{
|
||||
switch (mSection) {
|
||||
case DirectionSection:
|
||||
HandleDirectionEvent(event);
|
||||
break;
|
||||
case OriginSection:
|
||||
HandleOriginEvent(event);
|
||||
break;
|
||||
case RightSection:
|
||||
HandleRightEvent(event);
|
||||
break;
|
||||
case TypeSection:
|
||||
HandleTypeEvent(event);
|
||||
break;
|
||||
case UpSection:
|
||||
HandleUpEvent(event);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CameraParser::HandleDirectionEvent(yaml_event_t& event)
|
||||
{
|
||||
if (event.type != YAML_SEQUENCE_START_EVENT) {
|
||||
/* TODO: Clean this up. */
|
||||
assert(event.type != YAML_SEQUENCE_START_EVENT);
|
||||
return;
|
||||
}
|
||||
|
||||
auto onDone = [this](Vector3 origin) {
|
||||
mCamera->set_direction(origin);
|
||||
mSection = NoSection;
|
||||
SetShouldExpectKey(true);
|
||||
};
|
||||
|
||||
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CameraParser::HandleOriginEvent(yaml_event_t& event)
|
||||
{
|
||||
if (event.type != YAML_SEQUENCE_START_EVENT) {
|
||||
/* TODO: Clean this up. */
|
||||
assert(event.type != YAML_SEQUENCE_START_EVENT);
|
||||
return;
|
||||
}
|
||||
|
||||
auto onDone = [this](Vector3 origin) {
|
||||
mCamera->set_origin(origin);
|
||||
mSection = NoSection;
|
||||
SetShouldExpectKey(true);
|
||||
};
|
||||
|
||||
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CameraParser::HandleRightEvent(yaml_event_t& event)
|
||||
{
|
||||
if (event.type != YAML_SEQUENCE_START_EVENT) {
|
||||
/* TODO: Clean this up. */
|
||||
assert(event.type != YAML_SEQUENCE_START_EVENT);
|
||||
return;
|
||||
}
|
||||
|
||||
auto onDone = [this](Vector3 origin) {
|
||||
mCamera->SetRight(origin);
|
||||
mSection = NoSection;
|
||||
SetShouldExpectKey(true);
|
||||
};
|
||||
|
||||
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CameraParser::HandleUpEvent(yaml_event_t& event)
|
||||
{
|
||||
if (event.type != YAML_SEQUENCE_START_EVENT) {
|
||||
/* TODO: Clean this up. */
|
||||
assert(event.type != YAML_SEQUENCE_START_EVENT);
|
||||
return;
|
||||
}
|
||||
|
||||
auto onDone = [this](Vector3 origin) {
|
||||
mCamera->SetUp(origin);
|
||||
mSection = NoSection;
|
||||
SetShouldExpectKey(true);
|
||||
};
|
||||
|
||||
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone));
|
||||
}
|
||||
|
||||
} /* namespace yaml */
|
|
@ -0,0 +1,50 @@
|
|||
/* camera_parser.hh
|
||||
* vim: set tw=80:
|
||||
* Eryn Wells <eryn@erynwells.me>
|
||||
*/
|
||||
|
||||
#ifndef __YAML_CAMERAPARSER_HH__
|
||||
#define __YAML_CAMERAPARSER_HH__
|
||||
|
||||
#include "yaml/scalarMappingParser.hh"
|
||||
|
||||
|
||||
struct Camera;
|
||||
|
||||
|
||||
namespace yaml {
|
||||
|
||||
struct CameraParser
|
||||
: public ScalarMappingParser
|
||||
{
|
||||
CameraParser(Scene& scene, ParserStack& parsers);
|
||||
~CameraParser();
|
||||
|
||||
protected:
|
||||
void HandleKeyEvent(const std::string& key);
|
||||
void HandleValueEvent(yaml_event_t& event);
|
||||
|
||||
private:
|
||||
enum Section {
|
||||
NoSection,
|
||||
DirectionSection,
|
||||
OriginSection,
|
||||
RightSection,
|
||||
TypeSection,
|
||||
UpSection
|
||||
};
|
||||
|
||||
Camera *mCamera;
|
||||
Section mSection;
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
} /* namespace yaml */
|
||||
|
||||
#endif /* __YAML_CAMERAPARSER_HH__ */
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue