#include "common.h" #include "Camera.h" namespace CHCDemo { Camera::Camera() { mWidth = 100; mHeight = 100; mFovy = 90.0f * M_PI/180.0f; } Camera::Camera(int width, int height, float fieldOfView) { mWidth = width; mHeight = height; mFovy = fieldOfView * M_PI/180.0f; } void Camera::Precompute() { mDirection.Normalize(); Vector3 side = CrossProd(Vector3(0,1,0), mDirection); mUp = Normalize(CrossProd(side, mDirection)); mRight = Normalize(CrossProd(mDirection, mUp)); float k = tan(mFovy/2); mUp *= k; mRight *= k*mWidth/mHeight; } void Camera::SetPosition(const Vector3 &pos) { mPosition = pos; Precompute(); } void Camera::SetDirection(const Vector3 &dir) { mDirection = dir; Precompute(); } void Camera::LookInBox(const AxisAlignedBox3 &box) { mDirection = Vector3(0,0,1); mPosition = box.Center(); Precompute(); } void Camera::LookAtBox(const AxisAlignedBox3 &box) { mDirection = box.Max() - box.Min(); mPosition = box.Min() - mDirection; Precompute(); } }