/** @brief 行列更新 * @param 親のmeshScene行列 * @param 親のmeshWorld行列 */ void nxMesh::UpdateMatrices(nxMatrix4 &parentMeshScene, nxMatrix4 &parentMeshWorld) { /* MeshScene = MeshLocal x ParentMeshScene */ nxMatrix4 meshScene; nxMatrix4MulMatrix4(meshScene, GetLocalMatrix(), parentMeshScene); SetMeshSceneMatrix(meshScene); /* MeshWorld = MeshLocal x ParentMeshWorld */ nxMatrix4 meshWorld; nxMatrix4MulMatrix4(meshWorld, GetLocalMatrix(), parentMeshWorld); SetMeshWorldMatrix(meshWorld); /* MeshView */ nxMatrix4 meshView; nxScene *scene = nxManager::GetCurrentScene(); nxCamera *camera = scene->GetCameraManager().GetCurrentCamera(); nxMatrix4MulMatrix4( meshView, meshWorld, camera->GetWorldViewMatrix()); SetMeshViewMatrix(meshView); }
void Transform::CalculateWordlMatrix() { if( parent ) { SetWorldMatrix( parent->GetWordlMatrix() * GetLocalMatrix() ); }else { mWorldMatrix = GetLocalMatrix(); } }
void cNode3D::UpdateMatrix(bool abSetChildrenUpdated) { cMatrixf mtxTransform = GetLocalMatrix(); //Save the translation and set it to 0 so that only the rotation is altered. cVector3f vPos = mtxTransform.GetTranslation(); mtxTransform.SetTranslation(cVector3f(0,0,0)); //Log("Startpos: %s",vPos.ToString().c_str()); //Log("World pos: %s\n",GetWorldMatrix().GetTranslation().ToString().c_str()); //The animation rotation is applied before the local. mtxTransform = cMath::MatrixMul(mtxTransform,m_mtxRotation); //Skip scale for now. //mtxTransform = cMath::MatrixMul(cMath::MatrixScale(mvScale), mtxTransform); mtxTransform.SetTranslation(vPos + mvTranslation); SetMatrix(mtxTransform,abSetChildrenUpdated); //Log("World pos: %s\n",GetWorldMatrix().GetTranslation().ToString().c_str()); //Reset values m_mtxRotation = cMatrixf::Identity; mvScale = cVector3f(1,1,1); mvTranslation = cVector3f(0,0,0); }
void Transformable::UpdateModelMatrix() { glm::mat4 parentMatrix = glm::mat4(1.0f); if (Base::GetParent() != 0) { parentMatrix = Base::GetParent()->GetModelMatrix(); } m_modelMatrix = parentMatrix * GetLocalMatrix(); }
void Camera::UpdateModelMatrix() { Base::UpdateModelMatrix(); /* glm::mat4& modelMatrix = Base::GetModelMatrix(); glm::vec3 modelPosition(modelMatrix[3][0], modelMatrix[3][1], modelMatrix[3][2]); modelMatrix = glm::rotate(modelMatrix,GetRotation().y, glm::vec3(0, 1, 0)); glm::vec4 modelLookAtVector = modelMatrix * glm::vec4(m_lookAtVector, 1.0f); glm::vec3 lookAt = glm::vec3(modelLookAtVector.x, modelLookAtVector.y, modelLookAtVector.z); m_viewMatrix = glm::lookAt( modelPosition, // position of the camera in world space lookAt, // look-at vector in world space m_upVector); // up vector in local space */ //m_viewMatrix = glm::translate(m_viewMatrix,glm::vec3(Base::GetPosition().x, Base::GetPosition().y, Base::GetPosition().z)); //m_viewMatrix = glm::translate(glm::mat4(1.0f),glm::vec3(-Base::GetPosition().x, -Base::GetPosition().y, -Base::GetPosition().z)); //m_viewMatrix = glm::rotate(m_viewMatrix, Base::GetRotation().y, glm::vec3(0.0f, -1.0f, 0.0f)); // ------------------------------------------ // Version 1 working (kind of) //CHANGE: COMMENT START //m_viewMatrix = glm::translate(glm::mat4(1.0f),glm::vec3(-Base::GetPosition().x, -Base::GetPosition().y, -Base::GetPosition().z)); //m_viewMatrix = glm::rotate(m_viewMatrix, Base::GetRotation().y, glm::vec3(0.0f, -1.0f, 0.0f)); //glm::mat4 dummy = GetLocalMatrix(); //glm::vec3 position = glm::vec3(dummy[3][0], dummy[3][1], dummy[3][2]); //dummy[3][0] = 0.0f; //dummy[3][1] = 0.0f; //dummy[3][2] = 0.0f; //m_viewMatrix = glm::translate(glm::mat4(1.0f),glm::vec3(-position.x, -position.y, -position.z)); //m_viewMatrix = m_viewMatrix * dummy; //CHANGE: COMMENT END m_viewMatrix = glm::inverse(GetLocalMatrix()); // CHANGE m_projectionMatrix = glm::perspective<glm::float_t>( m_fieldOfView, // horizontal Field of View in degrees (float) m_ViewportWidth / m_ViewportHeight, // aspect ratio m_nearPlane, m_farPlane); }
glm::mat4 Transform::GetComputedMatrix() { glm::mat4 World = GetLocalMatrix(); Transform *par = parent; while ( par ) { World = parent->GetLocalMatrix() * World; par = par->Parent(); } return World; }
cMatrixf cPhysicsBodyNewton::GetInertiaMatrix() { float fIxx, fIyy, fIzz, fMass; NewtonBodyGetMassMatrix(m_pNewtonBody, &fMass, &fIxx, &fIyy, &fIzz); cMatrixf mtxRot = GetLocalMatrix().GetRotation(); cMatrixf mtxTransRot = mtxRot.GetTranspose(); cMatrixf mtxI( fIxx, 0, 0, 0, 0, fIyy, 0, 0, 0, 0, fIzz, 0, 0, 0, 0, 1); return cMath::MatrixMul(cMath::MatrixMul(mtxRot, mtxI), mtxTransRot); }
void cPhysicsBodyNewton::AddForceAtPosition(const cVector3f &a_vForce, const cVector3f &a_vPos) { m_vTotalForce += a_vForce; cVector3f vLocalPos = a_vPos - GetLocalPosition(); cVector3f vMassCentre = GetMassCentre(); if (vMassCentre != cVector3f(0,0,0)) { vMassCentre = cMath::MatrixMul(GetLocalMatrix().GetRotation(), vMassCentre); vLocalPos -= vMassCentre; } cVector3f vTorque = cMath::Vector3Cross(vLocalPos, a_vPos); m_vTotalTorque += vTorque; SetEnabled(true); }
void cNode3D::UpdateMatrix(bool a_bSetChildrenUpdated) { cMatrixf mtxTransform = GetLocalMatrix(); cVector3f vPos = mtxTransform.GetTranslation(); mtxTransform.SetTranslation(cVector3f(0,0,0)); mtxTransform = cMath::MatrixMul(mtxTransform, m_mtxRotation); mtxTransform.SetTranslation(vPos + m_vTranslation); SetMatrix(mtxTransform, a_bSetChildrenUpdated); m_mtxRotation = cMatrixf::Identity; m_vScale = cVector3f(1,1,1); m_vTranslation = cVector3f(0); }
void cPhysicsBodyNewton::AddForceAtPosition(const cVector3f &avForce, const cVector3f &avPos) { mvTotalForce += avForce; cVector3f vLocalPos = avPos - GetLocalPosition(); cVector3f vMassCentre = GetMassCentre(); if(vMassCentre != cVector3f(0,0,0)) { vMassCentre = cMath::MatrixMul(GetLocalMatrix().GetRotation(),vMassCentre); vLocalPos -= vMassCentre; } cVector3f vTorque = cMath::Vector3Cross(vLocalPos, avForce); mvTotalTorque += vTorque; SetEnabled(true); //Log("Added force %s\n",avForce.ToString().c_str()); }
void Transform::PostMultiply( const glm::mat4 &m ) { SetLocalMatrix( GetLocalMatrix() * m ); }
void Transform::PreMultiply( const glm::mat4 &m ) { SetLocalMatrix( m * GetLocalMatrix() ); }
void Transform::Rotate( float angle, glm::vec3 axis ) { SetLocalMatrix( glm::rotate( angle, axis ) * GetLocalMatrix() ); }
void Transform::Rotate( float angle, float x, float y, float z ) { SetLocalMatrix( glm::rotate( angle, x, y, z ) * GetLocalMatrix() ); }