현재 OpenGL을 배우고 있으며 기하학과 텍스처의 첫 번째 묶음이 표시됩니다.OpenGL의 계층 구조 모델
이제 다른 그래픽 액터간에 상위 - 하위 계층 모델을 설정하려고합니다. 내가 일반적으로 다음과 같이 구현있어 이해 :
void Draw(){
glPushMatrix();
<apply all transformations>
<draw this model>
<for each child c of this actor:>
c.Draw();
glPopMatrix();
}
이 방법은 아이들이 부모 (규모, 위치, 회전)의 모든 변환을 상속합니다. 하지만 때로는 특정 변형 만 적용하고 싶습니다 (예 : 특수 효과 액터는 부모와 함께 이동해야하지만 헬멧 액터는 모든 변형을 상속 받기를 원하지만 부모 회전은 사용하지 말아야합니다).
내가 그리기 기능에 적용 할 변환 매개 변수를 전달하고 함께 왔어요 아이디어 :
class Actor{
Vec3 m_pos, m_rot, m_scale; //This object's own transformation data
std::vector<Actor*> m_children;
void Draw(Vec3 pos, Vec3 rot, Vec3 scale){
(translate by pos) //transform by the given parent data
(rotate around rot)
(scale by scale)
glPushMatrix(); //Apply own transformations
(translate by m_pos)
(rotate around m_rot)
(scale by m_scale)
(draw model)
glPopMatrix(); //discard own transformations
for(Actor a : m_children){
glPushMatrix();
a.Draw(pass m_pos, m_rot and/or m_scale depending on what the current child wants to inherit);
glPopMatrix();
}
}
}
void StartDrawing(){
glLoadIdentity();
//g_wold is the "world actor" which everything major is attached to.
g_world.Draw(Vec3(0,0,0), Vec3(0,0,0), Vec3(0,0,0));
}
(의사 코드 errorneous 수도 있지만 생각을 전달해야합니다.).
하지만 다소 엉성한 것처럼 보이고 프로그램에 훨씬 더 많은 작업 부하가 발생합니다 (추가 벡터 연산이 많이 필요할 것입니다).
나는 계층 적 모델링에 대해 약간 읽었지만 모든 문학은 모든 어린이가 항상 모든 부모 속성을 상속 받기를 원한다고 가정하는 것으로 보입니다.
더 좋은 방법이 있습니까?