# How to get position of obs_source?



## Frosti (May 27, 2016)

Hey guys,

I'm trying to write a filter plugin to let the associated scene item randomly fidget for a while on the whole screen, triggered by a hotkey.
The last missing piece is to retrieve the position of the obs_source object to know how far it can be shifted in the 4 directions. There exists the obs_sceneitem_get_pos function, but I haven't found a way to get the obs_sceneitem from an obs_source. Another approach would be to use a vertex shader, add the randomly generated offset to vert_out.pos.xy and take this position modulo the two coordinate boundaries, but then the texture will be stretched all over the screen. (btw. what are the coordinates for the right and top edge in GLSL?)

Thanks in advance,
Frosti


----------



## Jim (Jun 1, 2016)

You can't technically get the position of the source from the source itself without examining the current matrix.

Instead, you should be modifying the source to shift left/right as much as you see fit, treating the source as though it were at position 0,0.  Then, just apply a matrix and draw it in the custom way desired.

If you're making some sort of "shake" filter, I'd just recommend drawing the source with a matrix like that.  You don't even need a custom/special effect to just modify its position.


----------



## Frosti (Jun 10, 2016)

Thanks Jim for the hint with the matrix, which led me to the solution.

Now I just set the entries viewProj[3][0] and viewProj[3][1] of the view projection matrix to the desired x and y coordinates (each between -1 and 1) and it works.


----------



## Jim (Jun 11, 2016)

You're not supposed to modify the viewProj.  You're supposed to use gs_matrix_* functions (inside of gs_matrix_push and gs_matrix_pop).


----------



## Jim (Jun 11, 2016)

Oh, actually if you're in a shader I suppose that's fine.


----------

