URGENT! Rotating an object based on mouseX position
in
Programming Questions
•
2 years ago
I have an assessment due very soon and I've spent the past 3 days melting my brain trying to figure this out.
I have an object and I want to rotate it from a range of 60 degrees to the left and 60 degrees to the right based on the mouseX position, so as I move the mouse from left to right, the object should be smoothly swinging left to right. I have to do this without using an if statement.
All I have is that I need to convert the mouseX location into the range [0, 1] which I put as:
- float mouseXPosition = (float)mouseX/width;
Now I am having trouble with converting this number to the required angles and limiting the angle to just 60 to the left and 60 to the right. I apologize if this is a basic question but I've looked all over and could not find any functions that could help me with this. I did find the atan2(); function but I am not sure how to use it with this as I am not basing the rotation on mouseY position.
Any hints in this matter would be greatly appreciated!! I need to figure this out soon! Thank you!
1