A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

# Tag Info

46

I think the direction of the coordinate axes are holdovers from different domains where the crucial plane was different, and X/Y were aligned with that crucial plane. In some applications the ground plane was the most important, thus X/Y were the ground and Z ended up perpendicular to that. For games however the crucial plane is usually the screen (...

11

I'm not sure of a good way to preface this, other than I hope it ties together nicely by the end. That said, let's dive in: A rotation and an orientation are different because the former describes a transformation, and the latter describes a state. A rotation is how an object gets into an orientation, and an orientation is the local rotated space of the ...

5

The sign of the dot-product of C with AB will be positive when the vector component of CD parallel to vector AB is in the direction AB, and negative when it is in the direction BA. The sign of the (z-component of the) cross-product of vector CD with vector AB will indicate which side of AB the agent is approaching from. Depending on your sign conventions, ...

5

The simplest way to do this is to compute a correcting rotation every time the camera moves: axis = cross(newPosition, oldPosition); angle = acos(dot(normalize(oldPosition), normalize(newPosition))); ...and then rotate the camera's orientation matrix/quaternion/basis vectors by this correction. But since the movements are likely to be small and frequent, ...

4

Your problem is under-constrained, so there are a lot of possible solutions. My suggestion is to see your vec3 as the result of rotating vector [1 0 0] by φ around axis Y then by θ around axis Z. This is the latitude/longitude notation. The corresponding transformation matrix is: |cosθ cosφ -sinθ -cosθ sinφ| |sinθ cosφ cosθ -sinθ sinφ| | sinφ ...

4

A single vector only represents a direction. It sounds like gimbal lock will not be a problem in your case. First you need to select an up vector to really define an orientation instead of a direction. You can start with the world's up vector and than use the last frames up vector from there on. Now you can calculate a side vector using the cross product ...

4

Click on the object in the scene, and look at the Rotation values in the Inspector. This will tell you which way the object is oriented in absolute terms. If the orientation does not match your expected axis (for example, 90 degrees off, or using an unintuitive axis for a given direction), you cannot change the axis of the object itself. Instead, you can ...

3

It's mostly legacy from the times when all that could've been made with 3D was some screen-space rotating cube or parallax scrolling or something similar. In such applications, Z was "depth" because X and Y were the axes for the screen plane. As demos were getting more advanced, the original conventions stayed because it's easier not to change anything that ...

3

Yes, in fact that's what quaternions are often used for - interpolating between two different orientations. Other methods of representing orientation suffer from issues like gimbal lock and wrap-around. Left is quaternions, right is Euler angles https://answers.unity.com/questions/717637/how-do-you-smoothly-transitionlerp-into-a-new-rota.html ...

3

You can just check if the width of the screen is less than the height - if this is the case, then you definitely have a monitor in portrait mode.

3

Your best luck is to learn some matrix math. You should have some kind of scene graph that establishes the character as a child node of the boat. It then would store it's position relative to the boat. The boat would have a transformation matrix, you apply that to the child nodes, and the child nodes could stack some more transformations on the matrix ...

3

I solved it. I was on the right track... The final solution is: void SceneElement::look_at(const mx::Vector3f& target, const mx::Vector3f& up) { mx::Vector3f forward_l = mx::normalize(target - position); mx::Vector3f forward_w(1, 0, 0); mx::Vector3f axis = forward_l % forward_w; float angle = mx::rad_to_deg(acos(forward_l * ...

2

As far as I have ever gleaned the Y = up/down, and Z = depth is based off of physics where gravity is always in the (-Y) direction, and then adding 3D means you don't want to change a fundamental, so it was made depth. On the Z = up/down method though that is a throw back to mathematicians. because X/Y was drawn on the paper that was flat on the table when ...

2

Turn the quaternion into a 3x3 matrix, transpose it (shortcut for the inverse of a purely rotational matrix), apply this matrix to your world space vector and you now have your model space velocity vector (entity's virtual axes: X=right, Y=Up, Z=forward or backward).

2

you can set the velocity to "world space" and just provide a vertical velocity, the particle system will follow the hand orientation, but the particles emitted will always move upwards.

2

This is a major bug in Unity. For those who are stumbling here trying to find a solution, a very awesome gentlemen posted a fix over here at github https://github.com/hvs-clark/unity-android-rotation-lock Hopefully Unity fixes this crazy bug soon, so we don't have to use workarounds like this in the future. From what I read, it is by design, which in my ...

2

If I understand what you're asking, the vector CD is just a vector, not a ray, so only the direction matters, not location. However, AB is a line segment, not just a vector, so its location matters. Your tests have one 'if' test to make two cases, but I think you actually have four cases. Let's look at the diagram in AB's reference frame: If you can ...

2

Alright so I figured out an even more ideal solution. The way I was trying to solve the problem was going to lead to more issues than I needed to deal with, so instead I slept on the problem and thought up a different approach. Instead of trying to min-max my orientation, I now calculate how far from the target orientation the camera is, If it lays above a ...

2

I bit on the mathematical side, but here's a Q & A on MSE on computing quanternion distance. Using that you could do something like: quat targetQuat = target->getOrientation(); quat currentQuat = getOrientation(); quat lerpQuat = glm::lerp(currentQuat, targetQuat, 0.05f); quat maximumQuat = targetQuat*quat(0.707, 0, -0.3535, 0); float d1 = ...

2

If I understand correctly, you are making gravity a vector, and that is messing the rest of your code base. So, first of all, as Anonymous Anonymous points out you will have to make velocity a vector. In fact, any other thing will probably have to be a vector too. Note: I will not define what a vector is. Also, everything I say here is for working in 2D. ...

2

Take the vector pointing from the first point to the second and also the vector from the first point to the camera position, take their cross product. This creates a vector perpendicular to the other ones. Take this vector and the one pointing from the first point to the second and take their cross products too and normalize it. This gives you the normal of ...

1

The resting yaw rotation is determined by the magnetometer - it's the only one of the three sensors that has an absolute reference direction in the horizontal plane. Unfortunately, it's also the most fiddly of the sensors. Metal components inside the device can cause its detected magnetic field vector to be shifted (hard iron distortion) or stretched/...

1

In case anyone comes across this, here is how I solved it (for my needs at least). This solution requires the target object have an parent GameObject (child position offset 0,0,0). Both must be specified as parameters to the script. using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO.Ports; public class ...

1

1

Thanks, @Dmi7ry, for posting the answer to this question above in the comments. The functions to use here are lengthdir_x and lengthdir_y, as explained in the link to the other question. For my purposes, I knew that the point on the turret that I want my bullet to appear at was 62 pixels out from the origin. The functions lengthdir_x and lengthdir_yallow ...

1

I haven't digested all of your code. Consider the effect of using the center of the rear axle as the vehicle's origin and have that point ride the actual Bezier. As such, the car's forward direction is coincident with the tangent. Both of these relate to the path of a real car. The front wheels just need to always point directly toward their next-frame-...

1

I don't know about the rotation part but for the mapping input to rotation you can do the following: (this doesn't go in code) add 32768 to your input getting a value 0-65535 from here you can get your multiplier which is 90/65535 = 0.00137 then to get your rotation distance you can simply multiply your input by your multiplier (this goes in code) ...

1

I figured out the best way to do this is to check the screen size on the device and base a boolean conditional to device on which axis to use. This is tested and working great. // Check the screen layout to determine if the device is a tablet. public boolean isTablet(Context context) { boolean xlarge = ((context.getResources().getConfiguration()....

1

Because the coordinate system that are used in games are based off of the dimension of the monitor. When computer renders anything, it starts at the upper left hand corner which gives the x, and y coordinate of [ 0, 0 ]. As the rendering progresses towards the right side of the screen, the x value increments, respectively when the render moves down, the y ...

Only top voted, non community-wiki answers of a minimum length are eligible