PDA

View Full Version : Trying to Pivote/Rotate matrix/view?



ReturnVoid
05-05-2013, 05:04 AM
hi,

Have been trying for a while now to do this, but it doesn't seem to be working as I wish:

I have the following points (as an example);
32,-80,150
-80,32,150
The lower the z value here the more accurate what I'm trying to do becomes. So the coordinates get displayed but on a slight angle, so I'm obviously missing something I just don't know what :sorrow:.

I currently have a top-overview of this (on a different context & have no issue), but I'm trying to get a cross section view, which I thought using Rotate on the X-axis 90degrees would work, but :(....
Following code is an extract of what I'm using, if it isn't enough let me know & I'll have to post more:



//prepare scene
m_ModelMatrix = IDENTITY_MATRIX;
m_ProjectionMatrix = IDENTITY_MATRIX;
m_ViewMatrix = IDENTITY_MATRIX;
RotateAboutX(&m_ModelMatrix,90); //have also tried using this after Translate
ScaleMatrix(&m_ViewMatrix, m_ScaleX, m_ScaleY, m_ScaleZ); //scales cords x,y,z
TranslateMatrix(&m_ViewMatrix, 0, 0, m_TranslateZ); //

//resizing
glViewport(0, 0, (GLsizei)cx, (GLsizei)cy);
//fovy is 60. Have tried others.
m_ProjectionMatrix = CreateProjectionMatrix(m_fovy,(float)CurrentWidth / CurrentHeight,1.0f,100.0f);


//drawing.
//have also tried rotating here.
glUniformMatrix4fv(m_ModelMatrixUniformLocation, 1, GL_FALSE, m_ModelMatrix.m);
glUniformMatrix4fv(m_ViewMatrixUniformLocation, 1, GL_FALSE, m_ViewMatrix.m);
glBindVertexArray(m_vVaoID.at(i));
glDrawArrays(DRAW_TYPE, 0, m_vGLSizeCount.at(i));


//shader
const GLchar* VertexShader =
{
"#version 330\n"\
"layout(location=0) in vec4 in_Position;\n"\
"layout(location=1) in vec4 in_Color;\n"\
"out vec4 ex_Color;\n"\
"uniform mat4 vsModelMatrix;\n"\
"uniform mat4 vsViewMatrix;\n"\
"uniform mat4 vsProjectionMatrix;\n"\
"void main(void)\n"\
"{\n"\
"gl_Position = (vsProjectionMatrix * vsViewMatrix * vsModelMatrix) * in_Position;\n"\
"ex_Color = in_Color;\n"\
"}\n"
};




Any insight would be much appreciated!
Thank you.

mobeen
05-06-2013, 10:34 PM
Hi,
I have not seens the whole code but just a first few lines and I find that probably ur transformation sequence is wrong.
Usually for a matrix library doing post multiplication (right handed as in OpenGL fixed function pipeline), the sequence of transformation is this

(Translate * ( Rotate * Scale)) that is to say you apply scaling first then rotation and finally translation. Doing it with fixed function pipeline will be something like this


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef();
glRotatef();
glScalef();

//your glVertex etc. calls here

This will be called in the reverse order on the vertice/s, scaling first then rotation and finally translation.

See if this helps.

ReturnVoid
05-09-2013, 05:06 AM
I don't know how the code you've posted translates into modern OpenGL :confused:.
I am a beginner. I have searched & read so much, but as per my problem above explains it's not working how I want & I really don't know why.

All I want to do is view these coordinates on the screen in 2D, but from side on (or rather, a different angle to their natural state). Where would I find a fully working example that does this that doesn't use depreciated code & doesn't use GLM :dejection:.

tonyo_au
05-10-2013, 01:39 AM
glm is the latest extension tool for modern OpenGL; it provides a standard library of matrix and vectors to make code sharing easier hence more and more tutorials are using it. If you don't want to use it or depreciated code, it will be harder for you to find tutorials.

Alfonse Reinheart
05-10-2013, 09:23 AM
It is not an "extension tool". It's not even "for OpenGL". It's just a vector math library. More tutorials are using it because it's simple to use and it works, which up until GLM hasn't really been true of vector math libraries.

tonyo_au
05-10-2013, 08:53 PM
It's not even "for OpenGL"
This is true but it does have a lot of functions that are replacements for OpenGL glu functions that other vector libraries don't have.