Page 1 of 1

accessing ground-truth kart position

PostPosted: 26 Sep 2014, 06:26
by dmochow
I am a brain researcher using STK as a stimulus whose responses we are recording with EEG.

I am looking to find a way to access the ground-truth _screen_ position of each kart for each frame, so that I can then relate the measured brain signal to the kart position. The code base / data structures are quite expansive, and I am wondering if anybody knows which classes/functions may contain this information. I'm assuming that since each kart has to be rendered on the screen at each frame, that this information must be passed somewhere along the way. My goal is to "intercept" this information from the appropriate function call.

Thanks in advance.

Re: accessing ground-truth kart position

PostPosted: 27 Sep 2014, 20:46
by konstin
I'm neither the physics nor the graphics expert, but I hope I can point you to the right places in the code:

All the code is in the src/ directory in the git-repository (https://github.com/supertuxkart/stk-code). The to relevant classes are Kart (karts/kart.cpp) and Camera (graphics/camera.cpp). To get the position of the kart the camera follows (which is normally the player kart) use Camera::getActiveCamera()->getKart()->getXYZ()->toIrrVector(). The viewport of the camera is returned by Camera::getActiveCamera()->getViewport(). As the computation of the kart position is done by OpenGL and I don't expect you want to change OpenGL, you have to do the computation of the position manually. It shouldn't be to difficult with some vector math and sinus/cosinus. The place to do that is probably the end of Camera::update because this method is called every frame and all important variables can be accessed there without big prefixes.

Re: accessing ground-truth kart position

PostPosted: 28 Sep 2014, 19:28
by dmochow
Konstin,
Thanks so much for pointing me to those methods -- using the camera position is a great idea.

Re: accessing ground-truth kart position

PostPosted: 01 Oct 2014, 23:57
by samuncle
dmochow I'm curious and interested in your project :). What's the usage of stk in this particular topic ? Will you publish some data ? or a paper ?

Re: accessing ground-truth kart position

PostPosted: 03 Oct 2014, 06:32
by dmochow
samuncle, the project is aimed at using brain activity to provide feedback to a player of a video game. the idea is that you can "read out" a player's attention/engagement level with the game by analyzing the neural signals, and then report that back to the player so that he/she can hopefully learn to attain higher levels of focus. stk is open source and a fun game, so a perfect stimulus for our purposes. If you know a lot about the code base, and would like to help, please let me know.

Re: accessing ground-truth kart position

PostPosted: 03 Oct 2014, 13:40
by hiker
Hi,
dmochow {l Wrote}: If you know a lot about the code base, and would like to help, please let me know.

if you have any questions, feel free to send me an email (e.g. here ;) )

Cheers,
Joerg

Re: accessing ground-truth kart position

PostPosted: 04 Oct 2014, 22:01
by dmochow
Joerg, thanks for offering to help.

I've managed to access the (x,y,z) kart position -- I am a bit unsure what the origin of this co-ordinate space is (other than x is left-right, y is vertical, and z is front-back). I ultimately want to relate this position to the screen position, but this requires me knowing how this 3D position is calculated.

Another one of my aims is to extract the button presses (i.e., key left, key right, etc.). I've looked at input_manager.cpp, but there seems to be a high level of abstraction in the handling of input. Do you know which classes/source files would allow me to intercept the player key presses?

Thanks again for being willing to help.

Jacek

Re: accessing ground-truth kart position

PostPosted: 07 Oct 2014, 07:09
by hiker
Hi,

Sorry for the delay, am busy with some other stuff atm. Add the following lines to Kart::update():
{l Code}: {l Select All Code}
    Camera * camera = Camera::getCamera(0);
    irr::scene::ISceneCollisionManager *cm = irr_driver->getSceneManager()->getSceneCollisionManager();
    core::position2di pos = cm->getScreenCoordinatesFrom3DPosition(getXYZ().toIrrVector());
    Log::verbose("kart", "%f %f %f --> %d %d  steer %f",
        getXYZ().getX(),getXYZ().getY(),getXYZ().getZ(),
        pos.X, pos.Y,
        m_controller->getControls()->m_steer);

It will print the kart world coordinates, the corresponding screen coordinates, and as an example the current value of steering (other values like shooting, acceleration etc. are in the same data structure returned by getControls() ). It only works in single player (camera number is hard coded), and not thoroughly tested. Oh, you might need to run with --log=0 in order to see the output.

Hope that helps!
Joerg

Re: accessing ground-truth kart position

PostPosted: 09 Oct 2014, 06:30
by dmochow
Hi Joerg,
That is extremely helpful -- thanks for taking the time to write the script. I will run it on my version and will let you know how it went. Please send me an email (jdmochow AT stanford DOT edu) with your name/affiliation so that I can credit you appropriately in publication of this work.

Thanks,
Jacek

Re: accessing ground-truth kart position

PostPosted: 09 Oct 2014, 10:27
by samuncle
Hi dmochow

I'm glad we are able to help you. I'm the track maker and if you need something custom in a track (like a special section) let me know.

Will you publish a paper about this experiment ? Will it be public ? I'm highly interested to see the results :).

Also Maybe in my very humble opinion, you should credit the supertuxkart dev team. Because we are a team and alone it would be possible to make this game :).