include/vamos/body/Gl_Car.h

Go to the documentation of this file.
00001 //  Gl_Car.h - a car that handles graphics, sound and input devices.
00002 //
00003 //  Copyright (C) 2001--2002 Sam Varner
00004 //
00005 //  This file is part of Vamos Automotive Simulator.
00006 //
00007 //  This program is free software; you can redistribute it and/or modify
00008 //  it under the terms of the GNU General Public License as published by
00009 //  the Free Software Foundation; either version 2 of the License, or
00010 //  (at your option) any later version.
00011 //
00012 //  This program is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU General Public License
00018 //  along with this program; if not, write to the Free Software
00019 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021 #ifndef _GL_CAR_H_
00022 #define _GL_CAR_H_
00023 
00024 #include <vamos/body/Car.h>
00025 #include <vamos/geometry/Sample.h>
00026 
00027 #include <GL/glu.h>
00028 
00029 #include "model.h"
00030 #include "font.h"
00031 #include "sound.h"
00032 #include "settings.h"
00033 #include "globals.h"
00034 
00035 #include <string>
00036 #include <vector>
00037 
00038 namespace Vamos_Body
00039 {
00040   class Dashboard;
00041 
00042   //* An exception thrown when a sound file can't be found.
00043   class Missing_Sound_File
00044   {
00045         // The requested file.
00046         std::string m_file;
00047 
00048   public:
00049         //** Constructor
00050         Missing_Sound_File (std::string file) : m_file (file) {};
00051 
00052         // Return the requested file.
00053         std::string file () const { return m_file; }
00054   };
00055 
00056 
00057 
00058   //* Information about rearview mirrors.
00059   class Rear_View_Mirror
00060   {
00061         const Vamos_Geometry::Three_Vector m_position;
00062         const double m_width;
00063         const double m_height;
00064         const double m_direction;
00065         const double m_field;
00066         const double m_near_plane;
00067         const double m_far_plane;
00068         Vamos_Geometry::Gl_Texture_Image* mp_mask;
00069 
00070         struct Rectangle
00071         {
00072           Rectangle () : x (0), y (0), width (1), height (1) {}; 
00073           int x;
00074           int y;
00075           int width;
00076           int height;
00077           double aspect () const { return double (width) / height; }
00078         };
00079 
00080         Rectangle m_viewport;
00081 
00082         int to_pixels (double range, double factor, double coordinate)
00083         { return int (0.5 * range * (1.0 - factor * coordinate)); }
00084 
00085         void set_viewport (int window_width, int window_height, 
00086                                            const Vamos_Geometry::Three_Vector& driver_position,
00087                                            double driver_field_of_view);
00088         void activate_viewport ();
00089         void transform_view () const;
00090         void draw_mask_shape ();
00091         unsigned char* make_stencil_buffer ();
00092         void set_stencil (int window_width, int window_height);
00093 
00094   public:
00095         Rear_View_Mirror (const Vamos_Geometry::Three_Vector& position,
00096                                           double width, double height,
00097                                           double direction, double field,
00098                                           double near_plane, double far_plane,
00099                                           std::string mask_file);
00100         ~Rear_View_Mirror ();
00101 
00102         void make_mask (int window_width, int window_height, 
00103                                         const Vamos_Geometry::Three_Vector& driver_position,
00104                                         double driver_field_of_view);
00105         void set_view ();
00106 
00107         double get_direction () const { return m_direction; }
00108         Vamos_Geometry::Three_Vector get_center () const;
00109   };
00110 
00111   //* A car that handles graphics, sound and input devices.
00112   class Gl_Car : public Car
00113   {
00114         double m_throttle_volume_factor;
00115         double m_engine_speed_volume_factor;
00116 
00117         // The engine sound.
00118         Vamos_Geometry::Sample* mp_engine_sample;
00119           
00120           int real_engine_sample;
00121           int tire_source[4];
00122 
00123         // The 3D car models.
00124         JOEMODEL joeinterior;
00125         JOEMODEL joeglass;
00126         JOEMODEL joeexterior;
00127         JOEMODEL joecollision;
00128         TEXTURE_HANDLE shadowtex;
00129 
00130         // The gauges and steering wheel.
00131         Dashboard* mp_dashboard;
00132 
00133         std::vector <Rear_View_Mirror*> m_mirrors;
00134 
00135         // Clipping planes.
00136         double m_near_plane;
00137         double m_far_plane;
00138 
00139         // Draw the gauges and readouts.
00140         void draw_dashboard ();
00141 
00142         // Draw detailed information.
00143         void draw_dashboard_extras ();
00144 
00145         // Perform the modelview transformations for the car.
00146         void transform_body ();
00147         
00148         int num_paintjobs;
00149 
00150   protected:
00151         // Draw the string STR on the screen at position (X, Y).  X and Y
00152         // set the position of lower-left corner of the text
00153         void draw_string (const std::string& str, double x, double y);
00154 
00155   public:
00156         //** Constructor
00157         Gl_Car (const Vamos_Geometry::Three_Vector& pos);
00158   
00159         //** Destructor
00160         virtual ~Gl_Car ();
00161         //~Gl_Car();
00162   
00163         // Define a sound for the engine.
00164         virtual void engine_sound (std::string file, 
00165                                                            double volume, 
00166                                                            double throttle_volume_factor, 
00167                                                            double engine_speed_volume_factor,
00168                                                            double pitch);
00169 
00170         // Set the 3D models.
00171         virtual void 
00172         exterior_model (std::string file, double scale,
00173                                         const Vamos_Geometry::Three_Vector& translation,
00174                                         const Vamos_Geometry::Three_Vector& rotation);
00175         virtual void 
00176         interior_model (std::string file, double scale,
00177                                         const Vamos_Geometry::Three_Vector& translation,
00178                                         const Vamos_Geometry::Three_Vector& rotation);
00179 
00180         void set_perspective (double aspect);
00181 
00182         void set_view (const Vamos_Geometry::Three_Vector& position,
00183                                    double field_of_view,
00184                                    double near_plane, double far_plane,
00185                                    double pan_angle);
00186 
00187         void add_rear_view (const Vamos_Geometry::Three_Vector& position,
00188                                                 double width, double height,
00189                                                 double direction, double field,
00190                                                 double near_plane, double far_plane,
00191                                                 std::string mask_file);
00192 
00193         // Set the dashboard.
00194         void dashboard (Dashboard* dash);
00195 
00196         // Render the car according to its current position and
00197         // orientation.
00198         void draw (bool transform) {draw(transform, 1.0);}
00199         void draw (bool transform, float opacity);
00200         
00201         int GetSoundSource();
00202         int GetTireSoundSource(int i);
00203         
00204         void draw_interior ();
00205         void draw_rear_view (double aspect, int index);
00206         void make_rear_view_mask (int window_width, int window_height);
00207         int get_n_mirrors () const { return m_mirrors.size (); }
00208 
00209         // Perform the transformations for the view.
00210         void view (double pan, const Vamos_Geometry::Three_Vector& view_position);
00211         void view (double pan) { view (pan, m_driver_view); }
00212 
00213         // Return the PLIB sound object for the engine.  Can't be const.
00214         Vamos_Geometry::Sample* engine_sound () { return mp_engine_sample; }
00215         
00216         TEXTURE_HANDLE * shadow_texture();
00217 
00218         // Return the sound parameters.
00219         virtual double engine_pitch ();
00220         virtual double engine_volume ();
00221 
00222         int GetNumPaintjobs() { return num_paintjobs; }
00223         void SetPaint(int pid);
00224         void SetReflectionTexture(TEXTURE_HANDLE * reftid) {joeexterior.ReflectionTextureID(reftid, 2);joeglass.ReflectionTextureID(reftid, 2);}
00225         
00226         JOEMODEL * GetCollisionModel() {return &joecollision;}
00227   };
00228 }
00229 
00230 #endif // not _GL_CAR_H_

Generated on Thu Oct 19 04:05:47 2006 by  doxygen 1.4.6