Transformation of a given point in image through translation and rotation

hi all !!

i’m trying to get the coordinates of a point in an image.
let’s say i know the point i need to know it’s coordinates after a translation and rotation, but i know the coordinates before the transformation and i would like to know where this point has gone after the transformations …

i’ve seen some related posts on the forum but i didn’t figure it out … in pseudo-code.


ofPoint p;
// that's the point i want to know the coordinates 


// here i would like to know where my point p has gone ? 
// where has p  ben transformed to ?

I’ve tried getting the matrix after all the transformations

  float myMatrix[ 16 ];
  glGetFloatv( GL_MODELVIEW_MATRIX, myMatrix );

and then trying to mulitply the point by the matrix i got before …

p =   p*mat ;

But the result i got it’s not where it should …

Can anyone understand what i’m trying to express and solve ?
I tried inverting the matrix point multiplication … but again the result it’s not correct.


Thanks for any clues or advices …

You can check the ofNode class, it has functions showing exactly what you need. It represents a transform, including position (point) rotation and scale.

Check ofNode::getGlobalPosition()

Also, I think you need to get modelview * projection matrix in order to get that multiplication right. There might be a more direct method in OF that I don’t know of

so i should create a ofNode on the point i’m interested on before transform …
then apply the same transformation i’m doing to the image, but to the ofNode
and then calling getGlobalPosition on the node ?

is that the idea ? i’ve never used ofNode with such functions …
by the way i’m multiplying with the modelview matrix as you suggested in the call :
glGetFloatv( GL_MODELVIEW_MATRIX, myMatrix );
on my pseudo-code …

i’ll give it a try !! thanks a lot for the path !!

do you mean where the point is in 3d or where the point is now on the screen in 2d?

ah sorry, I see now:

the problem I think is that the translations that the camera is doing are baked into the mat at this point. If you look at the GL_MODELVIEW_MATRIX at the start of the draw call, you’ll see this is the case. for example, I have a small window 400x200, mat looks like this at the start:

   1,        0,        0,        0
   0,        1,        0,        0
   0,        0,        1,        0
-200,     -100, -173.205,        1

what you could do is keep around a matrix that you could mirror all tranform commands to, ie:

ofMatrix4x4 mat;
mat.translate(200, 0, 0);
cout << ofPoint(100,0) * mat << endl;

I really love ofNode, so @chuckleplant’s advice could also be a good way to go.

hi @zach and all !

thanks for your idea of keeping a matrix with all the transformation commands on it … just works !
i assume that the reason why getting the GL_MODELVIEW_MATRIX straight on is that

the translations that the camera is doing are baked into the mat at this point.

I thought that it was possible to query opengl for the matrix that keeps all the transformations, without any relation to camera … anyway … your solution works !

@chuckleplant i didn’t find a way of working it out with the ofNode approach … ofNode::GetGlobalPosition() seems to don’t do what i expected … as it seems that getGlobalPosition is not taking in consideration the scale o the node so the coordinates are not as i expected. (i’m doing just a scale and rotation over Z).

by the way i’m not on a 3D space … just 2D .
many many thanks … allways learning .

and here is a simple example with what i was trying to get :wink: (81.0 KB)

here is the same thing (matrix) but also with ofNode and ofVec3f

it is a good example to see transformations with several different objects :slight_smile: (53.3 KB)