# Q: how to draw a 2D square in a 3D space?

Hi,

I want to draw a 2-D square. It is positioned at a specified 3D location but its shape on the user’s screen should be always a square with the same size regardless of translation, rotation, etc. How can I do this? Could someone help me? Thanks.

Regards.

Tony

Get the modelview matrix using glGetDoublev
Fill first 3X3 square in this matrix by
100
010
001
to eliminate rotation.
Extract depth from bottom row of matrix.
Calculate width like w = z*w1/z1 , where z is current depth, w1 is a width desired on z1 depth(this koefficient can be found using some trig).

Hope that helped.

Randy

This is my old particles code, hope it helps…

matrix_t modelView;
Vector3 x;
Vector3 a;
Vector3 b;
Vector3 c;

glGetFloatv(GL_MODELVIEW_MATRIX, modelView);

x.x = modelView[0];
x.y = modelView[4];
x.z = modelView[8];

y.x = modelView[1];
y.y = modelView[5];
y.z = modelView[9];

size = parts[i].GetSize();

a = parts[i].GetPos() + ((-x - y) * size);
b = parts[i].GetPos() + ((x - y) * size);
c = parts[i].GetPos() + ((x + y) * size);

//vertex 1
vertici[i*3].x = a.x;
vertici[i*3].y = a.y;
vertici[i*3].z = a.z;
//vertex 2
vertici[(i3)+1].x = b.x;
vertici[(i
3)+1].y = b.y;
vertici[(i3)+1].z = b.z;
//vertex 3
vertici[(i
3)+2].x = c.x;
vertici[(i3)+2].y = c.y;
vertici[(i
3)+2].z = c.z;

Hope it helps

Thanks Randy and rIO for your help. The messages surely give me enough lead to solve my problem. Your kindness and time are very appreciated.

Tony