c++ - Transformation hierarchy causes object to jump in space? -


i have 2 objects want parent tri child of torus. when , multiply matricies adding parents modelview childs, child jumps in space initially, on right , few units. insert offset this, , how calculate it?

obj = make_shared<object>(*this); obj->rename("tri"); obj->type->val_s = "tri"; obj->t->val_3 = glm::vec3(-4.f, 1.5f, 0.f); allobj.push_back(obj);   obj = make_shared<object>(*this); obj->rename("torus"); obj->type->val_s = "obj"; obj->t->val_3 = glm::vec3(3.f, 2.f, 0.f); allobj.push_back(obj);  //matrix scalem = glm::scale(glm::mat4(), s->val_3); rotationm = glm::tomat4(r_quat); glm::vec3 usablepivot = t->val_3 - pivot->val_3; glm::mat4 localaxis1m = glm::translate(glm::mat4(), usablepivot); glm::mat4 localaxis2m = glm::translate(glm::mat4(), -usablepivot);  translationm = glm::translate(glm::mat4(), t->val_3);  modelm = translationm * localaxis2m * rotationm * scalem * localaxis1m;  //view usableview = mygl->viewm;  //projection usableprojection = mygl->projectionm;  //mvp if (parent == "world") { mvp = usableprojection * usableview * modelm; } else { mvp = usableprojection * usableview * parentto->modelm * modelm; } 

matrix order in mine opengl apps:

  1. sub-object matrices

    • the lowest in ownership hierarchy first
    • they local parents
    • their have offset point (0,0,0) of parent space
    • if not , local world jump reason
    • in case sub-objects not sub objects
    • and handle them normal object without parent
  2. object world

    • is transform matrix of objects without parent
    • they local scene world
  3. then goes camera view

    • it inverse of camera space
    • where z-axis view direction
  4. last projection

    • like gluperspective(...)
    • this 1 stored in gl_projection matrix on fixed pipeline
    • instead of gl_modelview
  5. clipping done opengl separately via glviewport

    • (your usable view think)

look more info here

  • you can check content of matrices
  • look @ positions 12,13,14 offset vector stored
  • do not forget vector local parent coordinate system!!!
  • so more rotated ...
  • also idea draw axis lines each tested matrix in parent space
  • to see if correct
  • i use red,gree,blue lines x,y,z - axis
  • just extract origin of coordinate system [12,13,14]
  • and draw line same point + a*axis vector
  • a line length (big enough see line not point)
  • axis vectors @ positions x=[0,1,2], y=[4,5,6], z=[8,9,10]
  • do not forget set matrices parent coordinate system !!!
  • if handle matrices self via glsl not forget that
  • direction vectors normals transformed without offset
  • so whole transform matrix (all multilicated without projection , camera)
  • set offset 0 [12,13,14]=(0.0,0.0,0.0)
  • and multiply matrix

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -