Zheden
Zheden

Reputation: 593

OpenGL convert coordinates of object to another coordinate system

I have two spheres in different coordinate systems:

glMatrixMode( GL_MODELVIEW );

glLoadMatrixf( M1 );
glutWireSphere(70, 15, 15);


glLoadMatrixf( M2 );
glutWireSphere(70, 15, 15);

I want to find position of sphere 2 in coordinate system of first sphere. Could you please help me to do it?

Upvotes: 0

Views: 426

Answers (1)

derhass
derhass

Reputation: 45362

What you have is M1 transforming sphere 1 into eye space, and M2 for sphere 2, so you can use the eye space as the common space which allows you to relate the position between the two. So to transformthe vertices in object space of sphere to into the object space of sphere 1, you just go to common eye space using M2, and than back to object space of sphere 1 by using the inverse of M1. In classic GL notation, that will give you the compound transformation as the matrix

T=inverse(M1)*M2

and any point x in sphere 2's object space will be transformed to x' in sphere 1's object space as

x'=T*x

Upvotes: 1

Related Questions