# Billborad is not aligned to view

This topic is 664 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey guys,

I try to set up Billboards in my programm, but it does not work at all.

My "testplane" can be seen, but its not rotating according to the view.

See this image (from side view) for detail.

So this is what I got..

As you can see, I want to use the Billboards as Tree leaves.

The code for the white plane is the following:

glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glUseProgram(0);

glGetFloatv(GL_PROJECTION_MATRIX, @Matrix);
Right:= Vectorize(Matrix[0,0], Matrix[0,1], Matrix[0,2]);
Up:=    Vectorize(Matrix[1,0], Matrix[1,1], Matrix[1,2]);

glPushMatrix;
glColor3f(1,1,1);
glVertex3f(3 +Right.X+Up.X, 0+Right.Y+Up.Y, 3 +Right.Z+Up.Z);
glVertex3f(-3-Right.X+Up.X, 0-Right.Y+Up.Y, 3 -Right.Z+Up.Z);
glVertex3f(-3-Right.X-Up.X, 0-Right.Y-Up.Y, -3-Right.Z-Up.Z);
glVertex3f(3 +Right.X-Up.X, 0+Right.Y-Up.Y, -3+Right.Z-Up.Z);
glEnd;
glPopMatrix;

glEnable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);


Can you tell me my mistake?

##### Share on other sites

Why are you pushing the matrix when you aren't using it? (and more importantly, you aren't even calling the matrix functions, not using the parenthesis means they're function pointers instead and on their own they do absolutely nothing)

Anyway, I'd argue that probably the easiest way for you would be to rotate (glRotate3f) the billboard the same angle as the camera, but the other way (i.e. -angle instead of angle). Less headaches to cope with. And if you ever switch to a more modern API than the old OpenGL 1.1, remember you can do whatever is the equivalent there.

##### Share on other sites
Well, Im aware that glBegin is not the most modern way to work with, but I was learning it in this way, and it still works fine for me. Im just a hobby programmer without any specific knowledge ;)

Can you give me a tip how to get the angles of the "camera"? Like said, Im no professional so I need a bit more information.

##### Share on other sites

As far as i remember you need to get GL_MODELVIEW_MATRIX

then you get

BillboardX.x = mvm[0];
BillboardX.y = mvm[4];
BillboardX.z = mvm[8];

BillboardY.x = mvm[1];
BillboardY.y = mvm[5];
BillboardY.z = mvm[9];

those are yours worldspace up and right vectors

then

verts[i*4].v.x = particles[i].pos.x-BillboardX.x*particles[i].size+BillboardY.x*particles[i].size;
verts[i*4].v.y = particles[i].pos.y-BillboardX.y*particles[i].size+BillboardY.y*particles[i].size;
verts[i*4].v.z = particles[i].pos.z-BillboardX.z*particles[i].size+BillboardY.z*particles[i].size;

verts[i*4+1].v.x = particles[i].pos.x+BillboardX.x*particles[i].size+BillboardY.x*particles[i].size;
verts[i*4+1].v.y = particles[i].pos.y+BillboardX.y*particles[i].size+BillboardY.y*particles[i].size;
verts[i*4+1].v.z = particles[i].pos.z+BillboardX.z*particles[i].size+BillboardY.z*particles[i].size;

verts[i*4+2].v.x = particles[i].pos.x+BillboardX.x*particles[i].size-BillboardY.x*particles[i].size;
verts[i*4+2].v.y = particles[i].pos.y+BillboardX.y*particles[i].size-BillboardY.y*particles[i].size;
verts[i*4+2].v.z = particles[i].pos.z+BillboardX.z*particles[i].size-BillboardY.z*particles[i].size;

verts[i*4+3].v.x = particles[i].pos.x-BillboardX.x*particles[i].size-BillboardY.x*particles[i].size;
verts[i*4+3].v.y = particles[i].pos.y-BillboardX.y*particles[i].size-BillboardY.y*particles[i].size;
verts[i*4+3].v.z = particles[i].pos.z-BillboardX.z*particles[i].size-BillboardY.z*particles[i].size;



EDIT.

Yeah that was it:


void __fastcall  TFCOpenGL::drawbillboardF(float cx, float cy, float cz, float size)
{
double m_PickInfo_ModelView[16];// of ;

t3dpoint<float> Pos;
glGetDoublev(GL_MODELVIEW_MATRIX, m_PickInfo_ModelView);

BillboardX.x = m_PickInfo_ModelView[0];
BillboardX.y = m_PickInfo_ModelView[4];
BillboardX.z = m_PickInfo_ModelView[8];

BillboardY.x = m_PickInfo_ModelView[1];
BillboardY.y = m_PickInfo_ModelView[5];
BillboardY.z = m_PickInfo_ModelView[9];

glTexCoord2f(0.0, 1.0);

Pos.x = cx-BillboardX.x*size+BillboardY.x*size;
Pos.y = cy-BillboardX.y*size+BillboardY.y*size;
Pos.z = cz-BillboardX.z*size+BillboardY.z*size;

glVertex3f(Pos.x,Pos.y,Pos.z);
glTexCoord2f(1.0, 1.0);

Pos.x = cx+BillboardX.x*size+BillboardY.x*size;
Pos.y = cy+BillboardX.y*size+BillboardY.y*size;
Pos.z = cz+BillboardX.z*size+BillboardY.z*size;

glVertex3f(Pos.x,Pos.y,Pos.z);

glTexCoord2f(1.0, 0.0);
Pos.x = cx+BillboardX.x*size-BillboardY.x*size;
Pos.y = cy+BillboardX.y*size-BillboardY.y*size;
Pos.z = cz+BillboardX.z*size-BillboardY.z*size;
glVertex3f(Pos.x,Pos.y,Pos.z);

glTexCoord2f(0.0, 0.0);
Pos.x = cx-BillboardX.x*size-BillboardY.x*size;
Pos.y = cy-BillboardX.y*size-BillboardY.y*size;
Pos.z = cz-BillboardX.z*size-BillboardY.z*size;
glVertex3f(Pos.x,Pos.y,Pos.z);

glEnd();

}

Edited by WiredCat

##### Share on other sites

However, you replied exactly what I have already "achieved". Means that I have already set up my Right/Up Vector (see my code), but the Quad is not rotating with the camera.

Any solutions for that problem?

##### Share on other sites

lol,

you are picking wrong matrix, and getting wrong vector,

how is

glGetFloatv(GL_PROJECTION_MATRIX, @Matrix);
Right:= Vectorize(Matrix[0,0], Matrix[0,1], Matrix[0,2]);
Up:=    Vectorize(Matrix[1,0], Matrix[1,1], Matrix[1,2]);


equal to

double m_PickInfo_ModelView[16];// of ;

t3dpoint<float> Pos;
glGetDoublev(GL_MODELVIEW_MATRIX, m_PickInfo_ModelView);

BillboardX.x = m_PickInfo_ModelView[0];
BillboardX.y = m_PickInfo_ModelView[4];
BillboardX.z = m_PickInfo_ModelView[8];

BillboardY.x = m_PickInfo_ModelView[1];
BillboardY.y = m_PickInfo_ModelView[5];
BillboardY.z = m_PickInfo_ModelView[9];



to be more specific

glGetFloatv(GL_PROJECTION_MATRIX, @Matrix); and glGetDoublev(GL_MODELVIEW_MATRIX, m_PickInfo_ModelView);

after that you will have worldspace vectors (up, right) so you: LoadIdenity then setupcamera, and draw your object (defining position of billboard and its size)

Edited by WiredCat

##### Share on other sites
Lol, what an obvious mistake :/

Im sure that was the problem, I'll test it later on.

Thank you very much

##### Share on other sites
This thing is getting over me -.-

I replaced GL_PROJECTION_MATRIX with GL_MODELVIEW_MATRIX but nothing happens. The Quad is still not aligned to the view.