Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Trying to Pivote/Rotate matrix/view?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member Newbie
    Join Date
    Apr 2013

    Question Trying to Pivote/Rotate matrix/view?


    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);
    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 .

    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:

    Code :
    	//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); //
    	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);
    	//have also tried rotating here.
    	glUniformMatrix4fv(m_ModelMatrixUniformLocation, 1, GL_FALSE, m_ModelMatrix.m);
    	glUniformMatrix4fv(m_ViewMatrixUniformLocation, 1, GL_FALSE, m_ViewMatrix.m);
    	glDrawArrays(DRAW_TYPE, 0,;
    	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"\
    			"gl_Position = (vsProjectionMatrix * vsViewMatrix * vsModelMatrix) * in_Position;\n"\
    			"ex_Color = in_Color;\n"\

    Any insight would be much appreciated!
    Thank you.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Karachi, Pakistan
    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
    Code :
    (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
    Code :
    //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.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2013
    I don't know how the code you've posted translates into modern OpenGL .
    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 .

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    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.

  5. #5
    Senior Member OpenGL Lord
    Join Date
    May 2009
    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.

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts