problem with rotating using mouse

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
cr33
Posts: 22
Joined: Fri Mar 27, 2009 3:37 pm

problem with rotating using mouse

Post by cr33 »

when i try to calculate rotation from mouse cursor x,y coordinates everything is ok but spinning is constant and its hard to 'aim' at 1spot. so i wanted to suppress the spin by putting mouse cursor closer to the centre. however, this only works when cursor is at the bottom right quarter of screen: at resolution 1024/768 mouse returns to exactly 512,384... in other cases cursor stops at 494,369 and sometimes cannot be moved. i've used vector interpolation here.

Code: Select all

void update_mRot(ISceneNode * nodee) {

    vector2df rotation(0,0);
    vector2df center(cenW,cenH); // cenW,cenH = center of the screen


    f32 xrot=0;
    f32 yrot=0;
    if (my > cenH)
        xrot=(((my-cenH)/ROTSPEED)); // ROTSPEED = 80.0
    else if (my < cenH)
        xrot=-(((cenH-my)/ROTSPEED));
   // else if (my == cenH) xrot=0;

    if (mx > cenW)
        yrot=(((mx-cenW)/ROTSPEED));
    else if (mx < cenW)
        yrot=-(((cenW-mx)/ROTSPEED));
   // else if (mx == cenW) xrot=0;
    rotation.X=xrot;
    rotation.Y=yrot;

    turn(nodee, rotation.Y*ROTSPEED);  // <---- turn,pitch functions from Freeflight thread
                                           
    pitch(nodee, rotation.X*ROTSPEED);    
    center = center.getInterpolated(vector2df(mx,my), 2*frameDeltaTime);
    mx = center.X;
    my = center.Y;
    std::cout << mx << "  " << my << std::endl;
    device->getCursorControl()->setPosition(mx,my);


}

what it is supposed to do is: rotate the node relatively to mouse movement - the further mouse is from center of the screen the faster spin is. at the same time mouse cursor is pushed to the center, what causes loss of rotating speed if u know what i mean :P (coz its kind of hard to keep the 'node' in 1 position if cursor is not exactly at center)

i've tried to find some similiar threads but i couldn't find anything suitable

how this is supposed to be done anyway? is this a correct approach? i dunno how to control the node using mouse other way
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

normally the mouse would be locked to the center and set invisable. a crosshair normally replaces this.

the crosshair mouse should have a 2d box limit and the closer you get to the outside of the box the faster it spins. the box is used to keep the range of motion smaller then the total screen size. and to keep the crosshair within visable range of the screen space.

play the game freelancer and you'll see what I mean.

| | . | | <--- like that
Post Reply