// Filename: animChannelMatrixXfmTable.h
// Created by:  drose (20Feb99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University.  All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license.  You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////

#ifndef ANIMCHANNELMATRIXXFMTABLE_H
#define ANIMCHANNELMATRIXXFMTABLE_H

#include "pandabase.h"

#include "animChannel.h"

#include "pointerToArray.h"
#include "pta_float.h"
#include "compose_matrix.h"

////////////////////////////////////////////////////////////////////
//       Class : AnimChannelMatrixXfmTable
// Description : An animation channel that issues a matrix each frame,
//               read from a table such as might have been read from
//               an egg file.  The table actually consists of nine
//               sub-tables, each representing one component of the
//               transform: scale, rotate, translate.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_CHAN AnimChannelMatrixXfmTable : public AnimChannelMatrix {
protected:
  AnimChannelMatrixXfmTable();
  AnimChannelMatrixXfmTable(AnimGroup *parent, const AnimChannelMatrixXfmTable &copy);

PUBLISHED:
  AnimChannelMatrixXfmTable(AnimGroup *parent, const string &name);
  virtual ~AnimChannelMatrixXfmTable();
  
public:
  virtual bool has_changed(int last_frame, double last_frac, 
                           int this_frame, double this_frac);
  virtual void get_value(int frame, LMatrix4f &mat);

  virtual void get_value_no_scale_shear(int frame, LMatrix4f &value);
  virtual void get_scale(int frame, LVecBase3f &scale);
  virtual void get_hpr(int frame, LVecBase3f &hpr);
  virtual void get_quat(int frame, LQuaternionf &quat);
  virtual void get_pos(int frame, LVecBase3f &pos);
  virtual void get_shear(int frame, LVecBase3f &shear);

PUBLISHED:
  static INLINE bool is_valid_id(char table_id);

  void set_table(char table_id, const CPTA_float &table);
  INLINE CPTA_float get_table(char table_id) const;

  void clear_all_tables();
  INLINE bool has_table(char table_id) const;
  INLINE void clear_table(char table_id);

public:
  virtual void write(ostream &out, int indent_level) const;

protected:
  virtual AnimGroup *make_copy(AnimGroup *parent) const;

  INLINE static char get_table_id(int table_index);
  static int get_table_index(char table_id);
  INLINE static float get_default_value(int table_index);

  CPTA_float _tables[num_matrix_components];

public:
  static void register_with_read_factory();
  virtual void write_datagram(BamWriter* manager, Datagram &me);

  static TypedWritable *make_AnimChannelMatrixXfmTable(const FactoryParams &params);

protected:
  void fillin(DatagramIterator& scan, BamReader* manager);

public:
  virtual TypeHandle get_type() const {
    return get_class_type();
  }
  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  static TypeHandle get_class_type() {
    return _type_handle;
  }
  static void init_type() {
    AnimChannelMatrix::init_type();
    register_type(_type_handle, "AnimChannelMatrixXfmTable",
                  AnimChannelMatrix::get_class_type());
  }

private:
  static TypeHandle _type_handle;
};

#include "animChannelMatrixXfmTable.I"

#endif
