I would like to know how can i get 2d angle from a 3d quaternion rotation?
for example I have a 3d skeletal bones and I wanna my 2d sprite follow the rotation from for example Head bone in 2d orthogonal camera.
thanks for answers.
is there any ways?
Related
Please kindly redirect me if this is a repeated question:
Currently I have some points in 3D space projected on a plane, and I would like to convert it to 2D wrt the camera angle/view matrix I am currently at. For instance, the 3D coordinates on the YZ plane are (0,1,4) and (0,4,2), so the change in z is -2. However, I want to flatten this and achieve a change in z of 0. Any help or comments are appreciated!
In my game I have characters walking around a 3d terrain. The characters treat the terrain however as a 2d game map, so each character has a direction and a rotation on a 2d plane.
I want to rotate the characters as they're walking on the terrain, so that they are oriented to stand in relation to the terrain, rather then always be oriented as if they're walking on flat ground. This with keeping the original direction of the characters.
Basically I want
For each arbitrary x\z (width\depth) point on the game map I have
the (x,y,z) vector of the point on the terrain
The normal of the the specific terrain face related to the point
Using this, how do I set the rotation of the characters to achieve this?
Depending on which axis you would like to rotate the object the dot product of the faces normal with that axis will return you the cosine of the angle between the two vectors. By that angle you would have to rotate your object.
I have a plane which is rotated 90 degrees around an unknown axis. I know a point and normal for the plane before and after the rotation. How can I find the axis of rotation?
I've done a sketch to illustrate - it's 2D but the problem is actually 3D.
I worked it out with some help from #davin.
Use the cross product to find the direction of the rotation axis. The two known points on the planes and the unknown point on the rotation axis make an isosceles triangle, so simple geometry finds the unknown point.
The axis of rotation is an eigenvector of the rotation matrix. Moreover, it has eigenvalue 1. Every rotation matrix has such an eigenvector. Then just apply the translation to the eigenvector (presuming you're rotating and then translating) to get the final axis of rotation.
Mathematically, you need to solve Rv = v, which is equivalent to finding the nullspace of R-I.
I'm using eigen library to rotate a plane to be parallel to the ground plane.
The ground plane is defined using the normal vector (0,0,1)
The target plane is a set of 3D points and a normal
The rotation angle is known
the normal vector of the plane as well as every point on that plane has to be rotated to be parallel to the ground plane
I'd like to use affine transformation from
http://eigen.tuxfamily.org/api/TutorialGeometry.html
something like this
Transform t = AngleAxisf(a,axis);
axis in this case is a matrix representing an arbitary axis, along which the rotation takes place.
How to find this axis?
Many thanks
Making two planes parallel can be done by making their normals parallel, so you just need to find the axis to rotate the target plane normal about. This is just the axis that is perpendicular to both your ground plane normal and your target plane normal which can be found using the cross product. In your case, if your target plane has a normal of [x,y,z], then the rotation axis is [y,-x,0].
I need to project a 3D object onto a sphere's surface (uhm.. like casting a shadow).
AFAIR this should be possible with a projection matrix.
If the "shadow receiver" was a plane, then my projection matrix would be a 3D to 2D-plane projection, but my receiver in this case is a 3D spherical surface.
So given sphere1(centerpoint,radius),sphere2(othercenter,otherradius) and an eyepoint how can I compute a matrix that projects all points from sphere2 onto sphere1 (like casting a shadow).
Do you mean that given a vertex v you want the following projection:
v'= centerpoint + (v - centerpoint) * (radius / |v - centerpoint|)
This is not possible with a projection matrix. You could easily do it in a shader though.
Matrixes are commonly used to represent linear operations, like projection onto a plane.
In your case, the resulting vertices aren't deduced from input using a linear function, so this projection is not possible using a matrix.
If the sphere1 is sphere((0,0,0),1), that is, the sphere of radius 1 centered at the origin, then you're in effect asking for a way to convert any location (x,y,z) in 3D to a corresponding location (x', y', z') on the unit sphere. This is equivalent to vector renormalization: (x',y',z') = (x,y,z)/sqrt(x^2+y^2+z^2).
If sphere1 is not the unit sphere, but is say sphere((a,b,c),R) you can do mostly the same thing:
(x',y',z') = R*(x-a,y-b,z-c) / sqrt((x-a)^2+(y-b)^2+(z-c)^2) + (a,b,c). This is equivalent to changing coordinates so the first sphere is the unit sphere, solving the problem, then changing coordinates back.
As people have pointed out, these functions are nonlinear, so the projection cannot be called a "matrix." But if you prefer for some reason to start with a projection matrix, you could project first from 3D to a plane, then from a plane to the sphere. I'm not sure if that would be any better though.
Finally, let me point out that linear maps don't produce division-by-zero errors, but if you look closely at the formulas above, you'll see that this map can. Geometrically, that's because it's hard to project the center point of a sphere to its boundary.