quaternions

Rotating a vector around an axis with quaternion

这一生的挚爱 提交于 2020-01-05 11:27:05
问题 I am trying to learn 3d programming, and right now I am trying to understand how to use quaternions to rotate a vector around an axis. As far as I understand, to rotate a vector v around an axis a, after converting both vectors to quaternions, we multiply v by a, then the product by the conjugate of a. I want to rotate v(0,1,0) around a(1,0,0) by 90 degrees, and I should get a resulting vector v(0,0,1) (or 0,0,-1, depending on the direction of the rotation). I am not getting the output I am

User controlled Quaternion Slerp?

左心房为你撑大大i 提交于 2020-01-05 07:25:27
问题 I am trying to rotate a sphere with user control. void RotateGlobe() { SetLock(); if (Input.GetMouseButton(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); userInput.x = Input.GetAxis("Mouse X"); userInput.y = Input.GetAxis("Mouse Y"); if (userInput.magnitude > 0 & Physics.Raycast(ray, Mathf.Infinity, LayerMask.NameToLayer("UI"))) { Vector2 movement = new Vector2(Mathf.Sign(userInput.x), Mathf.Sign(userInput.y)); globe.transform.rotation = Quaternion.Slerp(globe.transform

Point look at Point

烂漫一生 提交于 2020-01-05 06:59:07
问题 So I have one point in 3D space, and I have location and rotation of the Camera in 3D space. So basically there is Vector3 on the object. Camera Vector3 and Quaternion . I need to get how to look at that point. I want to tell user how to move to that point. Should user direct camera left or right or behind? 回答1: One way to do this is to calculate the direction the camera is currently facing as a yaw angle (like a compass heading), and calculate the direction it needs to face in order to be

Translate Local quaternion rotation into global (gyro)

六眼飞鱼酱① 提交于 2020-01-05 05:00:12
问题 I need a way to get euler angles for rotation in global frame of reference from a local. I am using c#, wpf 3d and a gyroscope. I have a globe on the screen that should move in the same way as the gyro. Since the gyro sends movement relative to itself I need to use quaternions to keep the state of the object and update it but I'm stuck. If i do the following: var qu=eulerToQ(Gyro.X,Gyro.Y,Gyro.Z); GlobalQu = Quaternion.Multiply(qu, GlobalQu); IT rotates correctly on one axis. When I rotate by

OpenGL Rotation Around a Point Using GLM

百般思念 提交于 2020-01-04 09:54:12
问题 I've been reading other posts about how to rotate objects around a point in OpenGL by translating the pivot to the origin, rotating, and the translating back. However, I can't seem to get it working. I have a cube and am using glm::perspective and glm::lookAt to generate the projection and view matrices. glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f); // Camera matrix glm::mat4 View = glm::lookAt( glm::vec3(0,3.5,-5), glm::vec3(0,0,0), glm::vec3(0,1,0) ); // Model

Flipping issue when interpolating Rotations using Quaternions

有些话、适合烂在心里 提交于 2020-01-02 10:17:54
问题 I use slerp to interpolate between two quaternions representing rotations. The resulting rotation is then extracted as Euler angles to be fed into a graphics lib. This kind of works, but I have the following problem; when rotating around two (one works just fine) axes in the direction of the green arrow as shown in the left frame here the rotation soon jumps around to rotate from the opposite site to the opposite visual direction, as indicated by the red arrow in the right frame. This may be

Conversion between Euler <=> Quaternion like in Unity3d engine

梦想与她 提交于 2020-01-01 14:22:08
问题 I've used two examples (from this site too), but results are not the same as those that said Unity. Quaternion.Euler and .eulerAngles are Unity functions. FromQ doesn't perform singularity check, FromQ2 does. Results: eulers = (100,55,-11): Quaternion.Euler(eulers) == (0.6, 0.4, -0.4, 0.5) ToQ(eulers)); == (0.5, -0.4, 0.2, 0.7) // 0.5, -0.4 right but in wrong order FromQ(ToQ(eulers)) == (55.0, 100.0, -11.0) FromQ2(ToQ(eulers)) == (-55.5, -6.3, 71.0) // something right Quaternion.Euler(eulers)

Quaternion math for rotation?

孤者浪人 提交于 2020-01-01 09:24:46
问题 I'm drawing a flat disk using gluDisk() in my scene. gluDisk() draws the disk facing the positive Z axis but I want it to be facing some arbitrary normal I have. Clearly I need to use glRotate() to get the disk facing properly but what should be the rotation? I remember this can be calculated using Quaternions but I can't seem to remember the math. 回答1: The solution should be pretty straightforward, and shouldn't require quarternions. The axis of rotation to get from Normal1 to Normal2 must

View Matrix from Quaternion

倖福魔咒の 提交于 2020-01-01 05:22:07
问题 I'm currently building my own quaternion camera. As far as I know, you only need one quaternion to fully specify the camera's orientation (correct me if I'm wrong). So, how would I go about creating the view matrix? I'm using C++ as a programming language by the way. Any help would be appreciated. 回答1: First some caveats. You'll see lots of apparently conflicting formulae on the 'net and in literature on this subject. Most of the conflicts are apparent only. A few are real conflicts, but that

Quaternion “lookAt” function

亡梦爱人 提交于 2019-12-30 03:25:09
问题 Im struggling with the following problem. Im working with bone animation and I want (ie) the head of the player to follow an another object in space. My up axis is +Z my forward axis is +Y, and the magnitude of the quaternion is in W. I tried to use the mesa code for gluLookAt and use the 3x3 matrix to transform to a quaternion but it doesn't work as expected so I go in another direction... So far I got the following code that is "almost" working at least the head of the player is rotating