source: trunk/gui/vizservers/nanovis/Camera.cpp @ 467

Last change on this file since 467 was 431, checked in by qiaow, 18 years ago

Added 2D renderer.

File size: 1.9 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 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
29Camera::~Camera(){}     
30
31void Camera::move(double loc_x, double loc_y, double loc_z)
32{
33  location = Vector3(loc_x, loc_y, loc_z);
34}
35
36void Camera::aim(double target_x, double target_y, double target_z)
37{
38  target = Vector3(target_x, target_y, target_z);
39}
40
41void Camera::rotate(double angle_x, double angle_y, double angle_z)
42{
43  angle = Vector3(angle_x, angle_y, angle_z);
44}
45
46void 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(30, (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
65void Camera::set_screen_size(int w, int h){
66  width = w; height = h;
67}
Note: See TracBrowser for help on using the repository browser.