-
Notifications
You must be signed in to change notification settings - Fork 2
How to manually control bones
damu edited this page Jan 3, 2017
·
6 revisions
Bones of animated models can be controlled manually. This can for example be used to let a character look into a certain direction or into the camera or whatever.
Example: controlling the flaps of an airplane.
// typically in a header:
// keep a pointer to the node of the bone(s) (only the left flap is shown in
// this example)
Urho3D::Node* node_flap_l;
Urho3D::Node* node_plane; // keep a pointer to the node with the whole model
float flaps=0; // the angle of the flaps
...
// typically in a constructor
node_plane=scene_->CreateChild("plane");
AnimatedModel* plane=node_plane->CreateComponent<AnimatedModel>();
plane->SetModel(cache->GetResource<Model>("plane/plane.mdl"));
node_flap_l=node_plane->GetChild("flap.L",true); // the bone is called flap.L
// if you are using animations you may want to disable them for the
// manually controlled bones:
plane->GetSkeleton()->GetBone("flap.L")->animated_=false;
...
// in an update function:
if(input->GetKeyDown(KEY_F)) // the flap angle is changed with the F and R keys
flaps+=timeStep*20;
if(input->GetKeyDown(KEY_R))
flaps-=timeStep*20;
flaps=Clamp(flaps,0.0,60.0); // keep the flap angle between 0 and 60
// you could set the rotation directly or reset it and rotate to set a
// specific angle:
node_flap_l->SetRotation(Quaternion()); // reset the rotation
node_flap_l->Yaw(flaps); // yaw the bone
Modify me