opengl - How to position an object in model / view / world space? -


i have cube defined centre @ 0,0,0 , edges reaching out -1/+1 (i.e. cube has width, height, depth of 2).

i setup following matrices:

glm::mat4 modelmat4; modelmat4 = glm::translate(modelmat4, 0.0f, 0.0f, 200.f); modelmat4 = glm::scale(modelmat4, 200.0f, 200.0f, 200.0f);  glm::mat4 viewmat4; viewmat4 = glm::lookat(glm::vec3(0.0f, 0.0f, znear),             glm::vec3(0.0f, 0.0f, zfar),             glm::vec3(0.0f, 1.0f, 0.0f));  // initialwidth = window width // initialheight = window height // znear = 1.0f // zfar = 1000.0f glm::mat4 projectionmat4; projectionmat4 = glm::frustum(-initialwidth / 2.0f, initialwidth / 2.0f, -initialheight / 2.0f, initialheight / 2.0f, znear, zfar); 

but middle of object appears @ near z-plane (i.e. can see half of cube, inside).

if adjust model transform be:

glm::translate(modelmat4, 0.0f, 0.0f, 204.f); 

then can see front side of cube well.

if change model transform be:

glm::translate(modelmat4, 0.0f, 0.0f, 250.f); 

then cube rasterises @ approx 2x2x2 pixels.

what misunderstanding model, view projection matrices? expecting transform linear, z-plane disappears between 200 , 250. though planes defined between 1.0f , 1000.0f.

edit: shader code below:

#version 100  layout(location = 0) in vec3 v_position; layout(location = 1) in vec4 v_colour;  layout(location = 2) uniform mat4 v_modelmatrix; layout(location = 3) uniform mat4 v_viewmatrix; layout(location = 4) uniform mat4 v_projectionmatrix;  out vec4 f_incolour;  void main() {     gl_position = v_projectionmatrix * v_viewmatrix * v_modelmatrix * vec4(v_position, 1.0);     f_incolour = v_colour; } 

you didn't show how multiplying matrices, describe, seems doing wrong. sure in order:

mvp = projectionmat4 * viewmat4 * modelmat4; 

updated

looking more code, seeming lacking multiplication concanate transformations:

modelmat4 = glm::translate(modelmat4, 0.0f, 0.0f, 200.f); modelmat4 *= glm::scale(modelmat4, 200.0f, 200.0f, 200.0f); // <-- here 

so, modelmat4 results of scale , translation


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -