Sign in to follow this  
veeru

help with mouse click to move object

Recommended Posts

I am just learning OpenGL right now and trying to follow the lessons, but i have not gone through each lesson. I am trying to follow the lesson 48 but the author has not explain much in the comments, so i am just not able to follow it properly. if someone can explain me the _mapToSphere function in ArcBall.cpp sourcefile, i would really appreciate.

Share this post


Link to post
Share on other sites
It would maybe help if you would tell the people of what book you speak... which author?
I probably can't help you but someone will ask for the author and book/tutorial anyway...
Maybe you can even post some code with which you are having problems or the error messages if it won't compile.

Share this post


Link to post
Share on other sites
Well start on chapter 1 and not chapter 48.

Quote:
Original post by veeru
I am just learning OpenGL right now and trying to follow the lessons, but i have not gone through each lesson. I am trying to follow the lesson 48...

Share this post


Link to post
Share on other sites
I am already getting to know GL and i went until lesson 25 and i just wanted to know how can OpenGL get mouse event, so i went to lesson 48 and i am not understanding the function _mapToSphere in ArcBall.cpp file and author for lesson 48 did not comment the need or use of that function so i was wondering if anyone has any idea or knowledge of it.

Share this post


Link to post
Share on other sites
Most likely, if it's something simple, you'll just want to move the points of whatever you're drawing around. In the case of OpenGl, glTranslatef() would probably be fine. If you're using Win32 in your program, you could just handle some of the mouse movement functions, and use glTranslatef() accordingly.




float xMove = 0, yMove = 0;

POINT oldPoints, newPoints;
oldPoints.x = 0; oldPoint.y = 0;

....
....
....

// handle the WM_MOUSEMOVE message
case WM_MOUSEMOVE:
{

newPoints.x = HIWORD(lParam);
newPoints.y = LOWORD(lParam);


/*
bassically here you're just checking if the mouse moved in the positive or negative direction for each axis, and add to xMove/yMove accordingly.
Although there's probably a simpler way.
*/
if(newPoints.x > oldPoints.x)
xMove = .5;
else if(newPoints.x > oldPoints.x)
xMove = -.5;
else
xMove = 0;

if(newPoints.y > oldPoints.y)
yMove = .5;
else if(newPoints.y < oldPoints.y);
yMove = -.5;
else
yMove = 0;





glTranslatef(xMove, yMove, 0);

break;
}



Hope that helps a bit.

Share this post


Link to post
Share on other sites

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