Questions in topic: "matrix"
http://answers.unity.com/questions/topics/single/1777.html
The latest questions for the topic "matrix"HELP URGENT How to convert Mesh from local to World Space?
http://answers.unity.com/questions/1833540/help-how-to-convert-mesh-from-local-to-world-space.html
Hi. I spawn cube on each click and when the cube spawned and the cube send its own world space vertices to Chunk gameobject for store all cube data into it and to draw. And this Chunk gameobject draws with given world space vertices. I can get my cubes' vertices with World Position using Matrix4X4. And then I can draw mesh with given world space vertices. It draws very well. But it draws well when the Chunk gameobject position in the 0, 0, 0. But when I change position of Chunk gameobject then it draws at another position because my Chunk gameobject do not convert mesh to world space. How to convert mesh to world space?
**I send vertices with world space but when I change Chunk gameobject and it draws at another position. How to fix this?
I spent 2 days to find this issue but I could not find**
---------------------------------------------------
***CODE to draw mesh: This script called "GlobalChunkScript"***
[System.Serializable]
public class MeshData
{
public float[] Vertices;
public int[] Triangles;
}
[System.Serializable]
public class MeshDatabase
{
public List<MeshData> MeshDatas;
}
public class GlobalChunkScript : MonoBehaviour
{
public MeshFilter MeshFilter;
public MeshDatabase MeshDatabase;
public void DrawMesh()
{
Mesh mesh = new Mesh();
List<Vector3> VertiexList = new List<Vector3>();
List<int> TriangleList = new List<int>();
int[] Triangles;
for (int x = 0; x < MeshDatabase.MeshDatas.Count; x++)
{
// Vertices
for (int i = 0; i < MeshDatabase.MeshDatas[x].MeshTop.vertices.Length / 3; i++)
{
VertiexList.Add(new Vector3(
MeshDatabase.MeshDatas[x].MeshTop.vertices[i * 3],
MeshDatabase.MeshDatas[x].MeshTop.vertices[i * 3 + 1],
MeshDatabase.MeshDatas[x].MeshTop.vertices[i * 3 + 2]
));
}
// Triangles
for (int i = 0; i < MeshDatabase.MeshDatas[x].Triangles.Length; i++)
{
TriangleList.Add(MeshDatabase.MeshDatas[x].Triangles[i]);
}
}
Triangles = TriangleList.ToArray();
mesh.SetVertices(VertiexList);
mesh.triangles = Triangles;
mesh.Optimize();
mesh.RecalculateNormals();
MeshFilter.mesh = mesh;
}
}
-----------------------------------------------------
***And this CODE send data to GlobalChunkScript:***
public void SendMeshData
{
MeshFilter MeshFilter;
MeshFilter = GetComponentInChildren<MeshFilter>();
GlobalChunkScript GlobalChunkScript;
MeshData MeshData;
float[] vertices;
int[] triangles;
Matrix4x4 LocalToWorld = transform.localToWorldMatrix;
vertices = new float[MeshFilter.mesh.vertexCount * 3];
for (int i = 0; i < MeshFilter.mesh.vertexCount; i++)
{
vertices[i * 3] = LocalToWorld.MultiplyPoint3x4(MeshFilter.mesh.vertices[i]).x;
vertices[i * 3 + 1] = LocalToWorld.MultiplyPoint3x4(MeshFilter.mesh.vertices[i]).y;
vertices[i * 3 + 2] = LocalToWorld.MultiplyPoint3x4(MeshFilter.mesh.vertices[i]).z;
}
triangles = new int[MeshFilter.mesh.triangles.Length];
for (int i = 0; i < MeshFilter.mesh.triangles.Length; i++)
{
triangles[i] = MeshFilter.mesh.triangles[i] + 24 * GlobalChunkScript.MeshDatabase.MeshDatas.Count;
}
MeshData = new MeshData()
{
Vertices = vertices,
Triangles = triangles
};
GlobalChunkScript.MeshDatabase.MeshDatas.Add(MeshData);
}verticesworldspacematrixmeshfiltermatrix4x4Fri, 30 Apr 2021 19:23:50 GMTGameDeveloperAfUsing Matrix4x4.TRS to rotate Tilemap
http://answers.unity.com/questions/1820407/using-matrix4x4trs-to-rotate-tilemap-1.html
Hi, I'm working on a 2D game and trying to rotate a section of my Tilemap 90 degrees on the Z-axis via using the Tilemap.SetTransformMatrix function. From building on the [sample code][1] and Matrix4x4.TRS from the scripting API I can get the selected area of the Tilemap to rotate, but the tiles are rotating individually in place instead of as a group as I wanted.
Matrix4x4 matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, 0f, 90f), Vector3.one);
//code gets list of vector3int locations for all the square region of tiles to get rotated
//then foreach location found:
tilemap.RemoveTileFlags(location, TileFlags.LockTransform); //remove lock so tiles can be rotated
tilemap.SetTransformMatrix(location, matrix); //apply matrix
I've found lots of Tilemap tutorials, but none have discussed group rotation of tiles, just singular ones. I would be very happy if someone can tell me what I am doing wrong.
----------
**Update**: I wrote this horrible proof of concept code while testing which rotates the 3x3 center section of my tilemap 90 degrees clockwise as a group, without affecting the rotation value of the tilemap itself which is what I wanted:
----------
There has to be an easier/much more efficient way to do this?
Matrix4x4 matrix = Matrix4x4.TRS(new Vector3Int(2, 0, 0), Quaternion.Euler(0f, 0f, -degreesRotated), Vector3.one);
tmap.SetTransformMatrix(new Vector3Int(-1, 1, 0), matrix);
matrix = Matrix4x4.TRS(new Vector3Int(0, 2, 0), Quaternion.Euler(0f, 0f, -degreesRotated), Vector3.one);
tmap.SetTransformMatrix(new Vector3Int(-1, -1, 0), matrix);
matrix = Matrix4x4.TRS(new Vector3Int(-2, 0, 0), Quaternion.Euler(0f, 0f, -degreesRotated), Vector3.one);
tmap.SetTransformMatrix(new Vector3Int(1, -1, 0), matrix);
matrix = Matrix4x4.TRS(new Vector3Int(0, -2, 0), Quaternion.Euler(0f, 0f, -degreesRotated), Vector3.one);
tmap.SetTransformMatrix(new Vector3Int(1, 1, 0), matrix);
matrix = Matrix4x4.TRS(new Vector3Int(-1, 0, 0), Quaternion.Euler(0f, 0f, -degreesRotated), Vector3.one);
tmap.SetTransformMatrix(new Vector3Int(2, 1, 0), matrix);
matrix = Matrix4x4.TRS(new Vector3Int(1, -1, 0), Quaternion.Euler(0f, 0f, -degreesRotated), Vector3.one);
tmap.SetTransformMatrix(new Vector3Int(0, 1, 0), matrix);
matrix = Matrix4x4.TRS(new Vector3Int(1, 1, 0), Quaternion.Euler(0f, 0f, -degreesRotated), Vector3.one);
tmap.SetTransformMatrix(new Vector3Int(-1, 0, 0), matrix);
matrix = Matrix4x4.TRS(new Vector3Int(-1, 1, 0), Quaternion.Euler(0f, 0f, -degreesRotated), Vector3.one);
tmap.SetTransformMatrix(new Vector3Int(0, -1, 0), matrix);
matrix = Matrix4x4.TRS(new Vector3Int(-1, -1, 0), Quaternion.Euler(0f, 0f, -degreesRotated), Vector3.one);
tmap.SetTransformMatrix(new Vector3Int(1, 0, 0), matrix);
[1]: https://docs.unity3d.com/ScriptReference/Tilemaps.Tilemap.SetTransformMatrix.html?_ga=2.139285555.1852893696.1615059672-370128947.1611833629tilemapmatrixmatrix4x4Tue, 09 Mar 2021 12:49:47 GMTpil95Is it possible to change the offset of a texture based on another textures UV?
http://answers.unity.com/questions/1813926/is-it-possible-to-change-the-offset-of-a-texture-b.html
I am creating a program where I have a main skin texture and a tattoo texture placed over it. I am doing this using a shader. I have the tattoo on a different "TEXCOORD" because I created a rotation matrix for it. I now want to change the offset of the tattoo but I don't want it to move diagonally if the user chooses to have the tattoo at, lets say a 45 degree angle. I would like to change the offset in accordance to the main skin texture, which cannot be rotated. Is this possible? How can I go about it?rotationtextureshadersmatrixFri, 12 Feb 2021 20:08:19 GMTritamorenoFind direction on a sphere?
http://answers.unity.com/questions/1790684/find-direction-on-a-sphere.html
I want objects to rotate around the point in space. Imagine how the vertices move when you rotate a sphere mesh. They rotate using a matrix. I tried to do the same way and it works but super slow. For 40 objects in FixedUpdated it destroys my FPS on mobile.
Is there a faster way to get a direction on a sphere?
----------
Img: red vectors - point direction, green dir - sphereMovementDir
![alt text][1]
/// <summary>
///
/// </summary>
/// <param name="sphereMovementDir">direction the sphere moves in space</param>
/// <param name="sphereCenter">sphere center in world coordinates</param>
/// <param name="point">point on a sphere in world coordinates</param>
/// <returns></returns>
public Vector3 GetDirOnASphere(Vector3 sphereMovementDir, Vector3 sphereCenter, Vector3 point)
{
//transform sphereMovementDir to the rotation direction. Like a rotation of roll
Quaternion lookRot = Quaternion.Euler(sphereMovementDir.z, 0f, -sphereMovementDir.x);
//matrix that rotate smth using lookRot
Matrix4x4 m = Matrix4x4.Rotate(lookRot);
//calculate a new position for point after we applied rotation matrix
Vector3 newPointPos = sphereCenter + m.MultiplyPoint3x4(point - sphereCenter);
//get direction of movement on a point of a sphere
Vector3 forceDir = (newPointPos - point).normalized;
//return the dir so then I can apply it to the point...velocity
return forceDir;
}
[1]: /storage/temp/171377-screenshot-2020-11-21-102407.pngrotationmathmatrixSat, 21 Nov 2020 07:31:04 GMTMelnikovvMatrix losing reference to GameObject?
http://answers.unity.com/questions/1780517/matrix-losing-reference-to-gameobject.html
I have a gameObject `private GameObject[,] gridAsMatrix = new GameObject[5,5];` and I have a CreateGrid function that's called on Start. It is as follows.
void CreateGrid(Transform mapHolder)
{
for(int i=0;i<gridHeight;i++)
{
for(int j=0;j<gridWidth;j++)
{
GameObject newHex= Instantiate(hexagonPrefab);
Vector2 gridPos=new Vector2(i,j);
newHex.transform.position = CalcWorldPos(gridPos);
newHex.transform.SetParent(mapHolder,false);
newHex.name=i.ToString() + j.ToString();
Debug.Log(newHex.name);
gridAsMatrix[i,j]=newHex;
Debug.Log(gridAsMatrix[i,j].name);
}
}
}
The two debug statements above work correctly and give the same output. Yet in my Update function I have the following statement
void Update()
{
PropagateDown();
}
void PropagateDown()
{
for(int i=0;i<hexHeight;i++)
{
for(int j=0;j<hexWidth;j++)
{
Debug.Log(gridAsMatrix[i,j].name);
}
}
}
but this time the gridAsMatrix[i,j].name gives out "00" as its output always. Why did my values change? I am also using an editor script but I don't think its the cause of the issue. I can give that also if this isn't enough.matrixarray of gameobjectsThu, 15 Oct 2020 14:55:10 GMTogito123assertion failed on expression ismatrixvalid(matrix)
http://answers.unity.com/questions/1775591/assertion-failed-on-expression-ismatrixvalidmatrix.html
how to handle the error assertion failed on expression:ismatrixvalid(matrix)matrixwarningexpressionSun, 27 Sep 2020 16:36:27 GMTe8cs0653d grid/matrix inside a mesh
http://answers.unity.com/questions/1773454/3d-gridmatrix-inside-a-mesh.html
Hi All,
I'm trying to create a matrix/grid inside a 3D mesh.
I can create grids, i can create random points inside meshes and colliders, I can even slice the grids using a plane... but I'm having trouble combining the 2.
I'm trying to create an environment where I can get any 3D mesh (Any shape/design/3D file format) and then create a series of 3D points inside it at a given distance from each other.
And obviously only have the points that are inside the mesh, removing the others.
I've looked into Octree and just found out about KDtree but really not sure i need to get that complicated.
Does anyone know how I can achieve this, how would you go about doing this?
Not looking for code or anything, just direction.
![alt text][1]
[1]: /storage/temp/167824-3d-matrix.jpg3dgridmatrixpointsSun, 20 Sep 2020 06:49:59 GMTMorphusTwoHow to invert an 8x8 matrix or calculate 8DOF homography
http://answers.unity.com/questions/1753595/how-to-invert-an-8x8-matrix-or-calculate-8dof-homo.html
Hi, I'm trying to write my own distortion tool. I have 2 sets of corners and want to solve for the transformation matrix between them. I found I can do that by solving the system below for H but it means I need to invert an 8x8 matrix. How do I do that? or otherwise how do I find the transformation matrix from the points?
![alt text][1]
**Edit:** I'm trying to find the 4x4 matrix H=[h11, ..., h32] that transformed 4 given pairs of 2d points. Once I have it I can use it to transform all of a mesh's vertices and get a distorted mesh (I'll do it by extending BaseMeshEffects). So I need to invert the large matrix on the left & Left-multiply the inverse by the vector on the right to get H's coefficients.
![alt text][2]
[1]: /storage/temp/163857-solvefor8dofhomography.png
[2]: /storage/temp/163936-4pointstransform.pngmatrixtransformationalgebraWed, 22 Jul 2020 10:02:22 GMTWavePlantHow calculated ViewportToWorldPoint
http://answers.unity.com/questions/1731992/how-calculated-viewporttoworldpoint.html
Hello
What does the ViewportToWorldPoint code look like?
I tried to make one but it doesn't return that value...
public Vector3 ViewportToWorldPoint(Vector3 position)
{
Matrix4x4 P = Camera.main.projectionMatrix;
Matrix4x4 V = Camera.main.worldToCameraMatrix;
Matrix4x4 VP = P * V;
Vector4 projW = P * new Vector4(0.0f, 0.0f, position.z, 1.0f);
float x = 1.0f - (2.0f * position.x);
float y = 1.0f - (2.0f * position.y);
float z = projW.z / projW.w;
Vector4 worldPoint = VP.inverse * new Vector4(x, y, z, 1.0f);
worldPoint.x /= worldPoint.w;
worldPoint.y /= worldPoint.w;
worldPoint.z /= worldPoint.w;
return worldPoint;
}cameratransitionmatrixMon, 18 May 2020 07:14:01 GMTmagyarfiuHow calculated ScreenToWorldPoint
http://answers.unity.com/questions/1731806/how-calculated-screentoworldpoint-1.html
Hello
What does the ScreenToWorldPoint code look like?
It would be something like that, but it doesnâ€™t return the value it should.
public Vector3 ScreenToWorldPoint(Vector3 position) {
float x = (2.0f * position.x / Camera.main.pixelWidth) - 1.0f;
float y = (2.0f * position.y / Camera.main.pixelHeight) - 1.0f;
float z = position.z * 2 - 1;
Vector3 clip = new Vector3(x, y, -1.0f);
Matrix4x4 viewInverse = Camera.main.cameraToWorldMatrix;
Matrix4x4 projectionInverse = Matrix4x4.Inverse(Camera.main.projectionMatrix);
Matrix4x4 viewProjectionInverse = viewInverse * projectionInverse;
Vector3 worldPoint = viewProjectionInverse.MultiplyPoint(clip);
return worldPoint;
}cameramatrixSun, 17 May 2020 16:38:26 GMTmagyarfiuInstantiate Object to always form a matrix on my screen
http://answers.unity.com/questions/1725380/instantiate-object-to-always-form-a-matrix-on-my-s.html
I have a square prefab and I want to instantiate NxN prefabs that will form a matrix on the screen.
![alt text][1]
[1]: /storage/temp/158306-screenshot-2020-05-02-at-113915.png
All the objects are instantiated and are set to have as parent a canvas. My prefab is anchored to the top-left corner to the canvas. My current solution that does not satisfy my need is:
int yAnchorPos = -100;
for (int row = 0; row < nBoardSize; ++row)
{
int xAnchorPos = 100;
_mGameBoard[row] = new GameObject[nBoardSize];
for (int col = 0; col < nBoardSize; ++col)
{
_tilePrefab = Instantiate(_tilePrefab, transform.position, Quaternion.identity);
_tilePrefab.transform.SetParent(this.transform);
_tilePrefab.GetComponent<RectTransform>().anchoredPosition = new Vector3(xAnchorPos,yAnchorPos,0);
_tilePrefab.transform.tag = row.ToString() + col.ToString();
_tilePrefab.transform.name = _tilePrefab.transform.tag;
_mGameBoard[row][col] = _tilePrefab;
_mGameBoard[row][col].GetComponent<Image>().color = colors[UnityEngine.Random.Range(0, 4)];
xAnchorPos += 150;
}
yAnchorPos -= 150;
}
But I would like my objects to have same distance between them even is I have to generate a matrix of 4x4, 6x6, 8x8, etc.
Is there any solution?canvasinstantiate prefabmatrixMon, 04 May 2020 09:55:59 GMTunity_TDkmLyQfc3QYFQXYZ Rotation Matrix
http://answers.unity.com/questions/1682405/xyz-rotation-matrix.html
Hello,
can somone tell me which lines are missing for a complete xyz rotation matrix?
x = Mathf.Cos(Radians) * Child.transform.localPosition.x - Mathf.Sin(Radians) * Child.localPosition.y;
y = Mathf.Sin(Radians) * Child.transform.localPosition.x + Mathf.Cos(Radians) * Child.localPosition.y;
Example video of current state:
https://www.youtube.com/watch?v=P3N3gYSOwVU&feature=youtu.berotaterotatearoundmatrixThu, 05 Dec 2019 19:37:26 GMTMichael_RHow to get the corrrect Stereo Projection matrices
http://answers.unity.com/questions/1679616/how-to-get-the-corrrect-stereo-projection-matrices.html
I have tried the method:
Camera.GetStereoNonJitteredProjectionMatrix(Camera.StereoscopicEye.Left/Right);
However, the matrix that it gives me is actually different than the one used on the GPU. For a comparison, I used a GPU readback to get the projection matrix from the Vive Pro, and compared that with the matrix that the camera method gave me:
// Camera method, left eye:
0.77925 0.00000 -0.05615 0.00000
0.00000 0.70090 0.00480 0.00000
0.00000 0.00000 -1.00060 -0.60018
0.00000 0.00000 -1.00000 0.00000
// Camera method, right eye:
0.78300 0.00000 0.05547 0.00000
0.00000 0.70472 0.00192 0.00000
0.00000 0.00000 -1.00060 -0.60018
0.00000 0.00000 -1.00000 0.00000
// GPU Readback, left eye:
0.77925f, 0.00000f, -0.05615f, 0.00000f
0.00000f, -0.70090f, -0.00480f, 0.00000f
0.00000f, 0.00000f, 0.00030f, 0.30009f
0.00000f, 0.00000f, -1.00000f, 0.00000f
// GPU Readback, right eye:
0.78300f, 0.00000f, 0.05547f, 0.00000f
0.00000f, -0.70472f, -0.00192f, 0.00000f
0.00000f, 0.00000f, 0.00030f, 0.30009f
0.00000f, 0.00000f, -1.00000f, 0.00000f
These are somehow different, so I'm wondering which additional calculations Unity does before sending it to the GPU. If I know that then I could implement those steps myself and be able to overwrite the Projection matrix in for VR.graphicsmathmatrixmathsSun, 24 Nov 2019 18:54:09 GMTMarco_Stone2d collision matrix not working with user layers
http://answers.unity.com/questions/1678577/2d-collision-matrix-not-working-with-user-layers.html
as the question suggests when trying to cause collision ignore with the collision matrix on user layers they collide anyways but when using builtin layers it works.
using 2019.2.11.f1collider2dcollision2dmatrixignorecollisionSun, 17 Nov 2019 15:12:44 GMTtheWoollygoatPlayer wont jump when platform's layer is changed to a created one!
http://answers.unity.com/questions/1667281/player-wont-jump-when-platforms-layer-is-changed-t.html
I need the platform's layer to be a created one so that the spikes can pass through using the collision matrix. The problem is when i change the layer of the platform the player doesn't jump for some reason like he just stayes on the ground while doing the jump animation. Can anyone please help me!! I tried everything i could think of!!! Thanks in advance <3collisionjumplayersplatformmatrixTue, 24 Sep 2019 01:43:35 GMTdavidcmpouIs there such a thing as Unity Algebra?
http://answers.unity.com/questions/1665020/is-there-such-a-thing-as-unity-algebra.html
I have seen some questions about Linear Algebra with the importance indicating the abstract math. What I am interested in learning from Unity is the abstract of the Unity Algebra. For example, when writing equations using math abstract symbols describing the GameObject's Transform and its properties, the position, the rotation and the scale, what symbols do the Unity Team uses when writing out such symbolic equations. How does the symbols reflect the reference frames between local and global? The Unity Manuel and the Unity Scripting does not cover this topic at all... Big question, when writing an article about the Unity Game Engine, I would think they would want consistency describing their math. Please update your Manuels with an advanced section showing the abstract symbolic math related to you vectors and matrices and how they relate to each other...
I like to continue this conversation in the forms but again I do not see where to go to do this... If you want people to write professional articles covering Unity with a consistent symbolic algebra then allow the Unity Team to gives us the Unity Algebra that they use. What I mean by Algebra is a text (textbook) showing the math operations T subscript L for local-transform and T subscript G for global-transform, etc...
Seriously, I really need the Unity Algebra when writing articles, Unity's User can lookup the algebra in Unity's Algebra Textbook...
Thank YoutransformquaternionmathvectormatrixThu, 12 Sep 2019 19:05:15 GMTUniteMageCan you create a camera perspective that doesn't change with viewing angle?
http://answers.unity.com/questions/1659820/can-you-create-a-camera-perspective-that-doesnt-ch.html
Is it possible to create a custom camera projection that gives an overhead perspective view but doesn't change based on viewing angle?
----------
To explain better. In orthographic projection if you had a bunch of cubes facing in the same direction so that from the camera view they all looked like squares. Then if you switch to perspective you would see the sides of the cubes that are further to the edge of the view etc.
But what about a projection where all the cubes have all their sides (except the back) equally visible regardless of their position? So that they would all look like identical 3d trapezoids viewed directly from above. Hopefully the picture makes it clear.
![alt text][1]
I'm still trying to wrap my head around how the camera projections even work. But I'd just like to know if this sort of thing is even feasible? Or if its something that's already been done and theres a name for it?
Plus any pointers to tutorials that discuss relevant subject matter would be appreciated. Thanks.
[1]: /storage/temp/145037-untitled-1.jpgorthographicmatrixprojectionperspectiveThu, 22 Aug 2019 23:25:06 GMTMarky5959UnityObjectToClipPos is inverted?
http://answers.unity.com/questions/1651562/unityobjecttoclippos-is-inverted.html
I upgraded untiy and an old shader and one of the core cg functions used by unity got its values inverted. To illustrate I assigned one of the values to the red channel on a test shader:
<br>
![alt text][1]
<br>
The code is the same on both versions, the offending line/function is:
o.vertex = UnityObjectToClipPos(v.vertex);
<br>
This is apparently expected behaviour in newer versions, but it breaks the shader. A solution would be to somehow invert the return values of UnityObjectToClipPos, but I have no idea on how to do it, I haven't found a similar function for it and the documentation seems sparse, any help deeply appreciated!
<br>
----------
**UPDATE**: I managed to solve the original issue by just finding a newer version of the shader I was using. My situation was unlikely but here are the details if anybody has the same issue in the future.
<br>
<br>
The shader is the **FXWater4Simple** from the standard assets, I was using the 5.4 and didn't think they would actually update it. Now I have the 2018.1.9f2 version of the shader (last time they updated the standard assets apparently) and everything seems fine.
<br>
<br>
In regards to the original question, there was another line in the code which was important:
<br>
<br>
o.pos = UnityObjectToClipPos(v.vertex);
o.screenPos = ComputeScreenPos(o.pos);
which now is:
<br>
o.pos = UnityObjectToClipPos(v.vertex);
o.screenPos = ComputeNonStereoScreenPos(o.pos);
<br>
That's the only change I've noticed in the code. The problem is still a mystery to me because now I can't seem to replicate the issue by reverting the code, which spells doom and makes me believe maybe the problem is something else and it will eventually come back.
[1]: /storage/temp/143509-1.pngshadershadersshader programmingcgmatrixWed, 24 Jul 2019 23:28:51 GMTAgapitoToriSet orientation from 3x3 rotation matrix
http://answers.unity.com/questions/1651386/apply-rotation-from-3x3-rotation-matrix.html
I have been trying to reproduce scenes on Unity from another software called MuJoCo. I have been stuck on setting the camera angle for a week now. Any help and feedback are very appreciated!
In MuJoCo, I have obtained the frame orientations of the camera that are stored as 3-by-3 matrices. I want to use that matrix and apply to the camera in Unity. So I tried to calculate the quaternion and apply to Unity. The results are not good.
What I did:
I followed the equations in this page [link text][1] and created a function. Then I created a new
quaternion and assigned the quaternion to localRotation of the camera.
thecamera = root.transform.GetChild(i).gameObject.GetComponent<Camera>();
thecamera.transform.localRotation = Mat2Quat(fcamort);
Quaternion Mat2Quat(float[] mat)
{
float qw = Mathf.Sqrt(1.0f + mat[0] + mat[4] + mat[8]) / 2.0f;
float qx = (mat[7] - mat[5]) / (4.0f * qw);
float qy = (mat[2] - mat[6]) / (4.0f * qw);
float qz= (mat[3] - mat[1]) / (4.0f * qw);
Quaternion quat = new Quaternion(qx, qz, qy, qw);
return quat;
}
I suspect what I did wrong was the convention on both softwares are different. In MuJoCo, they used right-handed coordinate system, with x pointing to right, y pointing forward and z upward. The camera is looking along the -Z axis of its frame. I have attached a photo to explain this.![alt text][2]
[1]: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/
[2]: /storage/temp/143476-mj-un-frame.jpgrotationquaternionorientationmatrixframeWed, 24 Jul 2019 12:23:17 GMTcmwongIs this a valid projection matrix and why?
http://answers.unity.com/questions/1632232/is-this-a-valid-projection-matrix-and-why.html
Hi,
<br><br>
from several AR/VR headset I keep getting projection matrices, having non zero value in the second column/ first row.<br>
I wasn't able to find an explanation for this. Is it possible that this is related to some lens correction effect?
<br>
<br>
Thanks
<br><br>
Edit:
This is some example projection matrix data (Samsung Odysee Plus MRTK v2):
<br>
<pre>
<code>
0.8804515 <b>-0.00124849</b> -0.08054376 0
0 0.7055852 0.0006020069 0
0 0 -1.0002 -0.20002
0 0 -1 0
</code>
</pre>renderingvrmathmatrixprojectionThu, 16 May 2019 12:32:06 GMTseb_kruegerFind a dynamic path from a start point to end point in a mxn matrix
http://answers.unity.com/questions/1631492/find-a-dynamic-path-from-a-start-point-to-end-poin.html
Hi,
I have an mxn matrix in my 2dgame (in the image below, it's 16 rows and 11 columns), where I need to start from a random cell marked in red and need to end in a random cell marked in green. I need to create a dynamic path from the start point to end point which needs to be changed each time, I load the scene. Since I'm new to this, I don't know how to do this. If possible can someone help me how to do this? Thanks in advance
![alt text][1]
[1]: /storage/temp/138152-2019-05-14-12-30-15-untitled-document-google-docs.pngpathfindingmatrixpath-findingTue, 14 May 2019 07:33:41 GMTtonyjoseph456Getting the forward position of an object in a vertex shader
http://answers.unity.com/questions/1620489/getting-the-forward-position-of-an-object-in-a-ver.html
I have a vertex shader that tries to get the forward position of the pivot point of the object and do something based on that position.
I've tried
float4 objectOrigin = mul(_Object2World, float4(0.0, 0.0, 0.0, 1.0));
originForward= objectOrigin.z;
but obviosly objectOrigin.z is not always the forward position.
I've also tried
float4 objectOrigin = mul(_World2Object, float4(0.0, 0.0, 0.0, 1.0));
originForward= objectOrigin.z;
which kinda works better but it still isn't its forward position, depending on the rotation sometimes its reversed and also for some reason this value gets changed as I rotate the object.
I'm not very good with matrix math and haven't found anything useful on google either.
is it possible to get the forward matrix of a point in a vertex shader?
what I really want is equivalent of [transform.forward][1] in a shader.
[1]: https://docs.unity3d.com/ScriptReference/Transform-forward.htmlrotationshadershadersmatrixforwardTue, 09 Apr 2019 20:57:18 GMTazilvlOn which side of the vector on graph is the origin? [Geometry]
http://answers.unity.com/questions/1619915/on-which-side-of-the-vector-on-graph-is-the-origin.html
I have a vector on a graph. The position of the vector on the graph is known. The vector value is normalized and is known. If the graph is divided along the vector's position and direction, on which side is the origin, left or right?
float x = someValue;
float y = otherValue;
Vector2 vector = someVector.normalized;
// Find:
bool originIsOnRight;
Given these variables, how to calculate originIsOnRight?
![alt text][1]
[1]: /storage/temp/136078-notes-190407-191723-b1b-1.jpgangleeuleranglesvectormatrixMon, 08 Apr 2019 09:12:49 GMTDemSecHow to set ortho projection / model view matrix without a camera?
http://answers.unity.com/questions/1611239/how-to-set-ortho-projection-model-view-matrix-with.html
I'm trying to create the correct projection and modelview matrix for rendering without a camera.
_orthoCamera is a camera I set up in the scene view. Using the _orthoCamera projection matrix and modelview matrix works but I don't know exactly how to recreate these. My attempt is the commented code.
//not correct
//var projection = Matrix4x4.Ortho(-512, 512, -512, 512, 0.3f, 1000);
//var modelView = Matrix4x4.LookAt(new Vector3(512, 512, -5), new Vector3(512, 512, 0), Vector3.up); //inverse?
//correct result
var projection = _orthoCamera.projectionMatrix;
var modelView = _orthoCamera.worldToCameraMatrix;
GL.LoadProjectionMatrix(projection);
GL.modelview = (modelView);
This is how I set the camera up in the scene.
![alt text][1]
[1]: https://i.stack.imgur.com/0Uz9Y.pngmatrixorthographic cameraprojection-matrixMon, 11 Mar 2019 11:07:48 GMTSkaltumRaycasting with Lense Distortion
http://answers.unity.com/questions/1606747/raycasting-with-lense-distortion.html
I'm having an issue with raycasting while using Unity's Lens Distortion image effect.
Raycasts lose accuracy because they use the camera's projection matrix without accounting for the distortion of the image effect. I tried to find the matrix or algorithm used for the distortion but I haven't found anything.
Does any know what algorithm is used and how to modify the raycasting logic to account for the distortion?
Documentation about the effect is here:
https://docs.unity3d.com/Packages/com.unity.postprocessing@2.0/api/UnityEngine.Rendering.PostProcessing.LensDistortion.htmlraycastingimage effectsmatrixdistortionTue, 26 Feb 2019 19:07:01 GMTanaswattarMatrices to rotation
http://answers.unity.com/questions/1604049/matrices-to-rotation.html
I need to convert values found in Cheat Engine of a program (Minecraft in this case) by reading memory to Vector3 or Quaternions so that I can match my Unity's camera's rotation to that of the target program's camera's rotation.
.
So far I can find values (see images) but I cannot make sense of them. Please halp.
.
Most of the valuies range from -1 to 1, but some stay between 1 and 0.
.
Here is my original forum post: https://forum.unity.com/threads/3d-in-game-overlay-in-any-game.631612/
.
https://i.imgur.com/EFSjj55.png
https://i.imgur.com/32XGHws.png
https://i.imgur.com/PQjU0CL.pngrotationquaternionmemorymatrixWed, 20 Feb 2019 05:56:59 GMTMachinemanEditor Scrollview clipping Issue
http://answers.unity.com/questions/1599271/editor-scrollview-clipping-issue.html
Hey All,
<br>
<br>
I'm using a matrix trick I've seen posted around to scale individual windows within a scrollview.
<br>
<br>
Rect preWindowPos = new Rect(n.pos.x, n.pos.y, n.size.x, n.size.y);
Matrix4x4 oldMatrix = GUI.matrix;
GUIUtility.ScaleAroundPivot(new Vector2(zoomScale, zoomScale), preWindowPos.position);
Rect postWindowPos = GUI.Window(id++, preWindowPos, DrawNode, n.name);
GUI.matrix = oldMatrix;
<br>
This works well, but the clipping from the scrollview messes with the drawn windows. I've read that you can use GUI.EndGroup() and GUI.BeginGroup() to adjust the clipping rects, but have had no success.
<br><br>
![alt text][1]
[1]: /storage/temp/132677-editorclipping.png
<br>
<br>
Any suggestions would be greatly appreciated.
<br>
<br>scalingscrollviewmatrixclippingeditor windowThu, 07 Feb 2019 13:38:32 GMTLoftySkyHow to get find euler angle provided I have Transformation Matrix
http://answers.unity.com/questions/1593370/how-to-get-find-euler-angle-provided-i-have-transf.html
Hello I have a 2 camera setup, Cam1 and Cam2. Provided I get the Transformation matrix to convert Cam2 view same as Cam1. How Can I get the rotation matrix and Euler angles?rotationeuleranglesmatrixtransform.rotationtranslationWed, 23 Jan 2019 10:14:08 GMTJeevanKumarGHow to get Transformation Matrix
http://answers.unity.com/questions/1593364/how-to-get-transformation-matrix.html
I have two cameras (Cam1 and Cam2) looking at same object (say a Cube). I want to get the transformation matrix such that Cam2 view is same as Cam1. How can I get the Transformation matrix?cameramatrixcamera rotationtransformationmatrix4x4.trsWed, 23 Jan 2019 10:11:23 GMTJeevanKumarGHow does TWO BONE IK works?
http://answers.unity.com/questions/1590885/how-does-two-bone-ik-works.html
Hello,
could someone pls describe how TWO BONE/JOINT IK works. Ive also tried some tutorials one youtube about IK but they where pretty complicated. I heard about the "Jacobian inverse technique" and the "Denavit-Hartenberg-Transformation" but i didnt understood them so far.
p.s. Sorry for my bad englishmathmatrixikWed, 16 Jan 2019 19:24:17 GMTMichael_R