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

pandatool/src/flt/fltCurve.cxx

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

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