09.04.2015, 23:23
Hi. It's no secret I'm rubbish at maths, even though I got an A at school..
I'll try to explain this as clearly as possible. It's relatively complex maths, so please only try and help if you know what you're doing.
I'm trying to adjust an object's rotation to place it on a slope. In this instance, I'm trying to make it so when a spike strip is placed on a sloped surface (e.g. the hills in San Fierro) it adjusts its rotation to that of the hill.
I'm at a good starting point - I've got the Z height of each end of the spike strip relative to the ground using MapAndreas. I just need to work out the rotation to set on the object for it to line up with said points.
To illustrate my problem, I made a diagram:

Point A is the lowest point, and Point B is the highest point (z coordinate). These may be reversed. The red line is the spike strip. As you can see, it's at an angle of about 45 degrees to line up with the points. The question is, how do I get this angle from the Z value of point a and b? The rotation of the object that needs to be changed to match these coordinates is the X rotation. I need to do the same for the Y rotation, but I guess it would be easy to do after I can do the X? If not I'd need to know how to do that also.
I've been researching this for hours, and here are some of the results I've found:
http://stackoverflow.com/questions/7...orizontal-axis
http://math.stackexchange.com/questi...117-833-80-550
http://stackoverflow.com/questions/2...wo-points-java
I've tried intensely to get this to work, but it's not even close. I don't even know if you need to use atan2 or not.
If someone could help me out with this I'd appreciate it so much. Thank you in advance.
NOTES:
- The object's rotation is relative to itself, which makes it easier.
- The object can be placed in any rotation however, which may or may not affect this. I don't think so?
- Angles in GTA:SA are reversed (counter-clockwise). East is 270 when you'd expect it to be 90.
P.S. If you still don't understand what I'm trying to do, please let me know and I'll try and explain it differently.
I'll try to explain this as clearly as possible. It's relatively complex maths, so please only try and help if you know what you're doing.
I'm trying to adjust an object's rotation to place it on a slope. In this instance, I'm trying to make it so when a spike strip is placed on a sloped surface (e.g. the hills in San Fierro) it adjusts its rotation to that of the hill.
I'm at a good starting point - I've got the Z height of each end of the spike strip relative to the ground using MapAndreas. I just need to work out the rotation to set on the object for it to line up with said points.
To illustrate my problem, I made a diagram:

Point A is the lowest point, and Point B is the highest point (z coordinate). These may be reversed. The red line is the spike strip. As you can see, it's at an angle of about 45 degrees to line up with the points. The question is, how do I get this angle from the Z value of point a and b? The rotation of the object that needs to be changed to match these coordinates is the X rotation. I need to do the same for the Y rotation, but I guess it would be easy to do after I can do the X? If not I'd need to know how to do that also.
I've been researching this for hours, and here are some of the results I've found:
http://stackoverflow.com/questions/7...orizontal-axis
http://math.stackexchange.com/questi...117-833-80-550
http://stackoverflow.com/questions/2...wo-points-java
I've tried intensely to get this to work, but it's not even close. I don't even know if you need to use atan2 or not.
If someone could help me out with this I'd appreciate it so much. Thank you in advance.
NOTES:
- The object's rotation is relative to itself, which makes it easier.
- The object can be placed in any rotation however, which may or may not affect this. I don't think so?
- Angles in GTA:SA are reversed (counter-clockwise). East is 270 when you'd expect it to be 90.
P.S. If you still don't understand what I'm trying to do, please let me know and I'll try and explain it differently.