![]() ![]() The icons for turrets that are forward and left or right are pushed to the center, while anything behind is still following the vehicle’s rotation. In this short article, we would like to show how to rotate any vector 2D to the right side (90 degrees) using Javascript. Here is my function to transform a 2D vectors components under rotation. I just added a check to see what side of the ship WorldNorth was on and then multiplied the OffsetAngle by -1 or 1 depending on the result.īUUUT… it only works for the one turret that is dead forward and center of the vehicles location. Now I just need to get it to do that for the east side as well… The turret icon, will follow the rotation of the vehicle when it is turning east, but remain fixed to the top of the screen(this is what I want!) when the vehicle is facing west. The resulting OffsetAngle is always positive, climbs to 180 as the vehicle turns south, then falls back to 0 when turning to face north again. OutVector = (CompPos - Center).RotateAngleAxis(OffsetAngle, Up) It only really makes sense to apply a 2D rotation to a 2D vector to obtain the transformed coordinates. You are trying to multiply a 7圆 matrix with a 2x2 matrix. Jwatte’s last suggestion has lead me to getting something that half works:įVector CompDIR = (Center - CompPos).GetSafeNormal() įloat OffsetAngle = FMath::RadiansToDegrees(acosf(FVector:: DotProduct(CompDIR, WorldNorth))) Matrix dimensions will need to be compatible in order to obtain a matrix product. I need the group to always be oriented towards the top of the screen. The problem is that the turret position icons(the whole group of them not each individual icon) turn to match the vehicles facing. I am trying to represent those weapon turret actors onto a HUD Menu that is supposed to display a top down of the vehicle, and icons representing its turrets at the turret positions. I have a vehicle that has several weapon turret actors attached. (Point - Center) -> RotateAroundAxis(Up, Amount) -> (+ Center) This is different from what’s traditionally meant by “rotating a vector around a vector.” However, when you say “location vector” it sounds like you’re using “points.” While you can “rotate a point around a point,” that means subtracting the center point from the point, then rotating around your rotation vector (up?), then adding back the location of the center point. You will want to verify that the magnitude of the cross is not very close to zero (as in, the two vectors are nearly co-linear) and if that happens, use some default axis vector (or not rotate.) If the other vector is in the plane of rotation, then cross the two vectors and normalize to get the axis of rotation. If the other vector is an axis, then just normalize it, and plug it in as the axis in RotateAngleAxis. ![]() What does “around the other” really mean? Do you have two points, and one point is the “center”? It’s unclear from your question whether the other vector is actually a rotation axis, or another vector in the plane of rotation. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |