# Vector to pitch and yaw, or how to use glMultMatrixf

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

## Recommended Posts

I need to get roll, pitch and yaw from two different vectors

or i just must know how to properly use glMultMatrixf:

so i have a matrix

float matrix[16];

i do identity then

sth like this

t.pointer[0] = 1.0;t.pointer[1] = 0.0; t.pointer[2] = 0.0; t.pointer[3] = 0.0;
t.pointer[4] = 0.0;t.pointer[5] = 1.0; t.pointer[6] = 0.0; t.pointer[7] = 0.0;
t.pointer[8] = 0.0;t.pointer[9] = 0.0; t.pointer[10] = 1.0; t.pointer[11] = 0.0;
t.pointer[12] = 0.0;t.pointer[13] = 0.0; t.pointer[14] = 0.0; t.pointer[15] = 1.0;
[/quote]

So then i place normalized vectors into the matrix

for right vector - into 0,4,8

for up vector 1,5,9

and for front vector 2,6,10

i do not use translation for now

then i try something like this for opengl:

glPushMatrix();

gluLookAt(point the camera is facing);

glPushMatrix();

glMultMatrixf( thismatrix );

draw rotated and translated model

glPopMatrix();

glPopMatrix();

but dont see model being rotated and sometimes when i rotate camera to see model from different position its scaling or transalting :0

i really forgot how to use glMultMatrix(); //especially when ;]

i rather want to know how to obtain yaw and pitch angles from a given vector with full 360.0 degree scale :/ so far my all atemps to accomplish this failed

##### Share on other sites
Any particular reason why you are transposing the rotation part of your matrix?

##### Share on other sites
i dont understand where i am transposing the matrix?

do you think i set wrong values to the float matrix[16]; array? or what? you mean 2,6,10?

##### Share on other sites

i dont understand where i am transposing the matrix?

OpenGL has a convenient memory layout where index 0-4 is the x-axis, 5-8 is y, 9-12 is z and 13-15 is the origin of your local coordinate system. So I have no idea why you assign them the way you do.

##### Share on other sites
i still dont understand where is the up, right and back or front vector of then modelview matrix

i thought it should be

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];

so when i want to set a matrix i need to transpose it after i set values to [0] [4] [8] and [1] [5][9] and then call glLoadMatrixf();?or what

why i must use two different sets of matrix one is from glGetFloatv() and it's standard matrix that i understand but i dont understand the 'transposed ???' matrix

is it still identity matrix like

1 0 0 0

0 1 0 0

0 0 1 0

0 0 0 1

or is it transposed??? WHAT THE F*****?

and do i transpose rotation part or whole matrix?

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

t3dpoint 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();

}

[/quote]

##### Share on other sites
Billboards are a completely different topic from "getting matrix from pitch and yaw". They aren't drawn like any other object with their own orientation, but in a way that makes them face the "camera". In that case you WANT to use the transposed of the view matrix rotation part, because in this particular case it means inverting the rotation. Of course instead of first applying a view matrix for the camera and then undoing it by using the inverse for the billboard you could just as well replace the rotation part with identity.

But basically: what are you even trying to do and why are suddenly billboards coming out of nowhere?

##### Share on other sites
So i just want to make my model being properly displayed

the blue vecotr is front vecotr of model, green is the up vector,and red is the right vector

[media]
[/media]

on the vid i calculate angles from vec positions, but i think i should rotate model not by glrotatef but by matrix

so i just want to inster those normlaized vectors into the matrix after glpushmatrix(); glloadidentoty(); glulookat(actual camera); glMultMatrixf or glLoadMatrixf draw model properly glpopkmatrix; ;]

i showed the code from billboard because somebody asked me why i set the vectors in this way i do :s

====

i just want to fly around the world and throw some bombs whereever i like ;]

take a look :

And you can also look here

[media]
[/media]

well in future i will add dynamic and high detailed ground surface and dynamic global weather but now i want just simple model drawing :x

##### Share on other sites
ihavedone it :PP

AIR_MATRIX[0] = rotationmodel->VBO_V[1].x; //right
AIR_MATRIX[1] = rotationmodel->VBO_V[1].y;
AIR_MATRIX[2] = rotationmodel->VBO_V[1].z;
AIR_MATRIX[3] = 0.0f;
AIR_MATRIX[4] = rotationmodel->VBO_V[3].x; //up
AIR_MATRIX[5] = rotationmodel->VBO_V[3].y;
AIR_MATRIX[6] = rotationmodel->VBO_V[3].z;
AIR_MATRIX[7] = 0.0f;
AIR_MATRIX[8] = rotationmodel->VBO_V[4].x;//front
AIR_MATRIX[9] = rotationmodel->VBO_V[4].y;
AIR_MATRIX[10] = rotationmodel->VBO_V[4].z;
AIR_MATRIX[11] = 0.0f;
AIR_MATRIX[12] = 0.0f; //point
AIR_MATRIX[13] = 0.0f;
AIR_MATRIX[14] = 0.0f;
AIR_MATRIX[15] = 1.0f;

and the problem was yes row and column order ;P

// [r1 u1 l1 px] --> from nehe billboarding tutorial
// [r2 u2 l2 py]
// [r3 u3 l3 pz]
// [0 0 0 1]

// 0 1 2 3 -> the normal matrix notation?
// 4 5 6 7
// 8 9 10 11
// 12 13 14 15

// 0 4 8 12 opengl matrix notation
// 1 5 9 13
// 2 6 10 14
// 3 7 11 15

[/quote]

ahh and i use glMultMatrixf (AIR_MATRIX); where AIR_MATRIX is float * (16 elements)

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633763
• Total Posts
3013728
×