Sign in to follow this  

Mouse Rotation

This topic is 4197 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my DJ turntable simulation, I have it to where if the mouse is over the vinyl, and you hold the left mouse button, you can rotate the vinyl freely, which even has the mouse cursor rotating with it. However, I was only able to make it to where the up/left movement rotates it counter clockwise, and the down/right movement rotating it clockwise. You can see what I mean in this, which has my source code and exe: DJ.zip But theres a problem with that. If the cursor is gonna be on the left side of the vinyl, it gets confusing to whats up and down because it seems like it reversed! I want to make it to where, for example, if the mouse cursor was all the way on the bottom of the vinyl and I move my mouse in the X direction towards the left/right, and as it reaches more to the left/right of this circle, it will be harder for the cursor to travel in the X direction, forcing me to go in the Y direction with the mouse to continue the circular path. The same will hold true for the other parts of this circular path, only with Y, it'll be harder for it to move as it reaches closer to the top/bottom. It's gonna probably take some trig to solve this, and I couldn't do it on my own. I even tried cheating it using if statements, but it ended up like crap. I'm using DirectInput with the mouse in case anyone asks. Thanks in advance.

Share this post


Link to post
Share on other sites
call the center of the record (0,0)
call the mouse position (x,y)
call the rotation (in radians) of the record theta
up and right are positive, down and left are negative

if (x == 0)
{
if (y >= 0)
theta = pi / 2;
if (y < 0)
theta = 3 * (pi / 2);
}
else
{
theta = atan(y/x);
if (x < 0)
theta += pi;
}


uncompiled code, there may be errors.

Share this post


Link to post
Share on other sites
A very interesting program. You have done a good job so far.

Perhaps you could control the movement of the pointer by monitoring the actual mouse movement delta and timesing it by a vynal pixel poisition dependent value between 0 and 1 with the inner circle approching 1 and decreasing rapidly to 0 at the outer circle. You could then set the pointer to the computed value using setCursorPos. This would give the impression of increasing resistance on the surface.

Well thats just my idea, I hope it your project works out ok.

Alex

Share this post


Link to post
Share on other sites
or you can just use

RADIAN = 57.295
theta = atan2(x,y) * RADIAN; // inverse tangent that checks all 4 quadrants and divide by zero and returns angle

given the center of the record is (0,0). If not...

delta_x = disc_x - mouse_x;
delta_y = disc_y - mouse_y;

theta = atan2(delta_x,delta_y) * RADIAN;



Share this post


Link to post
Share on other sites

This topic is 4197 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this