1 | /*
|
---|
2 | * ----------------------------------------------------------------------
|
---|
3 | * Camera.cpp : Camera class
|
---|
4 | *
|
---|
5 | * ======================================================================
|
---|
6 | * AUTHOR: Wei Qiao <qiaow@purdue.edu>
|
---|
7 | * Purdue Rendering and Perceptualization Lab (PURPL)
|
---|
8 | *
|
---|
9 | * Copyright (c) 2004-2006 Purdue Research Foundation
|
---|
10 | *
|
---|
11 | * See the file "license.terms" for information on usage and
|
---|
12 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
---|
13 | * ======================================================================
|
---|
14 | */
|
---|
15 |
|
---|
16 | #include <stdio.h>
|
---|
17 | #include "Camera.h"
|
---|
18 |
|
---|
19 | Camera::Camera(int w, int h,
|
---|
20 | double loc_x, double loc_y, double loc_z,
|
---|
21 | double target_x, double target_y, double target_z,
|
---|
22 | int angle_x, int angle_y, int angle_z):
|
---|
23 | width(w),
|
---|
24 | height(h),
|
---|
25 | location(Vector3(loc_x, loc_y, loc_z)),
|
---|
26 | target(Vector3(target_x, target_y, target_z)),
|
---|
27 | angle(Vector3(angle_x, angle_y, angle_z)) { }
|
---|
28 |
|
---|
29 | Camera::~Camera(){}
|
---|
30 |
|
---|
31 | void Camera::move(double loc_x, double loc_y, double loc_z)
|
---|
32 | {
|
---|
33 | location = Vector3(loc_x, loc_y, loc_z);
|
---|
34 | }
|
---|
35 |
|
---|
36 | void Camera::aim(double target_x, double target_y, double target_z)
|
---|
37 | {
|
---|
38 | target = Vector3(target_x, target_y, target_z);
|
---|
39 | }
|
---|
40 |
|
---|
41 | void Camera::rotate(double angle_x, double angle_y, double angle_z)
|
---|
42 | {
|
---|
43 | angle = Vector3(angle_x, angle_y, angle_z);
|
---|
44 | }
|
---|
45 |
|
---|
46 | void Camera::activate(){
|
---|
47 | fprintf(stderr, "camera: %d, %d\n", width, height);
|
---|
48 | glViewport(0, 0, width, height);
|
---|
49 | glMatrixMode(GL_PROJECTION);
|
---|
50 | glLoadIdentity();
|
---|
51 | gluPerspective(60, (GLdouble)width/(GLdouble)height, 0.1, 50.0);
|
---|
52 |
|
---|
53 | glMatrixMode(GL_MODELVIEW);
|
---|
54 | glLoadIdentity();
|
---|
55 |
|
---|
56 | gluLookAt(location.x, location.y, location.z,
|
---|
57 | target.x, target.y, target.z,
|
---|
58 | 0., 1., 0.);
|
---|
59 |
|
---|
60 | glRotated(angle.x, 1., 0., 0.);
|
---|
61 | glRotated(angle.y, 0., 1., 0.);
|
---|
62 | glRotated(angle.z, 0., 0., 1.);
|
---|
63 | }
|
---|
64 |
|
---|
65 | void Camera::set_screen_size(int w, int h){
|
---|
66 | width = w; height = h;
|
---|
67 | }
|
---|