Rotate already rotated object around axis - rotation

I have a prefab layer object (rectangle) which is rotated bei some degrees to have the right angle to be seen by my 2d camera.
Now i want to rotate the object by x degrees around the Vector3.up axis.
this.gameObject.transform.RotateAroundLocal(this.gameObject.transform.up,angle);
I also tried Vector3.up as the axis and RotateAround , none of that produces the expected result. It rotates some, but not the correct angle somehow.

When it comes to 2D, I usually use orthographic camera looking at XY plane with Z axis pointing away from it. In which case I rotate things as follows:
gameObject.transform.Rotate(0, 0, angle, Space.World);
Which is angle degrees around Z axis clockwise.
In your case, I guess, it would be
gameObject.transform.Rotate(0, angle, 0 Space.World);

Related

Three.js | GLTF Rubik Cube 3D Rotation Problem

Im trying to create a rubik cube but i keep having problems with rotations, when is a single face rotation everythinks looks fine but when i combine 2 rotations it get weird
One Rotation 90 degrees on the left face - Rotation on the x axis
After second rotation on the back face with 45 degrees - rotation on the Z axis
I also found out if i do the X axis rotation it appears that i have to do Y axis rotation on some cubes and Z axis rotation on another for all to work good but that solution doesnt work.
I created a group consisted of the frame of the cube and the faces.
Loads everything then if it is Last, adds the group to the scene.
The this.cube is an array of groups.

Raycast to find point that intersects the z-axis at zero

Is it possible to make a raycast that triggers when it intersects zero on the z-axis, rather than waiting to hit an object?
I have an orthographic camera at (0, 0, -40), and facing directly towards the origin. I want to send a raycast from the center of each edge of the camera's viewport to find the (x, y) points where they intersect the z-axis at zero.
If it's an orthographic camera, the edges of the frustum are parallel like a box. Looking straight down the Z-axis, you can get the x,y values easily with:
x: camera.left or camera.right
y: camera.top or camera.bottom
They don't diverge at all, since ortho cams don't have perspective, so they'll also cross the Z-plane at the position of the camera's edges.

Rotating an IMU around X axis, but all 3 angles changes

I am having trouble with Euler angles of an IMU. I have an IMU that gives quaternion and Euler angles. Such questions like bias and so on will be done by the manufacturer and it like a black box for me. I have to trust on it.
My question is as follows: If I rotate IMU around his X-axis, so just the X angle should change its value (for example Roll angle) and it doesn't matter how I oriented the IMU in the space before. But if I rotate it around X Axes I get changes also on other 2 angles. It is like the rotation is not in IMU own coordinate system.

Axes rotate with SCNNode

If I rotate a sphere around the x-axis 90degree, the axes rotate with it. So the y-axis which is vertical first has now the position of the z-axis at the start.
I want my axes fixed, so that if i rotate around x-axis (1,0,0) it always rotates from front/back and around y-axis (0,1,0) from left/right.
Do I therefore have to calculate it with normals? Inputs appreciated.

How to find orientation of rubik cube?

I'm trying to make a rubik cube game in webgl using three.js (you can try it here).
And I have problems to detect on witch axis I have to rotate my cube according the rotation of the cube. For instance, if the cube is in original position/rotation, if I want to rotate the left layer from down to up, I must make a rotation on the Y axis. But I rotate my cube 90 degrees on Y, I will have to rotate It on the Z axis to rotate my left layer from down to up.
I'm trying to find a way to get the correct rotation axis according the orientation of the cube.
For the moment I check witch vector of the axis of the rotation matrix of the cube is most parallel with the vector(0,1,0) if I want to move a front layer from down to up. But it do not works in edge cases like this for instance :
I guess there is some simple way to do that, but I'm not good enough in matrix and mathematical stuff :)
An AxisHelper can show the aixs of the scene which you could determine the orientation with.
var axishelper = new THREE.AxisHelper(40);
axishelper.position.y = 300;
scene.add(axishelper);
You could also log your cube and check the position and rotation properties with Chrome Developer Tools or Firebug.
You can store the orientation of each cube in its own 4x4 matrix (i.e. a "model" matrix) that tells you how to get from the cube's local coordinates to the world's coordinates. Now, since you want to rotate the cube around to an axis (i.e. vector) in world coordinates, you need to translate the axis into cube coordinates. This is exactly what the inverse of the model matrix yields.

Resources