fltTransformTranslate.cxx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file fltTransformTranslate.cxx
  10. * @author drose
  11. * @date 2000-08-30
  12. */
  13. #include "fltTransformTranslate.h"
  14. #include "fltRecordReader.h"
  15. #include "fltRecordWriter.h"
  16. TypeHandle FltTransformTranslate::_type_handle;
  17. /**
  18. *
  19. */
  20. FltTransformTranslate::
  21. FltTransformTranslate(FltHeader *header) : FltTransformRecord(header) {
  22. _from.set(0.0, 0.0, 0.0);
  23. _delta.set(0.0, 0.0, 0.0);
  24. }
  25. /**
  26. * Defines the translation. The "from" point seems to be pretty much ignored.
  27. */
  28. void FltTransformTranslate::
  29. set(const LPoint3d &from, const LVector3d &delta) {
  30. _from = from;
  31. _delta = delta;
  32. recompute_matrix();
  33. }
  34. /**
  35. * Returns the reference point of the translation. This is largely
  36. * meaningless.
  37. */
  38. const LPoint3d &FltTransformTranslate::
  39. get_from() const {
  40. return _from;
  41. }
  42. /**
  43. *
  44. */
  45. const LVector3d &FltTransformTranslate::
  46. get_delta() const {
  47. return _delta;
  48. }
  49. /**
  50. *
  51. */
  52. void FltTransformTranslate::
  53. recompute_matrix() {
  54. _matrix = LMatrix4d::translate_mat(_delta);
  55. }
  56. /**
  57. * Fills in the information in this record based on the information given in
  58. * the indicated datagram, whose opcode has already been read. Returns true
  59. * on success, false if the datagram is invalid.
  60. */
  61. bool FltTransformTranslate::
  62. extract_record(FltRecordReader &reader) {
  63. if (!FltTransformRecord::extract_record(reader)) {
  64. return false;
  65. }
  66. nassertr(reader.get_opcode() == FO_translate, false);
  67. DatagramIterator &iterator = reader.get_iterator();
  68. iterator.skip_bytes(4); // Undocumented additional padding.
  69. _from[0] = iterator.get_be_float64();
  70. _from[1] = iterator.get_be_float64();
  71. _from[2] = iterator.get_be_float64();
  72. _delta[0] = iterator.get_be_float64();
  73. _delta[1] = iterator.get_be_float64();
  74. _delta[2] = iterator.get_be_float64();
  75. // iterator.skip_bytes(4); Undocumented additional padding.
  76. recompute_matrix();
  77. check_remaining_size(iterator);
  78. return true;
  79. }
  80. /**
  81. * Fills up the current record on the FltRecordWriter with data for this
  82. * record, but does not advance the writer. Returns true on success, false if
  83. * there is some error.
  84. */
  85. bool FltTransformTranslate::
  86. build_record(FltRecordWriter &writer) const {
  87. if (!FltTransformRecord::build_record(writer)) {
  88. return false;
  89. }
  90. writer.set_opcode(FO_translate);
  91. Datagram &datagram = writer.update_datagram();
  92. datagram.pad_bytes(4); // Undocumented additional padding.
  93. datagram.add_be_float64(_from[0]);
  94. datagram.add_be_float64(_from[1]);
  95. datagram.add_be_float64(_from[2]);
  96. datagram.add_be_float64(_delta[0]);
  97. datagram.add_be_float64(_delta[1]);
  98. datagram.add_be_float64(_delta[2]);
  99. // datagram.pad_bytes(4); Undocumented additional padding.
  100. return true;
  101. }