Add Camera::LookAt

This is identical to the POV-Ray look_at keyword for cameras. In fact, I stole the code almost directly from them… It's super handy for panning and tilting the camera towards a particular point, and saves me having to do dubiously accurate direction vector calculations by hand.

I still need to figure out what exactly this math is doing.
This commit is contained in:
Eryn Wells 2014-08-03 18:33:09 -07:00
parent e64b9403ac
commit 7297bc5c17
4 changed files with 52 additions and 0 deletions

View file

@ -32,6 +32,7 @@ CameraParser::HandleKeyEvent(const std::string& key)
{
static const std::map<std::string, Section> sSections = {
{"direction", DirectionSection},
{"lookAt", LookAtSection},
{"origin", OriginSection},
{"right", RightSection},
{"type", TypeSection},
@ -54,6 +55,9 @@ CameraParser::HandleValueEvent(yaml_event_t& event)
case DirectionSection:
HandleDirectionEvent(event);
break;
case LookAtSection:
HandleLookAtEvent(event);
break;
case OriginSection:
HandleOriginEvent(event);
break;
@ -92,6 +96,25 @@ CameraParser::HandleDirectionEvent(yaml_event_t& event)
}
void
CameraParser::HandleLookAtEvent(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 lookAt) {
mCamera->LookAt(lookAt);
mSection = NoSection;
SetShouldExpectKey(true);
};
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone));
}
void
CameraParser::HandleOriginEvent(yaml_event_t& event)
{

View file

@ -28,6 +28,7 @@ private:
enum Section {
NoSection,
DirectionSection,
LookAtSection,
OriginSection,
RightSection,
TypeSection,
@ -40,6 +41,7 @@ private:
};
void HandleDirectionEvent(yaml_event_t& event);
void HandleLookAtEvent(yaml_event_t& event);
void HandleOriginEvent(yaml_event_t& event);
void HandleRightEvent(yaml_event_t& event);
void HandleTypeEvent(yaml_event_t& event);