Page 1 of 1
How to Modify points and Rotate an point cloud object?
Posted: Mon Apr 05, 2021 8:15 am
by CCNewbieL6
Hello, It is me again.
As the title shown, I want to change the xyz value of a point cloud object.
And I want to rotate the object.
Code: Select all
ccPointCloud pc;
pc.addPoint(CCVector3(x, y, z));
......
// at here, I want to change the xyz value of pc.
I have read a former post(Move mesh in plugin), in which I saw a method that "to apply a 4x4 transformation matrix" to move a mesh.
I guess that the principles to move a mesh and to rotate a point cloud by matrix are same.
But, Now, I am confused that how to create such a matrix. For examlple, if I want to rotate the 'pc' 90 degrees around the x-axis, what should I do?
Re: How to Modify points and Rotate an point cloud object?
Posted: Mon Apr 05, 2021 8:48 pm
by daniel
Re: How to Modify points and Rotate an point cloud object?
Posted: Tue Apr 06, 2021 9:19 am
by CCNewbieL6
Thank you, Daniel!
I got it. To rotate a point cloud object or a mesh:
Code: Select all
#include <cmath>
ccPointCloud pc; // pc is a point cloud.
pc.addPoint(CCVector3(x, y, z)); // add a point
...... // here, we can add some more points
CCVector3 axis3dx(1, 0, 0); // rotate around the x-axis
CCVector3 axis3dy(0, 1, 0); // rotate around the y-axis
CCVector3 axis3dz(0, 0, 1); // rotate around the z-axis
CCVector3 t3d(0, 0, 0); // translation along the x, y or z axis. here I did not do any translation, so keep the value zero.
// create the matrices
ccGLMatrix matrx; // matrix-rotate-x
ccGLMatrix matry;
ccGLMatrix matrz;
// the first parameter is the rotation angle (in radians)
matrx.initFromParameters(M_PI / 3, axis3dx, t3d); //rotate 60 degrees around the x-axis and no translation
matry.initFromParameters(M_PI / 2, axis3dy, t3d); //rotate 90 degrees around the y-axis and no translation
matrz.initFromParameters(M_PI , axis3dz, t3d); //rotate 180 degrees around the z-axis and no translation
pc.rotateGL(matrx); // apply
pc.rotateGL(matry);
pc.rotateGL(matrz);
pc.redrawDisplay(); //redraw Display
pc.applyGLTransformation_recursive(); //apply
Above is what I understand. If there is something wrong, please point out it.
Re: How to Modify points and Rotate an point cloud object?
Posted: Thu Apr 08, 2021 2:53 pm
by daniel
I believe to actually rotate (change) the coordinates, you should call 'applyGLTransformation_recursive' at the end.
Re: How to Modify points and Rotate an point cloud object?
Posted: Thu Apr 22, 2021 2:40 am
by CCNewbieL6
Yes, it is necessary.