Forums

Full Version: viewer-centered perspective and hand-tracked steering
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear vdrift guys,

I'm posting here with the purpose of requesting for some hints about vdrift modification. I'm attending a Virtual Reality course in my university, and part of the final grade is given by a project/demo where we've to use physical simulation and head-and-hand tracking. My idea is to modify the vdrift source code, adding these features:

- inside-car camera view based on head position: using opencv, track the head position and modify what the player sees depending on his head position (something like this http://www.youtube.com/watch?v=KLz3IscAT...04F208119C);
- handle the steering wheel tracking a marker used by the player as a real wheel (e.g. using a sheet of paper with a marker drawn on it, tracking the marker to get the corresponding rotation);
- physical simulation: I've still no idea how to add something related to physic simulation on my planned vdrift modification. Maybe just some objects (dice, a cup of coffe, this kind of simple stupid things...) that move inside the car as it turns.

I've still to check the source code and figure out if this kind of modifications are feasible in the short period of time I have (about one month). I think I'll go through the code during the weekend. By the way, any kind of advice is really appreciated, as well as your ideas about the feasibility of the project.

Best,
Daniele
Hacking the tracking should be simple. You can override the inputs in void GAME::UpdateCarInputs(CAR & car) game.cpp.

Quote:physical simulation
You could implement a btRigidBody based camera. Attach it with a constraint to the car body. This would allow to simulate head movement due to inertia.
Thanks for the suggestion NaN, but could you please be a bit more precise? Hacking the camera view was very easy (I just created a new class inheriting from CAMERA_MOTION ... btw, the code is very clear and easy to understand even without a lot of documentation Wink ), but "injecting" the code for the marker-tracking based steering seems less trivial. Probably I can just put all the code in the ProcessSteering method of CONTROLMAP_LOCAL class, but, if possible, I would like to nicely integrate it with the rest of the code.

Thanks for any kind of hint,
Daniele
Quote:but "injecting" the code for the marker-tracking based steering seems less trivial
The most simple way would be to override carinputs[CARINPUT::STEER_LEFT] and carinputs[CARINPUT::STEER_RIGHT] just before car.HandleInputs(carinputs, TickPeriod()); in void GAME::UpdateCarInputs(CAR & car). The value range is [0, 1].

A more sophisticated approach might be to hook your code as a JOYSTICK to EVENTSYSTEM_SDL. And add your input polling code to void EVENTSYSTEM_SDL:TonguerocessEvents().
If you don't want to mess too much with the EVENTSYSTEM_SDL make Init() and ProcessEvents() virtual and derive from it.
NaN Wrote:A more sophisticated approach might be to hook your code as a JOYSTICK to EVENTSYSTEM_SDL. And add your input polling code to void EVENTSYSTEM_SDL:TonguerocessEvents().
I followed your approach: I've extended the JOYSTICK and added an extra fake axis mapped to the marker tracker. Furthermore, inside the PrecessEvents method, I had a loop over all joypads for updating the fake axis. It looks like it's working (both my setAxis and getAxis methods get called, as well as the one of the original JOYSTICK, which means that I don't lose the original joypad functionallities Wink ). The problem is that, when in the control-editing window I try to add a new control, the fake axis never gets recognized. That means, the if below return always false

Code:
                for (int i = 0; i < eventsystem.GetNumAxes(j) && !have_a_control_input; i++)
                {
                    //std::cout << "joy " << j << " axis " << i << ": " << eventsystem.GetJoyAxis(j, i) << endl;

                    assert(j < (int)controlgrab_joystick_state.size());
                    assert(i < controlgrab_joystick_state[j].GetNumAxes());

                    if (eventsystem.GetJoyAxis(j, i) - controlgrab_joystick_state[j].GetAxis(i) > 0.4 && !have_a_control_input)
                    {
                        have_a_control_input = true;

                        carcontrols_local.second.AddInputJoyAxis(controlgrab_input, controlgrab_analog,
                                controlgrab_only_one, j, i, "positive", error_output);
                    }

                    if (eventsystem.GetJoyAxis(j, i) - controlgrab_joystick_state[j].GetAxis(i) < -0.4 && !have_a_control_input)
                    {
                        have_a_control_input = true;

                        carcontrols_local.second.AddInputJoyAxis(controlgrab_input, controlgrab_analog,
                                controlgrab_only_one, j, i, "negative", error_output);
                    }
                }
            }

Which is the meaning of this subtraction?

Code:
eventsystem.GetJoyAxis(j, i) - controlgrab_joystick_state[j].GetAxis(i)

Why replicating the vector of joysticks? I'm missing something here ...
I haven't really looked into the input code yet. But yeah, the control setup code could use some refactoring being scattered over multiple files.

Code:
eventsystem.GetJoyAxis(j, i) - controlgrab_joystick_state[j].GetAxis(i) > 0.4
It looks like the setup only accepts an input axis if the input delta is greater then 0.4. Maybe to deal with non centered axes? It would make sense for a mouse. Just guessing here, don't have a joystick to check.
NaN Wrote:It looks like the setup only accepts an input axis if the input delta is greater then 0.4. Maybe to deal with non centered axes?

Yep, that's why. If you have a joystick input that is noisy it would immediately assign the control to that axis without that bit of code.
Hi mUogoro, are you still wokring on that project? Me and my friend have the same aim as you and would like to join your development/code!
Wow I didn't knew anything about it! Any of you can fork the project from github do any modifications and they can be merged into the project! This is very cool, please continue on it!