summaryrefslogtreecommitdiffhomepage
path: root/nGenEx/Camera.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'nGenEx/Camera.cpp')
-rw-r--r--nGenEx/Camera.cpp276
1 files changed, 138 insertions, 138 deletions
diff --git a/nGenEx/Camera.cpp b/nGenEx/Camera.cpp
index bbc72dd..9a5090f 100644
--- a/nGenEx/Camera.cpp
+++ b/nGenEx/Camera.cpp
@@ -1,15 +1,15 @@
/* Project nGenEx
- Destroyer Studios LLC
- Copyright © 1997-2004. All Rights Reserved.
+ Destroyer Studios LLC
+ Copyright © 1997-2004. All Rights Reserved.
- SUBSYSTEM: nGenEx.lib
- FILE: Camera.cpp
- AUTHOR: John DiCamillo
+ SUBSYSTEM: nGenEx.lib
+ FILE: Camera.cpp
+ AUTHOR: John DiCamillo
- OVERVIEW
- ========
- Camera Class - Position and Point of View
+ OVERVIEW
+ ========
+ Camera Class - Position and Point of View
*/
#include "MemDebug.h"
@@ -18,7 +18,7 @@
// +--------------------------------------------------------------------+
Camera::Camera(double x, double y, double z)
- : pos(x,y,z)
+: pos(x,y,z)
{ }
Camera::~Camera()
@@ -29,17 +29,17 @@ Camera::~Camera()
void
Camera::MoveTo(double x, double y, double z)
{
- pos.x = x;
- pos.y = y;
- pos.z = z;
+ pos.x = x;
+ pos.y = y;
+ pos.z = z;
}
void
Camera::MoveTo(const Point& p)
{
- pos.x = p.x;
- pos.y = p.y;
- pos.z = p.z;
+ pos.x = p.x;
+ pos.y = p.y;
+ pos.z = p.z;
}
// +--------------------------------------------------------------------+
@@ -47,17 +47,17 @@ Camera::MoveTo(const Point& p)
void
Camera::MoveBy(double dx, double dy, double dz)
{
- pos.x += dx;
- pos.y += dz;
- pos.z += dy;
+ pos.x += dx;
+ pos.y += dz;
+ pos.z += dy;
}
void
Camera::MoveBy(const Point& p)
{
- pos.x += p.x;
- pos.y += p.y;
- pos.z += p.z;
+ pos.x += p.x;
+ pos.y += p.y;
+ pos.z += p.z;
}
// +--------------------------------------------------------------------+
@@ -65,8 +65,8 @@ Camera::MoveBy(const Point& p)
void
Camera::Clone(const Camera& cam)
{
- pos = cam.pos;
- orientation = cam.orientation;
+ pos = cam.pos;
+ orientation = cam.orientation;
}
// +--------------------------------------------------------------------+
@@ -74,23 +74,23 @@ Camera::Clone(const Camera& cam)
void
Camera::LookAt(const Point& target, const Point& eye, const Point& up)
{
- Point zaxis = target - eye; zaxis.Normalize();
- Point xaxis = up.cross(zaxis); xaxis.Normalize();
- Point yaxis = zaxis.cross(xaxis); yaxis.Normalize();
+ Point zaxis = target - eye; zaxis.Normalize();
+ Point xaxis = up.cross(zaxis); xaxis.Normalize();
+ Point yaxis = zaxis.cross(xaxis); yaxis.Normalize();
- orientation(0,0) = xaxis.x;
- orientation(0,1) = xaxis.y;
- orientation(0,2) = xaxis.z;
+ orientation(0,0) = xaxis.x;
+ orientation(0,1) = xaxis.y;
+ orientation(0,2) = xaxis.z;
- orientation(1,0) = yaxis.x;
- orientation(1,1) = yaxis.y;
- orientation(1,2) = yaxis.z;
+ orientation(1,0) = yaxis.x;
+ orientation(1,1) = yaxis.y;
+ orientation(1,2) = yaxis.z;
- orientation(2,0) = zaxis.x;
- orientation(2,1) = zaxis.y;
- orientation(2,2) = zaxis.z;
+ orientation(2,0) = zaxis.x;
+ orientation(2,1) = zaxis.y;
+ orientation(2,2) = zaxis.z;
- pos = eye;
+ pos = eye;
}
// +--------------------------------------------------------------------+
@@ -98,42 +98,42 @@ Camera::LookAt(const Point& target, const Point& eye, const Point& up)
void
Camera::LookAt(const Point& target)
{
- // No navel gazing:
- if (target == Pos())
- return;
-
- Point tgt, tmp = target - Pos();
-
- // Rotate into the view orientation:
- tgt.x = (tmp * vrt());
- tgt.y = (tmp * vup());
- tgt.z = (tmp * vpn());
-
- if (tgt.z == 0) {
- Pitch(0.5);
- Yaw(0.5);
- LookAt(target);
- return;
- }
-
- double az = atan(tgt.x/tgt.z);
- double el = atan(tgt.y/tgt.z);
-
- // if target is behind, offset by 180 degrees:
- if (tgt.z < 0)
- az -= PI;
-
- Pitch(-el);
- Yaw(az);
-
- // roll to upright position:
- double deflection = vrt().y;
- while (fabs(deflection) > 0.001) {
- double theta = asin(deflection/vrt().length());
- Roll(-theta);
-
- deflection = vrt().y;
- }
+ // No navel gazing:
+ if (target == Pos())
+ return;
+
+ Point tgt, tmp = target - Pos();
+
+ // Rotate into the view orientation:
+ tgt.x = (tmp * vrt());
+ tgt.y = (tmp * vup());
+ tgt.z = (tmp * vpn());
+
+ if (tgt.z == 0) {
+ Pitch(0.5);
+ Yaw(0.5);
+ LookAt(target);
+ return;
+ }
+
+ double az = atan(tgt.x/tgt.z);
+ double el = atan(tgt.y/tgt.z);
+
+ // if target is behind, offset by 180 degrees:
+ if (tgt.z < 0)
+ az -= PI;
+
+ Pitch(-el);
+ Yaw(az);
+
+ // roll to upright position:
+ double deflection = vrt().y;
+ while (fabs(deflection) > 0.001) {
+ double theta = asin(deflection/vrt().length());
+ Roll(-theta);
+
+ deflection = vrt().y;
+ }
}
@@ -142,71 +142,71 @@ Camera::LookAt(const Point& target)
bool
Camera::Padlock(const Point& target, double alimit, double e_lo, double e_hi)
{
- // No navel gazing:
- if (target == Pos())
- return false;
-
- Point tgt, tmp = target - Pos();
-
- // Rotate into the view orientation:
- tgt.x = (tmp * vrt());
- tgt.y = (tmp * vup());
- tgt.z = (tmp * vpn());
-
- if (tgt.z == 0) {
- Yaw(0.1);
-
- tgt.x = (tmp * vrt());
- tgt.y = (tmp * vup());
- tgt.z = (tmp * vpn());
-
- if (tgt.z == 0)
- return false;
- }
-
- bool locked = true;
- double az = atan(tgt.x/tgt.z);
- double orig = az;
-
- // if target is behind, offset by 180 degrees:
- if (tgt.z < 0)
- az -= PI;
-
- while (az > PI) az -= 2*PI;
- while (az < -PI) az += 2*PI;
-
- if (alimit > 0) {
- if (az < -alimit) {
- az = -alimit;
- locked = false;
- }
- else if (az > alimit) {
- az = alimit;
- locked = false;
- }
- }
-
- Yaw(az);
-
- // Rotate into the new view orientation:
- tgt.x = (tmp * vrt());
- tgt.y = (tmp * vup());
- tgt.z = (tmp * vpn());
-
- double el = atan(tgt.y/tgt.z);
-
- if (e_lo > 0 && el < -e_lo) {
- el = -e_lo;
- locked = false;
- }
-
- else if (e_hi > 0 && el > e_hi) {
- el = e_hi;
- locked = false;
- }
-
- Pitch(-el);
-
- return locked;
+ // No navel gazing:
+ if (target == Pos())
+ return false;
+
+ Point tgt, tmp = target - Pos();
+
+ // Rotate into the view orientation:
+ tgt.x = (tmp * vrt());
+ tgt.y = (tmp * vup());
+ tgt.z = (tmp * vpn());
+
+ if (tgt.z == 0) {
+ Yaw(0.1);
+
+ tgt.x = (tmp * vrt());
+ tgt.y = (tmp * vup());
+ tgt.z = (tmp * vpn());
+
+ if (tgt.z == 0)
+ return false;
+ }
+
+ bool locked = true;
+ double az = atan(tgt.x/tgt.z);
+ double orig = az;
+
+ // if target is behind, offset by 180 degrees:
+ if (tgt.z < 0)
+ az -= PI;
+
+ while (az > PI) az -= 2*PI;
+ while (az < -PI) az += 2*PI;
+
+ if (alimit > 0) {
+ if (az < -alimit) {
+ az = -alimit;
+ locked = false;
+ }
+ else if (az > alimit) {
+ az = alimit;
+ locked = false;
+ }
+ }
+
+ Yaw(az);
+
+ // Rotate into the new view orientation:
+ tgt.x = (tmp * vrt());
+ tgt.y = (tmp * vup());
+ tgt.z = (tmp * vpn());
+
+ double el = atan(tgt.y/tgt.z);
+
+ if (e_lo > 0 && el < -e_lo) {
+ el = -e_lo;
+ locked = false;
+ }
+
+ else if (e_hi > 0 && el > e_hi) {
+ el = e_hi;
+ locked = false;
+ }
+
+ Pitch(-el);
+
+ return locked;
}