I have a 3D world with a cube inside it. I understand that the cube's vertices are defined as coordinates about the cube's "centre of mass".
I want to place the cube at a position away from me, to the right and up above so I want to place the cube at (1,1,1). I don't have any 'camera' code at the moment so assume my viewing position is (0,0,0).
What do I need to translate to move the cube to a new location?
I am confused by the View and Model matrices. I thought View was the camera view/position and Model was the position of the vertices in the 3D world.
My code below works as I expect for x and y positions but z is negative going into the screen (further away) and positive moving towards/out of the screen. I would like z to be positive the further away an object is from the viewpoint.
What am I doing wrong?
glm::mat4 Projection = glm::perspective( 45.0f, g_AspectRatio, 0.1f, 100.0f );
glm::mat4 View = glm::mat4(1.0);
glm::mat4 Model = glm::mat4(1.0);
// Move the object within the 3D space
Model = glm::translate( Model, glm::vec3( m_X, m_Y, m_Z ) );
glm::mat4 MVP;
MVP = Projection * View * Model;
MVP
is passed into the transform
uniform.
My shader:
char *vs3DShader =
"#version 140\n"
"#extension GL_ARB_explicit_attrib_location : enable\n"
"layout (location = 0) in vec3 Position;"
"layout (location = 1) in vec4 color;"
"layout (location = 2) in vec3 normal;"
"out vec4 frag_color;"
"uniform mat4 transform;"
"void main()"
"{"
" gl_Position = transform * vec4( Position.x, Position.y, Position.z, 1.0 );"
" // Pass vertex color to fragment shader.. \n"
" frag_color = color;"
"}"
;