UV offset not offsetting correctly - unreal-engine4

I was playing around with uv offset in unreal-engine 4. So Far I learned that the origin starts at the upper left hand corner and U scales from 0 to 1 from left to right and V from top to bottom. For a texture, if I add some constant value lets say 0.25 to U it should shift to right but it is shifting to left. same with adding or subtracting with V. Its like the axes are inverted or something. So Where am I going wrong?

Related

2D box collision if the box rotates

I'll keep the question short.
I'm making a 2D game.
I have an object, but since it has many pieces, I just out it in a box to have it's hitbox.
If it's going up/down/left/right at perfect angles, I can check for collision because it's just about the left corner and then height and width.
How do I calculate if my mouseX and mouseY collide with it if it rotates at different angles.
Found a formula that x' = x sin A - y cos A or something, but didn't work.
Thank you!

Unity Rotate Sphere To Point Directly Upwards Based On Child Point

I've got a 3d sphere which I've been able to plot a point on using longitude and latitude thanks to some work of another developer I've found online. I think I understand what its doing.
What I need to do now is rotate my planet so the point is always at the top most point (ie the north pole) but I'm not sure how to do this. I'm probably missing some important fundamentals here so I'm hoping the answer can assist in my future learning.
Here's an image showing what I have - The blue line is a line coming from the longitude and latitude I have plotted and I need to rotate the planet so that line is basically pointing directly upwards.
https://ibb.co/2y24FxS
If anyone is able to advise it'd be very much appreciated.
If I'm not mistaken, Unity uses a coordinate system where the y-axis points up.
If the point on your sphere was in the xy-plane, you'd just have to determine the angle between the radius-vector (starts in the center of the sphere, ends on the point in question) and the y-axis, and than rotate by that amount around the z-axis, so that the radius vector becomes vertical. But your point is at an arbitrary location in 3D space - see the image below. So one way to go about it is to first bring the point to the xy-plane, then continue from there.
Calculate the radius vector, which is just r = x-sphereCenter. Make a copy of it, set y to zero, so that you have (x, 0, z) - which is just the projection of the vector r on the horizontal xz-plane - let's call the copy rXZ.
Determine the signed angle between the x-axis and rXZ (use Vector3.SignedAngle(xAxis, rXZ, yAxis), see docs), and create a rotation matrix M1 that rotates the sphere in the opposite direction around the vertical (negate the angle). This should place your point in the xy-plane.
Now determine the angle between r and the y-axis (Vector3.SignedAngle(r, yAxis, zAxis)), and create a new rotation matrix M2 that rotates by that angle around the zAxis. (I think for this second one, the simpler Vector3.Angle will work as well.)
So, what you want now is to combine the two matrices (by multiplying them) into a single transform (I'm assuming this is a transformation in the local coordinate system of the sphere, where (0, 0, 0) is the sphere's center). If I'm not mistaken, Unity uses column-major matrices, so the multiplication order should be M = M2 * M1 (the rightmost matrix is applied first).
Reorient your globe using M as a local transform, and it should bring your point to the top. You can also create M3 = M1.inverse, and then do M = M3 * M2 * M1, to preserve the original angular offset from the xy-plane.
Check for edge cases, such as r already being vertical (pointing straight up, or straight down).

matlab: calculate the degree given two points in an image

The goal is to rotate an image so that the bounding boxes including the hand instances are all axis aligned. Please see the following examples. The first image is the original one and the second image is the rotated version where the left hand (It's left in the image) is axis aligned and the third image is also a rotated version where the right hand is axis aligned.
Now given four points indicating the hand bounding box, we have to calculate the rotated degree. Let me take the left hand (It's left in the original image) as an example. Assuming the four points are [p1_x, p1_y], [p2_x, p2_y], [p3_x, p3_y], [p4_x, p4_y]. The line formed by[p1_x, p1_y] and [p2_x, p2_y] indicates the wrist and p1, p2, p3, p4 are clockwise. So the yellow line is formed by p1_x, p1_y] and [p4_x, p4_y].
My idea is the calculate the degree between the yellow line and the horizontal axis. For the left hand, the degree is about -10 and for the right hand the degree is about -110.
My problem is how to calculate these degrees?
Useatan2d to calculate the 4-quadrant inverse arctangent. For the line segment joining [p1_x, p1_y] and [p4_x, p4_y], do:
atan2d(p4_y-p1_y,p4_x-p1_x)

DirectX and Negative Scale

I am starting to experiment with some DirectX type stuff, and I had a question about the scaling matrices. If I set my view matrix to:
XMMatrixTranspose(XMMatrixIdentity() * XMMatrixScaling(1.0f,2.0f,1.0f))
Then everything (a centered square) on the y-axis appears twice as big, which is what I expect. If I set it to a negative number, ala:
XMMatrixScaling(1.0f,-2.0f,1.0f)
Then everything disappears. In fact, if I set any value of the scale matrix to < 0 then nothing shows up. I was expecting that the image would just be 'flipped' along the corresponding axis, but it just doesn't show up at all. Is it possible to use negative values when scaling, or am I just doing something completely wrong ??
This is caused by back-face culling and clipping. Assuming you have culling enabled (on by default), when you set the scale of the x or y axis to negative, it flips the winding order of all the triangles. This causes all the triangles to be considered "backwards" and the GPU doesn't draw them. Assuming you have no other transformation matrices applied, and the square is in the x-y plane, flipping the z sign doesn't cause the triangles to be back-facing, but rather just causes the square to be outside the viewport (e.g. moving from z = 0.5, halfway inside the veiwport depth range, to z = -0.5, outside the viewport depth range).
Back-face culling is a performance optimization since most 3D scenes have closed geometry (or at least, they don't let you see the open parts). This means that every backward facing triangle should have a front facing triangle that covers it, so there's no point in drawing the backward ones. This sometimes isn't always true though, if you've ever played a game and gotten too close to a rock or wall, and been able to see through the whole object, that's because you've clipped through the front, and since the other side is back-facing, it doesn't get drawn.

Find a point on a circle circumference based on degrees

Let's say that you have a stick figure. Let's say the stick figure has an elbow and a hand. What if the stick figure wants to spin his hand in a windmill without moving his elbow? If the elbow serves as the center of a circle, and the hand must always be on the circle's circumference, and I know the exact location of the elbow and hand, how do I move the hand around the circle's circumference, while preserving the radius (the length of the arm between the elbow and hand because it really shouldn't shrink or grow)?
I need to move the coordinate of the hand along the circumference of a circle, where the center of the circle is the elbow. This is in 2D.
I have the coordinates of both points. I can calculate the radius which is the length of the line between the points. Knowing the circle's center and radius, how do I rotate the hand along the circle circumference? I want it to maintain the radius, but change positions on the circumference. Basically, it must act like it's hinged.
P.S: I had a picture, but Stack Overflow said I was too new... Blame Stack Overflow.
Basic trigonometry says:
x = r * cos(a);
y = r * sin(a);
This does not take into account the rotation of the hand, just shows the point on the circle where the wrist will be. Is that what you are after?
EDIT: Sorry, that assumes the elbow is at (0, 0) and x +ve is right and y +ve is up.
Given the elbow is at (ex, ey) then wrist is at:
wx = ex + r * cos(a);
wy = ey + r * sin(a);
If, as happens in browsers, y is +ve down, then subtract instead of add.