Panda3D

fltLightSourceDefinition.cxx

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