void IObject::LookAt(XMFLOAT3 target) { XMVECTOR newX, newY, newZ, globalY; XMVECTOR targetLocation; XMFLOAT3 xAxis, yAxis, zAxis; XMFLOAT3 up = XMFLOAT3(0, 1, 0); XMVECTOR currentLocation = XMLoadFloat3(GetPosition()); globalY = XMLoadFloat3(&up); targetLocation = XMLoadFloat3(&target); newZ = targetLocation - currentLocation; newX = XMVector3Cross(globalY, newZ); newY = XMVector3Cross(newZ, newX); newX = XMVector3Normalize(newX); newY = XMVector3Normalize(newY); newZ = XMVector3Normalize(newZ); XMStoreFloat3(&xAxis, newX); XMStoreFloat3(&yAxis, newY); XMStoreFloat3(&zAxis, newZ); xAxis.y = 0.0f; yAxis.x = 0.0f; yAxis.z = 0.0f; zAxis.y = 0.0f; SetXAxis(xAxis); SetYAxis(yAxis); SetZAxis(zAxis); }
// --[ Method ]--------------------------------------------------------------- // // - Class : CMatrix // // - prototype : void RemoveRotation() // // - Purpose : Removes matrix's rotation values. // // ----------------------------------------------------------------------------- void CMatrix::RemoveRotation() { float fLengthX = XAxis().Length(); float fLengthY = YAxis().Length(); float fLengthZ = ZAxis().Length(); SetXAxis(CVector3(fLengthX, 0.0f, 0.0f)); SetYAxis(CVector3(0.0f, fLengthY, 0.0f)); SetZAxis(CVector3(0.0f, 0.0f, fLengthZ)); }
// --[ Method ]--------------------------------------------------------------- // // - Class : CMatrix // // - prototype : void RemoveScale() // // - Purpose : Removes matrix's scale values. // // ----------------------------------------------------------------------------- void CMatrix::RemoveScale() { CVector3 xAxis = XAxis(); CVector3 yAxis = YAxis(); CVector3 zAxis = ZAxis(); xAxis.Normalize(); yAxis.Normalize(); zAxis.Normalize(); SetXAxis(xAxis); SetYAxis(yAxis); SetZAxis(zAxis); }
void CMinotaur::AdjustRotation() { if (m_vPath.size() > 0) { XMFLOAT3 up = XMFLOAT3(0, 1, 0); XMVECTOR newX, newY, newZ, globalY; globalY = XMLoadFloat3(&up); XMVECTOR targetLocation; if (m_nCurrentNodeOnPath != -1) targetLocation = XMLoadFloat3(&m_vPath[m_nCurrentNodeOnPath]); else targetLocation = XMLoadFloat3(m_pPlayer->GetPosition()); XMVECTOR currentLocation = XMLoadFloat3(GetPosition()); newZ = targetLocation - currentLocation; newX = XMVector3Cross(globalY, newZ); newY = XMVector3Cross(newZ, newX); newX = XMVector3Normalize(newX); newY = XMVector3Normalize(newY); newZ = XMVector3Normalize(newZ); XMFLOAT3 xAxis, yAxis, zAxis; XMStoreFloat3(&xAxis, newX); XMStoreFloat3(&yAxis, newY); XMStoreFloat3(&zAxis, newZ); xAxis.y = 0.0f; yAxis.x = 0.0f; yAxis.z = 0.0f; zAxis.y = 0.0f; SetXAxis(xAxis); SetYAxis(yAxis); SetZAxis(zAxis); } }
/***************************************************************** * AdjustRotation() Rotates the skeleton. * * Ins: IAgentState<CSkeleton>* * * Outs: None * * Returns: void * * Mod. Date: 08/20/2015 * Mod. Initials: NS *****************************************************************/ void CSkeleton::AdjustRotation() { XMFLOAT3 up = XMFLOAT3(0, 1, 0); XMVECTOR newX, newY, newZ, globalY; globalY = XMLoadFloat3(&up); XMVECTOR targetLocation; if (m_nCurrentNodeOnPath != -1 && !m_vPath.empty()) targetLocation = XMLoadFloat3(&m_vPath[m_nCurrentNodeOnPath]); else targetLocation = XMLoadFloat3(m_pPlayer->GetPosition()); if (/*m_ipCurrentState == eBlockState ||*/ m_ipCurrentState != FOLLOW) targetLocation = XMLoadFloat3(m_pPlayer->GetPosition()); XMVECTOR currentLocation = XMLoadFloat3(GetPosition()); newZ = targetLocation - currentLocation; newX = XMVector3Cross(globalY, newZ); newY = XMVector3Cross(newZ, newX); newX = XMVector3Normalize(newX); newY = XMVector3Normalize(newY); newZ = XMVector3Normalize(newZ); XMFLOAT3 xAxis, yAxis, zAxis; XMStoreFloat3(&xAxis, newX); XMStoreFloat3(&yAxis, newY); XMStoreFloat3(&zAxis, newZ); xAxis.y = 0.0f; yAxis.x = 0.0f; yAxis.z = 0.0f; zAxis.y = 0.0f; SetXAxis(xAxis); SetYAxis(yAxis); SetZAxis(zAxis); }