Yeah, that works as long as your cube won't look up (aka - as long as you stay in 2d and only rotate around Y).
With matrix you could replace the lineAngle calculations like that then should work also when the cube rotates up:
Code: Select all
vector3df lineAngleA=getDirectionFromAngle(-45/2);
vector3df lineAngleB=getDirectionFromAngle(45/2);
irr::core::matrix4 mat;
mat.setRotationDegrees( prot);
mat.transformVect(lineAngleA);
mat.transformVect(lineAngleB);
(tiny side note - using code marker you can format code like this in the forum)
So I took the +prort.Y out of the angle calculation and do that part with a matrix instead.
If you have pure rotation matrix (or a rotation + scaling matrix) then only the inner 3x3 matrix is really used.
So for this case you can also use mat.rotateVect which unlike transformVect only uses the 3x3 matrix (despite it names it will also scale if you have a scale matrix). transformVect is needed if you also want to add the position (translation).
And a quick note about SMaterial. I guess the setFlag = true was copy paste error. But careful with material.Lighting = true; Then your lines only show if there is also a light-source in your scene. If those lines are for debugging you generally want to turn lighting off - then they have the exact color you set.
Edit: Just for fun a quick explanation what that 3x3 matrix does (and I really hope I don't mess it up, for the full deal better watch those videos
https://www.youtube.com/playlist?list=P ... itgF8hE_ab):
If you have x,y,z vector what it really means is - take x steps along x axis, then y along y axis and z steps along z-axis.
Matrixes are now the idea: What if you use axes which point in other directions?
Then you can still say - go x steps along first axis, y steps along second and z steps along third axis.
A bit like a treasure-map which has 3 directions drawn you have to follow.
And the first 3 rows in the 3x3 matrix are simply those 3 directions (ignore the 4th value in those rows, it's set to 0 for this case). So calculation is x*(axis1)+y*(axis2)+z*(axis3).
Original cartesian coordinate matrix is (1,0,0)(0,1,0)(0,0,1) (as you do 1 steps toward x-y-z in each direction there, also called the identity matrix). If you do the calculation there you'll find out you just get back x,y,z.
Now the trick is finding direction for the 3 axes so they point in the same direction as your cubeNode.
And that's where the same kind of sin/cos calculations you did above come into play.
matrix4::setRotationDegrees (or setRotationRadians which it calls) uses those to rotate the original 3 x,y,z axes into the same direction as your cubeNode.
And rotateVect then simply steps along those 3 directions given by the matrix (while transformVect adds the 4th row as well which moves your vector after rotating/scaling it).
And if think like that you also notice how rotation and scale are a bit mixed up in the 3x3 matrix (you take longer steps by using larger matrix values, but direction stays the same).