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

pandatool/src/flt/fltLightSourceDefinition.cxx

Go to the documentation of this file.
00001 // Filename: fltLightSourceDefinition.cxx
00002 // Created by:  drose (26Aug00)
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 "fltLightSourceDefinition.h"
00020 #include "fltRecordReader.h"
00021 #include "fltRecordWriter.h"
00022 
00023 TypeHandle FltLightSourceDefinition::_type_handle;
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: FltLightSourceDefinition::Constructor
00027 //       Access: Public
00028 //  Description:
00029 ////////////////////////////////////////////////////////////////////
00030 FltLightSourceDefinition::
00031 FltLightSourceDefinition(FltHeader *header) : FltRecord(header) {
00032   _light_index = 0;
00033   _ambient.set(0.0, 0.0, 0.0, 1.0);
00034   _diffuse.set(1.0, 1.0, 1.0, 1.0);
00035   _specular.set(0.0, 0.0, 0.0, 1.0);
00036   _light_type = LT_infinite;
00037   _exponential_dropoff = 1.0;
00038   _cutoff_angle = 180.0;
00039   _yaw = 0.0;
00040   _pitch = 0.0;
00041   _constant_coefficient = 0.0;
00042   _linear_coefficient = 0.0;
00043   _quadratic_coefficient = 1.0;
00044   _modeling_light = false;
00045 }
00046 
00047 ////////////////////////////////////////////////////////////////////
00048 //     Function: FltLightSourceDefinition::extract_record
00049 //       Access: Protected, Virtual
00050 //  Description: Fills in the information in this record based on the
00051 //               information given in the indicated datagram, whose
00052 //               opcode has already been read.  Returns true on
00053 //               success, false if the datagram is invalid.
00054 ////////////////////////////////////////////////////////////////////
00055 bool FltLightSourceDefinition::
00056 extract_record(FltRecordReader &reader) {
00057   if (!FltRecord::extract_record(reader)) {
00058     return false;
00059   }
00060 
00061   nassertr(reader.get_opcode() == FO_light_definition, false);
00062   DatagramIterator &iterator = reader.get_iterator();
00063 
00064   _light_index = iterator.get_be_int32();
00065   iterator.skip_bytes(2*4);
00066   _light_name = iterator.get_fixed_string(20);
00067   iterator.skip_bytes(4);
00068   _ambient[0] = iterator.get_be_float32();
00069   _ambient[1] = iterator.get_be_float32();
00070   _ambient[2] = iterator.get_be_float32();
00071   _ambient[3] = iterator.get_be_float32();
00072   _diffuse[0] = iterator.get_be_float32();
00073   _diffuse[1] = iterator.get_be_float32();
00074   _diffuse[2] = iterator.get_be_float32();
00075   _diffuse[3] = iterator.get_be_float32();
00076   _specular[0] = iterator.get_be_float32();
00077   _specular[1] = iterator.get_be_float32();
00078   _specular[2] = iterator.get_be_float32();
00079   _specular[3] = iterator.get_be_float32();
00080   _light_type = (LightType)iterator.get_be_int32();
00081   iterator.skip_bytes(4*10);
00082   _exponential_dropoff = iterator.get_be_float32();
00083   _cutoff_angle = iterator.get_be_float32();
00084   _yaw = iterator.get_be_float32();
00085   _pitch = iterator.get_be_float32();
00086   _constant_coefficient = iterator.get_be_float32();
00087   _linear_coefficient = iterator.get_be_float32();
00088   _quadratic_coefficient = iterator.get_be_float32();
00089   _modeling_light = (iterator.get_be_int32() != 0);
00090   iterator.skip_bytes(4*19);
00091 
00092   check_remaining_size(iterator);
00093   return true;
00094 }
00095 
00096 ////////////////////////////////////////////////////////////////////
00097 //     Function: FltLightSourceDefinition::build_record
00098 //       Access: Protected, Virtual
00099 //  Description: Fills up the current record on the FltRecordWriter with
00100 //               data for this record, but does not advance the
00101 //               writer.  Returns true on success, false if there is
00102 //               some error.
00103 ////////////////////////////////////////////////////////////////////
00104 bool FltLightSourceDefinition::
00105 build_record(FltRecordWriter &writer) const {
00106   if (!FltRecord::build_record(writer)) {
00107     return false;
00108   }
00109 
00110   writer.set_opcode(FO_light_definition);
00111   Datagram &datagram = writer.update_datagram();
00112 
00113   datagram.add_be_int32(_light_index);
00114   datagram.pad_bytes(2*4);
00115   datagram.add_fixed_string(_light_name, 20);
00116   datagram.pad_bytes(4);
00117   datagram.add_be_float32(_ambient[0]);
00118   datagram.add_be_float32(_ambient[1]);
00119   datagram.add_be_float32(_ambient[2]);
00120   datagram.add_be_float32(_ambient[3]);
00121   datagram.add_be_float32(_diffuse[0]);
00122   datagram.add_be_float32(_diffuse[1]);
00123   datagram.add_be_float32(_diffuse[2]);
00124   datagram.add_be_float32(_diffuse[3]);
00125   datagram.add_be_float32(_specular[0]);
00126   datagram.add_be_float32(_specular[1]);
00127   datagram.add_be_float32(_specular[2]);
00128   datagram.add_be_float32(_specular[3]);
00129   datagram.add_be_int32(_light_type);
00130   datagram.pad_bytes(4*10);
00131   datagram.add_be_float32(_exponential_dropoff);
00132   datagram.add_be_float32(_cutoff_angle);
00133   datagram.add_be_float32(_yaw);
00134   datagram.add_be_float32(_pitch);
00135   datagram.add_be_float32(_constant_coefficient);
00136   datagram.add_be_float32(_linear_coefficient);
00137   datagram.add_be_float32(_quadratic_coefficient);
00138   datagram.add_be_int32(_modeling_light);
00139   datagram.pad_bytes(4*19);
00140 
00141   return true;
00142 }

Generated on Fri May 2 03:19:21 2003 for Panda-Tool by doxygen1.3