source: trunk/vizservers/nanovis/Camera.cpp @ 750

Last change on this file since 750 was 580, checked in by vrinside, 17 years ago
File size: 2.1 KB
Line 
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
19Camera::Camera(int startx, int starty, 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     startX(startx),
24     startY(starty),
25         width(w),
26         height(h),
27         location(Vector3(loc_x, loc_y, loc_z)),
28         target(Vector3(target_x, target_y, target_z)),
29         angle(Vector3(angle_x, angle_y, angle_z)) { }
30
31Camera::~Camera(){}     
32
33void Camera::move(double loc_x, double loc_y, double loc_z)
34{
35  location = Vector3(loc_x, loc_y, loc_z);
36}
37
38void Camera::aim(double target_x, double target_y, double target_z)
39{
40  target = Vector3(target_x, target_y, target_z);
41}
42
43void Camera::rotate(double angle_x, double angle_y, double angle_z)
44{
45  angle = Vector3(angle_x, angle_y, angle_z);
46}
47
48void Camera::activate(){
49  //fprintf(stderr, "camera: %d, %d\n", width, height);
50  glViewport(startX, startY, width, height);
51  glMatrixMode(GL_PROJECTION);
52  glLoadIdentity();
53  gluPerspective(30, (GLdouble)(width - startX)/(GLdouble)(height - startY), 0.1, 50.0);
54
55  glMatrixMode(GL_MODELVIEW);
56  glLoadIdentity();
57
58  gluLookAt(location.x, location.y, location.z,
59            target.x, target.y, target.z,
60            0., 1., 0.);
61
62   glRotated(angle.x, 1., 0., 0.);
63   glRotated(angle.y, 0., 1., 0.);
64   glRotated(angle.z, 0., 0., 1.);
65}
66
67void Camera::set_screen_size(int sx, int sy, int w, int h){
68  width = w; height = h;
69  startX = sx; startY = sy;
70}
Note: See TracBrowser for help on using the repository browser.