Jump to content

Image of the Day

Working on #steam achievements!
#screenshotsaturday #indiegame #pixelart #NadiaWasHere #RPG #indiedev https://t.co/IcDuJSWsGK
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.


Sign up now

GLSL & Matrix Math Help

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 ICUP   Members   

140
Like
0Likes
Like

Posted 29 December 2012 - 11:39 PM

I'm new to 3-D math so I'm not sure if I'm doing this correctly.

 

I currently have a GLfloat[ 36 ] pyramid set to the buffer, and that data is sent to an vec4 Vertex in the shader.

 


#version 400 core

layout( location = 0 ) in vec4 Vertex;
uniform mat4 Model;

void main()
{
    gl_Position = Model * Vertex;
}

 

I then setup a 4x4 matrix to rotate around the y-axis, and send that as a uniform to the "Model" variable in the shader.

 

glm::mat4 ModelR(
        cos( rStepAngle ), 0.f, -sin( rStepAngle ), 0.f,
        0.f, 1.f, 0.f, 0.f,
        sin( rStepAngle ), 0.f, cos( rStepAngle ), 0.f,
        0.f, 0.f, 0.f, 0.f
        );

GLint ModelLoc = glGetUniformLocation( programs.basicShader, "Model" );
glUniformMatrix4fv( ModelLoc, 1, GL_FALSE, glm::value_ptr( ModelR ) );

 

I'm getting nothing on my screen except the clear color. I think I may be misunderstanding something here. Vertex is going to be 3 components (technically 4, with 0 at the end), that gets multiplied by the Model rotation. How many times is the main() of the shader being run? My understanding of it was that main() is run until all 12 vertices of the pyramid are multiplied by the Model matrix. Is this correct?

 

There's probably something wrong with my math...



#2 0r0d   Members   

1810
Like
1Likes
Like

Posted 30 December 2012 - 12:51 AM

Off the top of my head I'd say your problem is that you're making the last component of your position vector (w component) 0, instead of 1.  The last member of the matrix also needs to be 1.

 

position:

 (x, y, z, 1)

 

matrix:

(x1, y1, z1, 0)

(x2, y2, z2, 0)

(x3, y3, z3, 0)

( 0,  0,  0,  1)



#3 ICUP   Members   

140
Like
0Likes
Like

Posted 30 December 2012 - 02:05 AM

You were right. Thanks.






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.