Advertisement

Getting vertex coordinates

Started by July 30, 2003 01:20 PM
9 comments, last by Squalion 21 years, 7 months ago
Ok, I'd like to know the x,y,z of each vertex of a square, when it's being rotated, so atm I defined each vertex using variables like ax,ay,az, bx, cx, dx etc, and then having a function print them in a corner of the screen..I was wondering if there's an easier, more direct method? something like GL_GET_VERTEX or similiar, if it exists. [edited by - Squalion on July 30, 2003 2:20:38 PM]
lol
quote:
Original post by Squalion
Ok, I'd like to know the x,y,z of each vertex of a square, when it's being rotated, so atm I defined each vertex using variables like ax,ay,az, bx, cx, dx etc, and then having a function print them in a corner of the screen..I was wondering if there's an easier, more direct method? something like GL_GET_VERTEX or similiar, if it exists.
<


Multiply the vertices with the model(view) matrix.
You can get the matrix with glGetDoublev(GL_MODELVIEW_MATRIX, matrix);.

double m[16]; // Model matix
float v[3]; // Vector
float result[3];
glGetDoublev(GL_MODELVIEW_MATRIX, m);
result[0]=m[12]+m[0]*v[0]+m[4]*v[1]+m[8]*v[2];
result[1]=m[13]+m[1]*v[0]+m[5]*v[1]+m[9]*v[2];
result[2]=m[14]+m[2]*v[0]+m[6]*v[1]+m[10]*v[2];

[edited by - circuit on July 30, 2003 5:07:07 PM]
Advertisement
thanks a lot just realised my code didnt work, it set up the vertexes and also displayed them onscreen, but they remained static..duh ><

ty
lol
that throws up 14 errors, mostly about converting ''int'' to ''int[x]'' and stuff @_@
lol
Ok i changed ''Matrix'' to ''m'' and now it works, but still doesnt update the vertex positions...
lol
The OpenGL hardware doesn't support the return values jet, not even the OpenGL 2.0 compatible(Wildcat VP driver isue). But the return values are ment to be suported on OpenGL 2.0 hardware.
But for now hardware is just taking data into the pipeline.

Circuit meant for you to calculate the values with the main CPU("by your self") by tranforming them with model view matrix, he even wrote down the calculations for the tranform.

[edited by - Klemen on July 31, 2003 9:49:08 AM]
Advertisement
I see..how would I define ''v''? atm it just gives me values of 0, 0, and 5, for the x,y,z of the first point, even though even at the start they''re -1,-1, 0.
lol
It''s all written in circuit''s reply, just read it carefully.
v is vector m is matrix, the matrix is double type array of 16 values, vector is float type array of 3 values.
I understand that much, but where is v defined?
lol
v are your vertices, he just gave an example, it doesn''t have to be an array it can be a class it can be a pointer array

This topic is closed to new replies.

Advertisement