PDA

View Full Version : Drawing Cylinders from polar coordinates (Max MSP)



patternrecog
06-06-2011, 02:42 AM
I'm using Max MSP to rebuild some motion-tracked coordinates into a 'body' using cylinders. Max MSP has access to a limited set of simple OpenGL commands using its 'jit.gl.sketch' object.

The issue I have is that I can't seem to get the positioning right. I think I have the rotation roughly correct after a few weeks of banging my head against the wall.

Due to the fact Max is a visual programming tool, I can't post exactly what happens, but I can post the commands I give the sketch object.

For each cylinder, the following runs:


glmatrixmode modelview [doesn't seem to make any difference]
glpushmatrix
gltranslate $1 $2 $3 [mid-point between 2 coordinates]
glcolor 0.7 0.7 0.7 1.
glrotate $4 0 1 0 [Y-axis rotation from polar coordinates]
glrotate $5 1 0 0 [X-axis rotation from polar coordinates]
cylinder $7 $7 $6 [radius of each end and length from polar distance]
glpopmatrix

Then after all the cylinders, before the frame is rendered:


glclear
reset

I have created a simple test situation, with points at

0,0,1
0,1,0
1,0,0
0,0,0,

I join them into 4 pairs, and find the polar coordinates. This should result in a right-angle triangle on the positive XY plane at 0, and a line stretching down the Z axis to 1.

Instead I see:
http://i.imgur.com/hQirD.jpg

Now the rotation I can fix later by flipping some numbers/coordinates, but I can't figure out whats happening with the points where the cylinders intersect.

I think there might be some 'drift' coming from each translation, but I don't know how. Theres a command I think is Max MSP only (moveto) I can use instead of translate, but it results in a similar situation (only with everything closer together).

The 'z' axis cylinder appears to be in a weird spot that is level with the midpoint of the hypoteneuse.

Thats essentially a summary of the problem, but I'll include some more information for anyone who's curious:

The coordinates are as follows:


0.000 0.100 0.000
0.000 0.000 0.000
0.100 0.000 0.000
0.000 0.000 0.100

paired by this list (the intial 0s on each are just because they're stored in a 2d matrix)


0 1 0 2,
0 2 0 3,
0 2 0 4,
0 1 0 3

Run through a cartesian to polar coordinates object (output example):

90. -0. 0.1 [azimuth, elevation, distance]

which is fed into the gl commands above.

I'm neither a real programmer or any good with maths, so I appreciate any help I can get.