한국산업기술대학교 제 5 강스케일링및회전 이대현교수
학습안내 학습목표 3D 오브젝트의확대, 축소및회전방법을이해한다. 학습내용 3D 오브젝트의확대및축소 (Scaling) 3D 오브젝트의회전 (Rotation) 변홖공갂 (Transform Space)
SceneNode 의크기변홖 (Scale) void setscale ( Real x, Real y, Real z) void setscale ( const Vector3 & scale ) 씬노드에속해있는엔터티들의크기확장및축소. 씬노드의절대적스케일값을설정.
SceneNode 의크기변홖 (Scale) void scale ( Real x, Real y, Real z) void scale ( const Vector3 & scale ) 씬노드에속해있는엔터티들의크기확장및축소. 이미크기변홖된노드에적용하면앞서했었던크기변홖의위에적용됨. scale(vector3(2,2,2)) 를두번적용하면, setscale(vector3(4,4,4)) 와같음.
SceneNode 의크기변홖 (Scale) void setinheritscale ( bool inherit ) 장면노드의하위자식노드에게도크기변화가적용되는지결정. 디폴트값은 true
실습 Scale 엔터티크기변환
main.cpp (1) class LectureApp { 중략 실습 public: void go(void) { } 중략 Entity* entity1 = mscenemgr->createentity("professor", "DustinBody.mesh"); SceneNode* node1 = mscenemgr->getrootscenenode()-> createchildscenenode("professor", Vector3(0.0f, 0.0f, 0.0f)); node1->attachobject(entity1); Entity* entity2 = mscenemgr->createentity("ninja", "ninja.mesh"); SceneNode* node2 = node1->createchildscenenode("ninja", Vector3(100.0f, 0.0f, 0.0f)); node2->attachobject(entity2); 후략
main.cpp (2) bool framestarted(const FrameEvent &evt) { if (mkeyboard->iskeydown(ois::kc_1)) mprofessornode->setscale(1.0f, 1.0f, 1.0f); else if (mkeyboard->iskeydown(ois::kc_2)) mprofessornode->setscale(2.0f, 1.0f, 1.0f); else if (mkeyboard->iskeydown(ois::kc_3)) mprofessornode->setscale(3.0f, 1.0f, 1.0f); else if (mkeyboard->iskeydown(ois::kc_e)) mprofessornode->scale(1.1f, 1.0f, 1.0f); else if (mkeyboard->iskeydown(ois::kc_i)) mninjanode->setinheritscale(!mninjanode->getinheritscale()); 실습 } return true;
실행화면 키이입력 1,2,3,E,I 에따라다양한스케일실험.
if (mkeyboard->iskeydown(ois::kc_1)) mprofessornode->setscale(1.0f, 1.0f, 1.0f); else if (mkeyboard->iskeydown(ois::kc_2)) mprofessornode->setscale(2.0f, 1.0f, 1.0f); else if (mkeyboard->iskeydown(ois::kc_3)) mprofessornode->setscale(3.0f, 1.0f, 1.0f); else if (mkeyboard->iskeydown(ois::kc_e)) mprofessornode->scale(1.1f, 1.0f, 1.0f); else if (mkeyboard->iskeydown(ois::kc_i)) mninjanode->setinheritscale(!mninjanode->getinheritscale());
SceneNode 의회전 (Rotation) void pitch (const Radian &angle, TransformSpace relativeto=ts_local) x 축을회전축으로하여주어진각도만큼회전. Y Z X
SceneNode 의회전 (Rotation) void yaw (const Radian &angle, TransformSpace relativeto=ts_local) y 축을회전축으로하여주어진각도만큼회전. Y Z X
SceneNode 의회전 (Rotation) void roll (const Radian &angle, TransformSpace relativeto=ts_local) z 축을회전축으로하여주어진각도만큼회전. Y Z X
변홖공간
실습 Rotate 캐릭터회전
main.cpp bool framestarted(const FrameEvent &evt) { static SceneNode *curnode = mprofessornode; 실습 if (mkeyboard->iskeydown(ois::kc_p)) curnode->pitch(degree(1.0f)); else if (mkeyboard->iskeydown(ois::kc_y)) curnode->yaw(degree(1.0f)); else if (mkeyboard->iskeydown(ois::kc_r)) curnode->roll(degree(1.0f)); else if (mkeyboard->iskeydown(ois::kc_1)) curnode = mprofessornode; else if (mkeyboard->iskeydown(ois::kc_2)) curnode = mninjanode; } return true;
실행결과 키이입력 p,y,r,1,2 에따라다양한회전실험
yaw 씬노드자신의 y 축을회전축으로하여회전
pitch
roll
static SceneNode *curnode = mprofessornode; if (mkeyboard->iskeydown(ois::kc_p)) curnode->pitch(degree(1.0f)); else if (mkeyboard->iskeydown(ois::kc_y)) curnode->yaw(degree(1.0f)); else if (mkeyboard->iskeydown(ois::kc_r)) curnode->roll(degree(1.0f)); else if (mkeyboard->iskeydown(ois::kc_1)) curnode = mprofessornode; else if (mkeyboard->iskeydown(ois::kc_2)) curnode = mninjanode;
실습 Rotate Ramdom Axis 회전변환 ( 임의축 )
main.cpp 실습 bool framestarted(const FrameEvent &evt) { Vector3 axis(1.0f, 1.0f, 0.0f); axis.normalise(); mprofessornode->rotate(axis, Degree(1.0f)); } return true;
실행결과 : x = y 축을회전축으로회전
Vector3 axis(1.0f, 1.0f, 0.0f); axis.normalise(); mprofessornode->rotate(axis, Degree(1.0f));
학습정리 3D 오브젝트의확대및축소 setscale() 엔터티의절대크기 ( 원래모델의크기를기준 ) 설정 scale() 현재엔터티의크기를기준으로한상대적크기설정 3D 오브젝트의회전 기본축을중심으로한회전 yaw(), roll(), pitch() 임의축을중심으로한회전 - rotate