1 /* 2 * Shotgun Debugger 3 * Copyright 2005 Game Creation Society 4 * 5 * Programmed by Matt Sarnoff 6 * http://www.contrib.andrew.cmu.edu/~msarnoff 7 * http://www.gamecreation.org 8 * 9 * camera.h - camera class 10 * 11 * This program is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU General Public License 13 * as published by the Free Software Foundation; either version 2 14 * of the License, or (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 24 */ 25 26 #ifndef _CAMERA_H_ 27 #define _CAMERA_H_ 28 29 #include "sdb.h" 30 31 #define CAMERA_DEFAULT_HEIGHT 50.0 32 33 class Camera 34 { 35 public: Camera()36 Camera() { set(0.0, 0.0, CAMERA_DEFAULT_HEIGHT, 0.0); } setPos(float x,float y)37 void setPos(float x, float y) { pos.c[X] = x; pos.c[Y] = y; } setHeight(float h)38 void setHeight(float h) { height = h; } setRotation(float theta)39 void setRotation(float theta) { rot = theta; } set(float x,float y,float h,float th)40 void set(float x, float y, float h, float th) { setPos(x, y); setHeight(h); setRotation(th); } change(float dx,float dy,float dh,float dth)41 void change(float dx, float dy, float dh, float dth) { pos.c[X]+=dx; pos.c[Y]+=dy; height+=dh; rot+=dth; } apply()42 void apply() { glRotatef(rot, 0.0, 0.0, 1.0); gluLookAt(pos.c[X],pos.c[Y]-0,height, pos.c[X],pos.c[Y],0.0, 0.0,1.0,0.0); } applyPerspective()43 void applyPerspective() { glRotatef(rot, 0.0, 0.0, 1.0); gluLookAt(pos.c[X],pos.c[Y],0.0, pos.c[X],10000.0,0.0, 0.0,0.0,1.0); } drawCursor()44 void drawCursor() 45 { 46 glColor4f(0.0, 1.0, 0.0, 0.75); 47 glBegin(GL_LINES); 48 glVertex2f(pos.c[X]-5.0, pos.c[Y]); 49 glVertex2f(pos.c[X]+5.0, pos.c[Y]); 50 51 glVertex2f(pos.c[X], pos.c[Y]-5.0); 52 glVertex2f(pos.c[X], pos.c[Y]+5.0); 53 glEnd(); 54 } 55 Pos()56 Vector2D Pos() { return pos; } Height()57 float Height() { return height; } 58 private: 59 Vector2D pos; 60 float height; 61 float rot; 62 }; 63 64 #endif 65