Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/pgraph/camera.cxx

Go to the documentation of this file.
00001 // Filename: camera.cxx
00002 // Created by:  drose (26Feb02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "pandabase.h"
00020 #include "camera.h"
00021 #include "lens.h"
00022 #include "throw_event.h"
00023 
00024 TypeHandle Camera::_type_handle;
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: Camera::Constructor
00028 //       Access: Published
00029 //  Description:
00030 ////////////////////////////////////////////////////////////////////
00031 Camera::
00032 Camera(const string &name) :
00033   LensNode(name),
00034   _active(true),
00035   _camera_mask(DrawMask::all_on())
00036 {
00037 }
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //     Function: Camera::Copy Constructor
00041 //       Access: Protected
00042 //  Description:
00043 ////////////////////////////////////////////////////////////////////
00044 Camera::
00045 Camera(const Camera &copy) :
00046   LensNode(copy),
00047   _active(copy._active),
00048   _scene(copy._scene),
00049   _camera_mask(copy._camera_mask)
00050 {
00051 }
00052 
00053 ////////////////////////////////////////////////////////////////////
00054 //     Function: Camera::Destructor
00055 //       Access: Public, Virtual
00056 //  Description:
00057 ////////////////////////////////////////////////////////////////////
00058 Camera::
00059 ~Camera() {
00060   // We don't have to destroy the display region(s) associated with
00061   // the camera; they're responsible for themselves.  However, they
00062   // should have removed themselves before we destruct, or something
00063   // went wrong.
00064   nassertv(_display_regions.empty());
00065 }
00066 
00067 ////////////////////////////////////////////////////////////////////
00068 //     Function: Camera::make_copy
00069 //       Access: Public, Virtual
00070 //  Description: Returns a newly-allocated Node that is a shallow copy
00071 //               of this one.  It will be a different Node pointer,
00072 //               but its internal data may or may not be shared with
00073 //               that of the original Node.
00074 ////////////////////////////////////////////////////////////////////
00075 PandaNode *Camera::
00076 make_copy() const {
00077   return new Camera(*this);
00078 }
00079 
00080 ////////////////////////////////////////////////////////////////////
00081 //     Function: Camera::safe_to_flatten
00082 //       Access: Public, Virtual
00083 //  Description: Returns true if it is generally safe to flatten out
00084 //               this particular kind of Node by duplicating
00085 //               instances, false otherwise (for instance, a Camera
00086 //               cannot be safely flattened, because the Camera
00087 //               pointer itself is meaningful).
00088 ////////////////////////////////////////////////////////////////////
00089 bool Camera::
00090 safe_to_flatten() const {
00091   return false;
00092 }
00093 
00094 ////////////////////////////////////////////////////////////////////
00095 //     Function: Camera::safe_to_transform
00096 //       Access: Public, Virtual
00097 //  Description: Returns true if it is generally safe to transform
00098 //               this particular kind of Node by calling the xform()
00099 //               method, false otherwise.  For instance, it's usually
00100 //               a bad idea to attempt to xform a Character.
00101 ////////////////////////////////////////////////////////////////////
00102 bool Camera::
00103 safe_to_transform() const {
00104   return false;
00105 }
00106 
00107 ////////////////////////////////////////////////////////////////////
00108 //     Function: Camera::add_display_region
00109 //       Access: Private
00110 //  Description: Adds the indicated DisplayRegion to the set of
00111 //               DisplayRegions shared by the camera.  This is only
00112 //               intended to be called from the DisplayRegion.
00113 ////////////////////////////////////////////////////////////////////
00114 void Camera::
00115 add_display_region(DisplayRegion *display_region) {
00116   _display_regions.push_back(display_region);
00117 }
00118 
00119 ////////////////////////////////////////////////////////////////////
00120 //     Function: Camera::remove_display_region
00121 //       Access: Private
00122 //  Description: Removes the indicated DisplayRegion from the set of
00123 //               DisplayRegions shared by the camera.  This is only
00124 //               intended to be called from the DisplayRegion.
00125 ////////////////////////////////////////////////////////////////////
00126 void Camera::
00127 remove_display_region(DisplayRegion *display_region) {
00128   DisplayRegions::iterator dri =
00129     find(_display_regions.begin(), _display_regions.end(), display_region);
00130   if (dri != _display_regions.end()) {
00131     _display_regions.erase(dri);
00132   }
00133 }
00134 
00135 ////////////////////////////////////////////////////////////////////
00136 //     Function: Camera::register_with_read_factory
00137 //       Access: Public, Static
00138 //  Description: Tells the BamReader how to create objects of type
00139 //               Camera.
00140 ////////////////////////////////////////////////////////////////////
00141 void Camera::
00142 register_with_read_factory() {
00143   BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00144 }
00145 
00146 ////////////////////////////////////////////////////////////////////
00147 //     Function: Camera::write_datagram
00148 //       Access: Public, Virtual
00149 //  Description: Writes the contents of this object to the datagram
00150 //               for shipping out to a Bam file.
00151 ////////////////////////////////////////////////////////////////////
00152 void Camera::
00153 write_datagram(BamWriter *manager, Datagram &dg) {
00154   LensNode::write_datagram(manager, dg);
00155 
00156   dg.add_bool(_active);
00157   dg.add_uint32(_camera_mask.get_word());
00158 }
00159 
00160 ////////////////////////////////////////////////////////////////////
00161 //     Function: Camera::make_from_bam
00162 //       Access: Protected, Static
00163 //  Description: This function is called by the BamReader's factory
00164 //               when a new object of type Camera is encountered
00165 //               in the Bam file.  It should create the Camera
00166 //               and extract its information from the file.
00167 ////////////////////////////////////////////////////////////////////
00168 TypedWritable *Camera::
00169 make_from_bam(const FactoryParams &params) {
00170   Camera *node = new Camera("");
00171   DatagramIterator scan;
00172   BamReader *manager;
00173 
00174   parse_params(params, scan, manager);
00175   node->fillin(scan, manager);
00176 
00177   return node;
00178 }
00179 
00180 ////////////////////////////////////////////////////////////////////
00181 //     Function: Camera::fillin
00182 //       Access: Protected
00183 //  Description: This internal function is called by make_from_bam to
00184 //               read in all of the relevant data from the BamFile for
00185 //               the new Camera.
00186 ////////////////////////////////////////////////////////////////////
00187 void Camera::
00188 fillin(DatagramIterator &scan, BamReader *manager) {
00189   LensNode::fillin(scan, manager);
00190 
00191   _active = scan.get_bool();
00192   _camera_mask.set_word(scan.get_uint32());
00193 }

Generated on Fri May 2 00:41:07 2003 for Panda by doxygen1.3