SoftPixel Forum

Official community of the SoftPixel Engine and the SoftPixel Sandbox (REGISTRATION only with consultation with the Admin)
It is currently Fri May 25, 2018 11:11 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Jan 20, 2014 6:12 pm 
Offline

Joined: Tue Jan 07, 2014 6:38 pm
Posts: 90
Location: Germany
(Solution at first reply)

Hello, me again.
I want to make a fp-camera.
Here is what o have tried:
Code:
int mousex;
int mousey;
//...
while (mainloop)
{
    int mousediffx = spControl-> getCursorPosition ().X - mousex;
    int mousediffy = spControl-> getCursorPosition ().Y - mousey;
    Cam-> getTransformation ()-> turn (dim::vector3df (mousediffy, mousediffx, 0));
}

It works almost fine, but it rotates LOCAL, so you are often making a roll or sth. like that.
So i want to ask, if i can rotate GLOBAL.
Thanks.


Top
 Profile  
 
PostPosted: Mon Jan 20, 2014 8:23 pm 
Offline

Joined: Tue Jan 07, 2014 6:38 pm
Posts: 90
Location: Germany
I did it on an other way:
Code:
//Global
float pitch = 0, yaw = 0;
int resX = GetSystemMetrics (SM_CXSCREEN);
int resY = GetSystemMetrics (SM_CYSCREEN);
//...
while (mainloop)
{
    int mousediffx = spControl->getCursorPosition().X - (resX / 2);
    int mousediffy = spControl->getCursorPosition().Y - (resY / 2);
    pitch += mousediffy / GameFPS * 20;
    yaw += mousediffx / GameFPS * 20;
    if (yaw > 360) yaw = 0;
    if (yaw < 0) yaw = 360;
    if (pitch > 90) pitch = 90;
    if (pitch < -90) pitch = -90;
    Cam->setRotation(dim::vector3df (pitch, yaw, 0));
    SetCursorPos (resX / 2, resY / 2);
}

Its maybe not the best solution, but the best i found.
Im open for improvements :)


Top
 Profile  
 
PostPosted: Tue Jan 21, 2014 6:55 pm 
Offline
Site Admin
User avatar

Joined: Sat Jul 07, 2012 5:58 pm
Posts: 540
Location: Germany
Your second solution looks ok. But you can also take a look at the implementation of the tool::Toolset::moveCameraFree function in the SVN Repository.
It looks pretty similar.

The transformation functions "move" and "turn" change the transformation but
the function "setPosition" and "setRotation" set the transformation.

( Mh, It seems the "io::InputController" class is not contained in the API Docu :-( , look in the SVN Repo for the InputController)
By the way: use io::InputController::getCursorSpeed instead of getCursorPosition ;-)

_________________
My latest project:
- The XièXiè Programming Language

My hardware:
- GIGABYTE GeForce GTX 670
- Intel Core i7 (Ivy-Bridge)
- 16 GB DDR3


Top
 Profile  
 
PostPosted: Fri Jan 24, 2014 2:57 pm 
Offline

Joined: Tue Jan 07, 2014 6:38 pm
Posts: 90
Location: Germany
Thanks.
and i have now more, because now physics(bullet) is included


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group