Game Development Reference
In-Depth Information
A vertex is transformed using this matrix as follows:
Mv ={ Rx * x + Ux * y + Fx * z , Ry * x + Uy * y + Fy * z , Rz * x + Uz * y + Fz * z }
The full code to align the object to its parent involves subtracting the
parent's pivot point from the current position for the object, then scaling
this vector by the parent's scale. This vector is rotated and transformed
using the parent's rotation matrix and location. Finally, the object's scale
is multiplied by the parent's scale.
typedef struct stVECTOR{
double x,y,z;
}VECTOR;
void CToon3DObject::AlignToParent(){
VECTOR pp;
//Store the simple position before alignment for editing
//purposes
StorePos();
if (m_parent){
//Transform position if the object has a parent:
//Note parent must have been transformed first
pp.x=(m_pos.x - m_parent->m_piv.x) *
m_parent->m_scale.x;
pp.y=(m_pos.y - m_parent->m_piv.y) *
m_parent->m_scale.y;
pp.z=(m_pos.z - m_parent->m_piv.z) *
m_parent->m_scale.z;
m_pos.x = m_parent->m_right.x * pp.x +
m_parent->m_up.x * pp.y +
m_parent->m_forward.x * pp.z + m_parent->m_pos.x;
m_pos.y = m_parent->m_right.y * pp.x +
m_parent->m_up.y * pp.y +
m_parent->m_forward.y * pp.z + m_parent->m_pos.y;
m_pos.z = m_parent->m_right.z * pp.x +
m_parent->m_up.z * pp.y +
m_parent->m_forward.z * pp.z + m_parent->m_pos.z;
//Adjust scale
m_scale.x *= m_parent->m_scale.x;
m_scale.y *= m_parent->m_scale.y;
m_scale.z *= m_parent->m_scale.z;
}
}
Search Nedrilad ::




Custom Search