| |
5: Collecting everything we have learned so far we can write these six convenience functions for setting and getting global position, rotation and scale data:
GetGlobalPosition(obj); // Returns the global position of obj
GetGlobalRotation(obj); // Returns the global rotation of obj
GetGlobalScale(obj); // Returns the global scale of obj
SetGlobalPosition(obj, pos); // Sets the global position of obj to pos
SetGlobalRotation(obj, rot); // Sets the global rotation of obj to rot
SetGlobalScale(obj, scale); // Sets the global scale of obj to scale
GetGlobalPosition(obj)
{
return obj->GetMg()->GetV0();
}
GetGlobalRotation(obj)
{
return obj->GetMg()->GetHPB();
}
GetGlobalScale(obj)
{
var m = obj->GetMg();
return vector(vlen(m->GetV1()),
vlen(m->GetV2()),
vlen(m->GetV3()));
}
SetGlobalPosition(obj, pos)
{
var m = obj->GetMg();
m->SetV0(pos);
obj->SetMg(m);
}
SetGlobalRotation(obj, rot)
{
var m = obj->GetMg();
var pos = m->GetV0();
var scale = vector(vlen(m->GetV1()),
vlen(m->GetV2()),
vlen(m->GetV3()));
m->SetRotHPB(rot);
m->SetV0(pos);
m->SetV1(vnorm(m->GetV1()) * scale.x);
m->SetV2(vnorm(m->GetV2()) * scale.y);
m->SetV3(vnorm(m->GetV3()) * scale.z);
obj->SetMg(m);
}
SetGlobalScale(obj, scale)
{
var m = obj->GetMg();
m->SetV1(vnorm(m->GetV1()) * scale.x);
m->SetV2(vnorm(m->GetV2()) * scale.y);
m->SetV3(vnorm(m->GetV3()) * scale.z);
obj->SetMg(m);
}
|
|