Panda3D
|
00001 // Filename: fltCurve.cxx 00002 // Created by: drose (28Feb01) 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 "fltCurve.h" 00016 #include "fltRecordReader.h" 00017 #include "fltRecordWriter.h" 00018 #include "fltHeader.h" 00019 #include "fltMaterial.h" 00020 00021 TypeHandle FltCurve::_type_handle; 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Function: FltCurve::Constructor 00025 // Access: Public 00026 // Description: 00027 //////////////////////////////////////////////////////////////////// 00028 FltCurve:: 00029 FltCurve(FltHeader *header) : FltBeadID(header) { 00030 _curve_type = CT_b_spline; 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: FltCurve::extract_record 00035 // Access: Protected, Virtual 00036 // Description: Fills in the information in this bead based on the 00037 // information given in the indicated datagram, whose 00038 // opcode has already been read. Returns true on 00039 // success, false if the datagram is invalid. 00040 //////////////////////////////////////////////////////////////////// 00041 bool FltCurve:: 00042 extract_record(FltRecordReader &reader) { 00043 if (!FltBeadID::extract_record(reader)) { 00044 return false; 00045 } 00046 00047 nassertr(reader.get_opcode() == FO_curve, false); 00048 DatagramIterator &iterator = reader.get_iterator(); 00049 00050 iterator.skip_bytes(4); 00051 _curve_type = (CurveType)iterator.get_be_int32(); 00052 00053 int num_control_points = iterator.get_be_int32(); 00054 iterator.skip_bytes(8); 00055 for (int i = 0; i < num_control_points; i++) { 00056 double x = iterator.get_be_float64(); 00057 double y = iterator.get_be_float64(); 00058 double z = iterator.get_be_float64(); 00059 _control_points.push_back(LPoint3d(x, y, z)); 00060 } 00061 00062 check_remaining_size(iterator); 00063 return true; 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: FltCurve::build_record 00068 // Access: Protected, Virtual 00069 // Description: Fills up the current record on the FltRecordWriter with 00070 // data for this record, but does not advance the 00071 // writer. Returns true on success, false if there is 00072 // some error. 00073 //////////////////////////////////////////////////////////////////// 00074 bool FltCurve:: 00075 build_record(FltRecordWriter &writer) const { 00076 if (!FltBeadID::build_record(writer)) { 00077 return false; 00078 } 00079 00080 writer.set_opcode(FO_curve); 00081 Datagram &datagram = writer.update_datagram(); 00082 00083 datagram.pad_bytes(4); 00084 datagram.add_be_int32(_curve_type); 00085 datagram.add_be_int32(_control_points.size()); 00086 datagram.pad_bytes(8); 00087 00088 ControlPoints::const_iterator ci; 00089 for (ci = _control_points.begin(); ci != _control_points.end(); ++ci) { 00090 const LPoint3d &p = (*ci); 00091 datagram.add_be_float64(p[0]); 00092 datagram.add_be_float64(p[1]); 00093 datagram.add_be_float64(p[2]); 00094 } 00095 00096 return true; 00097 }