00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "actorNode.h"
00016 #include "config_physics.h"
00017 #include "physicsObject.h"
00018
00019 #include "transformState.h"
00020
00021 TypeHandle ActorNode::_type_handle;
00022
00023
00024
00025
00026
00027
00028 ActorNode::
00029 ActorNode(const string &name) :
00030 PhysicalNode(name) {
00031 _contact_vector = LVector3::zero();
00032 add_physical(new Physical(1, true));
00033 _mass_center = get_physical(0)->get_phys_body();
00034 _mass_center->set_active(true);
00035 #ifndef NDEBUG
00036 _mass_center->set_name(name);
00037 #endif
00038 _ok_to_callback = true;
00039 _transform_limit = 0.0;
00040 }
00041
00042
00043
00044
00045
00046
00047 ActorNode::
00048 ActorNode(const ActorNode ©) :
00049 PhysicalNode(copy) {
00050 _contact_vector = LVector3::zero();
00051 _ok_to_callback = true;
00052 _mass_center = get_physical(0)->get_phys_body();
00053 _transform_limit = copy._transform_limit;
00054 }
00055
00056
00057
00058
00059
00060
00061 ActorNode::
00062 ~ActorNode() {
00063 }
00064
00065
00066
00067
00068
00069
00070
00071
00072 void ActorNode::
00073 update_transform() {
00074 LMatrix4 lcs = _mass_center->get_lcs();
00075
00076
00077 _ok_to_callback = false;
00078 set_transform(TransformState::make_mat(lcs));
00079 _ok_to_callback = true;
00080 }
00081
00082
00083
00084
00085
00086
00087
00088
00089 void ActorNode::
00090 test_transform(const TransformState *ts) const {
00091 LPoint3 pos(ts->get_pos());
00092 nassertv(pos[0] < _transform_limit);
00093 nassertv(pos[0] > -_transform_limit);
00094 nassertv(pos[1] < _transform_limit);
00095 nassertv(pos[1] > -_transform_limit);
00096 nassertv(pos[2] < _transform_limit);
00097 nassertv(pos[2] > -_transform_limit);
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 void ActorNode::
00109 transform_changed() {
00110 PandaNode::transform_changed();
00111
00112
00113 if (!_ok_to_callback) {
00114 return;
00115 }
00116
00117
00118 CPT(TransformState) transform = get_transform();
00119
00120 if (_transform_limit > 0.0) {
00121 test_transform(transform);
00122 }
00123
00124
00125 if (_mass_center->get_oriented() == true) {
00126 _mass_center->set_orientation(transform->get_quat());
00127 }
00128
00129
00130 _mass_center->set_position(transform->get_pos());
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140 void ActorNode::
00141 write(ostream &out, unsigned int indent) const {
00142 #ifndef NDEBUG //[
00143 out.width(indent); out<<""; out<<"ActorNode:\n";
00144 out.width(indent+2); out<<""; out<<"_ok_to_callback "<<_ok_to_callback<<"\n";
00145 out.width(indent+2); out<<""; out<<"_mass_center\n";
00146 _mass_center->write(out, indent+4);
00147 PhysicalNode::write(out, indent+2);
00148 #endif //] NDEBUG
00149 }