Jump to content

camera look question


aiaf
 Share

Recommended Posts

I select a model in the scene then move around, rotate camera,

then i want to move the mouse over the previous selection

 

In some class i have this code for the camera, called in the main loop:

 camera->Move(camMovement);

 currentMousePosition = window->GetMousePosition();
 mouseDifference.x = currentMousePosition.x - centerMouse.x;
 mouseDifference.y = currentMousePosition.y - centerMouse.y;

 camRotation.x += Math::Round(mouseDifference.y / mouseSensitivity);
 camRotation.y += Math::Round(mouseDifference.x / mouseSensitivity);

 camera->SetRotation(camRotation);

 window->SetMousePosition(centerMouse.x, centerMouse.y);

 

Currently i try like this, this code is only executed once when i press space:

 

 Vec3 cu = currentUnit->GetModel()->GetPosition(true);
 Vec3 sp = camera->Project(cu);
 window->SetMousePosition(sp.x, sp.y);
 System::Print(String(sp.x) + " " + String(sp.y));

 

This kind of works but it moves the cursor sligthly off the model (seems related to SetMousePosition being called in the main loop).If i press space 3 4 times it gets in the right position.

 

Anyone can help with this ? run out of ideas maybe i should try another approach

 

Thanks

I made this with Leadwerks/UAK:

Structura Stacky Desktop Edition

Website:

Binary Station

Link to comment
Share on other sites

You are not showing enough information to be able to see or replicate the problem. What is setting the values for the 'centerMouse.x' and 'centerMouse.y' variables? And which 'window:SetMousePosition()' is occurring first/last? The one in the main loop or the one when the SPACE key is pressed?

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

This is in the camera constructor:

centerMouse = Vec2(Math::Round(context->GetWidth()/2), Math::Round(context->GetHeight()/2));

 

The camera update occurs in player->Loop and the space is pressed in console->Loop.

    running = console->Loop();
    player->Loop(window);

 

SetMousePosition is getting executed every loop in player->Loop.

Someone press space one call in consoleLoop, then it goes on until closed in player->Loop.

I made this with Leadwerks/UAK:

Structura Stacky Desktop Edition

Website:

Binary Station

Link to comment
Share on other sites

Nevermind this post, this was me not passing a parameter by reference, didnt need the Project function

 

Vec3 cu = currentUnit->GetModel()->GetPosition(true);
camera->SetPosition(cu.x, cu.y, cu.z - 7);
camRotation->x = 0;
camRotation->y = 0;

camera->SetRotation(*camRotation);

I made this with Leadwerks/UAK:

Structura Stacky Desktop Edition

Website:

Binary Station

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...