00001 // Filename: actorNode.cxx 00002 // Created by: charles (07Aug00) 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 "actorNode.h" 00020 #include "config_physics.h" 00021 #include "physicsObject.h" 00022 00023 #include "transformState.h" 00024 00025 TypeHandle ActorNode::_type_handle; 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Function : ActorNode 00029 // Access : public 00030 // Description : Constructor 00031 //////////////////////////////////////////////////////////////////// 00032 ActorNode:: 00033 ActorNode(const string &name) : 00034 PhysicalNode(name) { 00035 add_physical(new Physical(1, true)); 00036 _mass_center = get_physical(0)->get_phys_body(); 00037 _mass_center->set_active(true); 00038 _ok_to_callback = true; 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function : ActorNode 00043 // Access : public 00044 // Description : Copy Constructor. 00045 //////////////////////////////////////////////////////////////////// 00046 ActorNode:: 00047 ActorNode(const ActorNode ©) : 00048 PhysicalNode(copy) { 00049 _ok_to_callback = true; 00050 _mass_center = get_physical(0)->get_phys_body(); 00051 } 00052 00053 //////////////////////////////////////////////////////////////////// 00054 // Function : ~ActorNode 00055 // Access : public 00056 // Description : destructor 00057 //////////////////////////////////////////////////////////////////// 00058 ActorNode:: 00059 ~ActorNode(void) { 00060 } 00061 00062 //////////////////////////////////////////////////////////////////// 00063 // Function : update_transform 00064 // Access : public 00065 // Description : this sets the transform generated by the contained 00066 // Physical, moving the node and subsequent geometry. 00067 //////////////////////////////////////////////////////////////////// 00068 void ActorNode:: 00069 update_transform(void) { 00070 LMatrix4f lcs = _mass_center->get_lcs(); 00071 00072 // lock the callback so that this doesn't call transform_changed. 00073 _ok_to_callback = false; 00074 set_transform(TransformState::make_mat(lcs)); 00075 _ok_to_callback = true; 00076 } 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function : transform_changed 00080 // Access : private, virtual 00081 // Description : node hook. This function handles outside 00082 // (non-physics) actions on the actor 00083 // and updates the internal representation of the node. 00084 //////////////////////////////////////////////////////////////////// 00085 void ActorNode:: 00086 transform_changed() { 00087 // this callback could be triggered by update_transform, BAD. 00088 if (_ok_to_callback == false) 00089 return; 00090 00091 // get the transform 00092 CPT(TransformState) transform = get_transform(); 00093 00094 // extract the position 00095 00096 LPoint3f pos; 00097 transform->get_mat().get_row3(pos,3); 00098 00099 // extract the orientation 00100 if (_mass_center->get_oriented() == true) { 00101 LOrientationf orientation(transform->get_mat()); 00102 _mass_center->set_orientation(orientation); 00103 } 00104 00105 // apply 00106 _mass_center->set_position(pos); 00107 }