Fixing up CameraParser
- Compiler errors - Coulple name tweaks - Headers
This commit is contained in:
parent
3ec5b20f16
commit
e2b5ffaf6c
2 changed files with 56 additions and 12 deletions
|
@ -3,7 +3,11 @@
|
||||||
* Eryn Wells <eryn@erynwells.me>
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cameraParser.hh"
|
#include <cassert>
|
||||||
|
|
||||||
|
#include "camera.h"
|
||||||
|
#include "yaml/cameraParser.hh"
|
||||||
|
#include "yaml/vectorParser.hh"
|
||||||
|
|
||||||
|
|
||||||
namespace yaml {
|
namespace yaml {
|
||||||
|
@ -11,7 +15,9 @@ namespace yaml {
|
||||||
CameraParser::CameraParser(Scene& scene,
|
CameraParser::CameraParser(Scene& scene,
|
||||||
ParserStack& parsers)
|
ParserStack& parsers)
|
||||||
: ScalarMappingParser(scene, parsers),
|
: ScalarMappingParser(scene, parsers),
|
||||||
mCamera(new PerspectiveCamera())
|
mCamera(new PerspectiveCamera()),
|
||||||
|
mSection(NoSection),
|
||||||
|
mType(TypePerspective)
|
||||||
{
|
{
|
||||||
GetScene().SetCamera(mCamera);
|
GetScene().SetCamera(mCamera);
|
||||||
}
|
}
|
||||||
|
@ -25,11 +31,11 @@ void
|
||||||
CameraParser::HandleKeyEvent(const std::string& key)
|
CameraParser::HandleKeyEvent(const std::string& key)
|
||||||
{
|
{
|
||||||
static const std::map<std::string, Section> sSections = {
|
static const std::map<std::string, Section> sSections = {
|
||||||
{"direction": DirectionSection},
|
{"direction", DirectionSection},
|
||||||
{"origin": OriginSection},
|
{"origin", OriginSection},
|
||||||
{"right": RightSection},
|
{"right", RightSection},
|
||||||
{"type": TypeSection},
|
{"type", TypeSection},
|
||||||
{"up": UpSection},
|
{"up", UpSection},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (sSections.count(key) > 0) {
|
if (sSections.count(key) > 0) {
|
||||||
|
@ -42,7 +48,7 @@ CameraParser::HandleKeyEvent(const std::string& key)
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ObjectParser::HandleValueEvent(yaml_event_t& event)
|
CameraParser::HandleValueEvent(yaml_event_t& event)
|
||||||
{
|
{
|
||||||
switch (mSection) {
|
switch (mSection) {
|
||||||
case DirectionSection:
|
case DirectionSection:
|
||||||
|
@ -114,8 +120,8 @@ CameraParser::HandleRightEvent(yaml_event_t& event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto onDone = [this](Vector3 origin) {
|
auto onDone = [this](Vector3 right) {
|
||||||
mCamera->SetRight(origin);
|
mCamera->SetRight(right);
|
||||||
mSection = NoSection;
|
mSection = NoSection;
|
||||||
SetShouldExpectKey(true);
|
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
|
void
|
||||||
CameraParser::HandleUpEvent(yaml_event_t& event)
|
CameraParser::HandleUpEvent(yaml_event_t& event)
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,14 +34,20 @@ private:
|
||||||
UpSection
|
UpSection
|
||||||
};
|
};
|
||||||
|
|
||||||
Camera *mCamera;
|
enum Type {
|
||||||
Section mSection;
|
TypePerspective,
|
||||||
|
TypeOrthographic
|
||||||
|
};
|
||||||
|
|
||||||
void HandleDirectionEvent(yaml_event_t& event);
|
void HandleDirectionEvent(yaml_event_t& event);
|
||||||
void HandleOriginEvent(yaml_event_t& event);
|
void HandleOriginEvent(yaml_event_t& event);
|
||||||
void HandleRightEvent(yaml_event_t& event);
|
void HandleRightEvent(yaml_event_t& event);
|
||||||
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;
|
||||||
|
Section mSection;
|
||||||
|
Type mType;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace yaml */
|
} /* namespace yaml */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue