00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #if defined(_MSC_VER)
00026 #pragma warning(disable:4305) // from const double to float
00027 #endif
00028
00029
00030 #include "Teddy/SpaceGame/ShipCamera.h"
00031 #include "Teddy/SpaceGame/Ship.h"
00032 #include "Teddy/Models/Mesh.h"
00033 using namespace Teddy::Models;
00034
00035
00036 namespace Teddy {
00037 namespace SpaceGame {
00038
00039
00046 ShipCamera::ShipCamera( Ship *ship, Scene *scene, Mesh *cabin_mesh )
00047 :Camera( ship->getName(), scene )
00048 {
00049 this->ship = ship;
00050 this->cabin = cabin_mesh;
00051 this->range = 0;
00052 front();
00053 }
00054
00055
00062 void ShipCamera::projectScene( Projection *p ){
00063 unsigned long tmp_options;
00064
00065 if( range == 0 ){
00066 tmp_options = ship->getOptions();
00067 ship->disableOptions( MI_VISIBLE );
00068 Camera::projectScene( p );
00069 ship->setOptions( tmp_options );
00070 }else{
00071 Camera::projectScene( p );
00072 }
00073 }
00074
00075
00077 void ShipCamera::tick(){
00078 setPosition( ship->getPosition() );
00079 v[0] = ship->v[0];
00080 v[1] = ship->v[1];
00081 v[2] = ship->v[2];
00082 v[3] = ship->v[3];
00083 heading( degs(heading_v) );
00084 pitch ( degs(pitch_v ) );
00085 roll ( degs(roll_v ) );
00086 foward( -range );
00087 }
00088
00089
00091 void ShipCamera::front(){
00092 setHeading( 0 );
00093 setPitch ( 0 );
00094 setRoll ( 0 );
00095 setTitle ( "Front View" );
00096 }
00097
00098
00100 void ShipCamera::left(){
00101 setHeading( M_HALF_PI );
00102 setPitch ( 0 );
00103 setRoll ( 0 );
00104 setTitle ( "Left View" );
00105 }
00106
00107
00109 void ShipCamera::right(){
00110 setHeading( -M_HALF_PI );
00111 setPitch ( 0 );
00112 setRoll ( 0 );
00113 setTitle ( "Right View" );
00114 }
00115
00116
00118 void ShipCamera::rear(){
00119 setHeading( M_PI );
00120 setPitch ( 0 );
00121 setRoll ( 0 );
00122 setTitle ( "Rear View" );
00123 }
00124
00125
00127 void ShipCamera::top(){
00128 setHeading( 0 );
00129 setPitch ( M_HALF_PI );
00130 setRoll ( 0 );
00131 setTitle ( "Top View" );
00132 }
00133
00134
00136 void ShipCamera::bottom(){
00137 setHeading( 0 );
00138 setPitch ( -M_HALF_PI );
00139 setRoll ( 0 );
00140 setTitle ( "Bottom View" );
00141 }
00142
00143
00148 void ShipCamera::setCabin( Mesh *cabin_mesh ){
00149 this->cabin = cabin_mesh;
00150 }
00151
00152
00154 void ShipCamera::setDistance( float distance ){
00155 this->range = distance;
00156 }
00157
00158
00160 void ShipCamera::setHeading( float heading ){
00161 this->heading_v = heading;
00162 }
00163
00164
00166 void ShipCamera::setPitch( float pitch ){
00167 this->pitch_v = pitch;
00168 }
00169
00170
00172 void ShipCamera::setRoll( float roll ){
00173 this->roll_v = roll;
00174 }
00175
00176
00178 float ShipCamera::getDistance(){
00179 return this->range;
00180 }
00181
00182
00183 float ShipCamera::getHeading(){
00184 return this->heading_v;
00185 }
00186
00187
00188 float ShipCamera::getPitch(){
00189 return this->pitch_v;
00190 }
00191
00192
00193 float ShipCamera::getRoll(){
00194 return this->roll_v;
00195 }
00196
00197
00198 void ShipCamera::setShip( Ship *target ){
00199 this->ship = target;
00200 }
00201
00202
00203 Ship *ShipCamera::getShip(){
00204 return this->ship;
00205 }
00206
00207
00208 Scene *ShipCamera::getScene(){
00209 return this->scene;
00210 }
00211
00212
00213 Mesh *ShipCamera::getMesh(){
00214 return this->cabin;
00215 }
00216
00217
00218 };
00219 };
00220