void ccGenericMesh::applyGLTransformation(const ccGLMatrix& trans) { //vertices should be handled another way! //we must take care of the triangle normals! if (m_triNormals && (!getParent() || !getParent()->isKindOf(CC_MESH))) { bool recoded = false; //if there is more triangle normals than the size of the compressed //normals array, we recompress the array instead of recompressing each normal unsigned i,numTriNormals = m_triNormals->currentSize(); if (numTriNormals>ccNormalVectors::GetNumberOfVectors()) { NormsIndexesTableType* newNorms = new NormsIndexesTableType; if (newNorms->reserve(ccNormalVectors::GetNumberOfVectors())) { for (i=0; i<ccNormalVectors::GetNumberOfVectors(); i++) { CCVector3 new_n(ccNormalVectors::GetNormal(i)); trans.applyRotation(new_n); normsType newNormIndex = ccNormalVectors::GetNormIndex(new_n.u); newNorms->addElement(newNormIndex); } m_triNormals->placeIteratorAtBegining(); for (i=0; i<numTriNormals; i++) { m_triNormals->setValue(i,newNorms->getValue(m_triNormals->getCurrentValue())); m_triNormals->forwardIterator(); } recoded=true; } newNorms->clear(); newNorms->release(); newNorms=0; } //if there is less triangle normals than the compressed normals array size //(or if there is not enough memory to instantiate the temporary array), //we recompress each normal ... if (!recoded) { //on recode direct chaque normale m_triNormals->placeIteratorAtBegining(); for (i=0; i<numTriNormals; i++) { normsType* _theNormIndex = m_triNormals->getCurrentValuePtr(); CCVector3 new_n(ccNormalVectors::GetNormal(*_theNormIndex)); trans.applyRotation(new_n.u); *_theNormIndex = ccNormalVectors::GetNormIndex(new_n.u); m_triNormals->forwardIterator(); } } } else { //TODO: process failed! } }
void ccFacet::applyGLTransformation(const ccGLMatrix &trans) { ccHObject::applyGLTransformation(trans); // move/rotate the center to its new location trans.apply(m_center); // apply the rotation to the normal of the plane equation trans.applyRotation(m_planeEquation); // compute new d-parameter from the updated values CCVector3 n(m_planeEquation); m_planeEquation[3] = n.dot(m_center); }
ccBBox ccDrawableObject::getFitBB(ccGLMatrix& trans) { //Default behavior: returns axis aligned bounding box! trans.toIdentity(); return getBB(true,false,m_currentDisplay); }
void MatrixDisplayDlg::fillDialogWith(const ccGLMatrix& mat) { m_mat = ccGLMatrixd(mat.data()); int precision = ccGui::Parameters().displayedNumPrecision; //display as 4x4 matrix maxTextEdit->setText(mat.toString(precision)); //display as rotation vector/angle { PointCoordinateType angle_rad; CCVector3 axis3D, t3D; mat.getParameters(angle_rad, axis3D, t3D); fillDialogWith(CCVector3d::fromArray(axis3D.u),angle_rad,CCVector3d::fromArray(t3D.u),precision); } }
void ccGraphicalTransformationTool::glRotate(const ccGLMatrix& rotMat) { switch(rotComboBox->currentIndex()) { case 0: //XYZ m_rotation = rotMat * m_rotation; break; case 1: //X m_rotation = rotMat.xRotation() * m_rotation; break; case 2: //Y m_rotation = rotMat.yRotation() * m_rotation; break; case 3: //Z m_rotation = rotMat.zRotation() * m_rotation; break; } updateAllGLTransformations(); }
void ccClipBox::get(ccBBox& extents, ccGLMatrix& transformation) { extents = m_box; if (isGLTransEnabled()) { transformation = m_glTrans; } else { transformation.toIdentity(); } }
//===============================================getAbsoluteGLTransformation===================================================// //由祖先到子物体,将旋转矩阵依次累加 bool ccHObject::getAbsoluteGLTransformation(ccGLMatrix& trans) const { trans.toIdentity(); bool hasGLTrans = false; //recurse among ancestors to get the absolute GL transformation const ccHObject* obj = this; while (obj){ if (obj->isGLTransEnabled()){ //是否可进行变换 trans = trans * obj->getGLTransformation(); hasGLTrans = true; } obj = obj->getParent(); } return hasGLTrans; }
ccGLMatrix ccGLMatrix::Interpolate(float coef, const ccGLMatrix& glMat1, const ccGLMatrix& glMat2) { //we compute the transformation matrix between glMat1 and glMat2 ccGLMatrix invTrans1 = glMat1.inverse(); ccGLMatrix m12 = invTrans1 * glMat2; CCVector3 axis,tr; float alpha; m12.getParameters(alpha,axis,tr); //we only have to interpolate the angle value alpha *= coef; //and the translation tr *= coef; //we build-up the resulting matrix m12.initFromParameters(alpha,axis,tr); //eventually we build-up resulting transformation return glMat1 * m12; }
void ccApplyTransformationDlg::updateAll(const ccGLMatrix& mat, bool textForm/*=true*/, bool axisAngleForm/*=true*/, bool eulerForm/*=true*/) { if (textForm) { QString matText = mat.toString(); matrixTextEdit->blockSignals(true); matrixTextEdit->setPlainText(matText); matrixTextEdit->blockSignals(false); } if (axisAngleForm) { rxAxisDoubleSpinBox->blockSignals(true); ryAxisDoubleSpinBox->blockSignals(true); rzAxisDoubleSpinBox->blockSignals(true); rAngleDoubleSpinBox->blockSignals(true); txAxisDoubleSpinBox->blockSignals(true); tyAxisDoubleSpinBox->blockSignals(true); tzAxisDoubleSpinBox->blockSignals(true); PointCoordinateType alpha = 0; CCVector3 axis,t; mat.getParameters(alpha,axis,t); rxAxisDoubleSpinBox->setValue(axis.x); ryAxisDoubleSpinBox->setValue(axis.y); rzAxisDoubleSpinBox->setValue(axis.z); rAngleDoubleSpinBox->setValue(alpha * CC_RAD_TO_DEG); txAxisDoubleSpinBox->setValue(t.x); tyAxisDoubleSpinBox->setValue(t.y); tzAxisDoubleSpinBox->setValue(t.z); rxAxisDoubleSpinBox->blockSignals(false); ryAxisDoubleSpinBox->blockSignals(false); rzAxisDoubleSpinBox->blockSignals(false); rAngleDoubleSpinBox->blockSignals(false); txAxisDoubleSpinBox->blockSignals(false); tyAxisDoubleSpinBox->blockSignals(false); tzAxisDoubleSpinBox->blockSignals(false); } if (eulerForm) { ePhiDoubleSpinBox ->blockSignals(true); eThetaDoubleSpinBox ->blockSignals(true); ePsiDoubleSpinBox ->blockSignals(true); etxAxisDoubleSpinBox->blockSignals(true); etyAxisDoubleSpinBox->blockSignals(true); etzAxisDoubleSpinBox->blockSignals(true); PointCoordinateType phi,theta,psi = 0; CCVector3 t; mat.getParameters(phi,theta,psi,t); ePhiDoubleSpinBox ->setValue(phi * CC_RAD_TO_DEG); eThetaDoubleSpinBox ->setValue(theta * CC_RAD_TO_DEG); ePsiDoubleSpinBox ->setValue(psi * CC_RAD_TO_DEG); etxAxisDoubleSpinBox->setValue(t.x); etyAxisDoubleSpinBox->setValue(t.y); etzAxisDoubleSpinBox->setValue(t.z); ePhiDoubleSpinBox ->blockSignals(false); eThetaDoubleSpinBox ->blockSignals(false); ePsiDoubleSpinBox ->blockSignals(false); etxAxisDoubleSpinBox->blockSignals(false); etyAxisDoubleSpinBox->blockSignals(false); etzAxisDoubleSpinBox->blockSignals(false); } }