本文整理汇总了C++中Matrix4d::makeRotate方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix4d::makeRotate方法的具体用法?C++ Matrix4d::makeRotate怎么用?C++ Matrix4d::makeRotate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix4d
的用法示例。
在下文中一共展示了Matrix4d::makeRotate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mouseMotionProcess
void Window::mouseMotionProcess(int x, int y){
Vector3d direction;
double pixel_diff;
double rot_angle, zoom_factor;
Vector3d curPoint;
curPoint = trackBallMapping(x, y);
switch (movement){
case control::ROTATION:
{
if (!lightControl){
direction = curPoint - lastPoint;
double velocity = direction.magnitude();
if (velocity > 0.0001){
Vector3d rotAxis = lastPoint * curPoint;
rotAxis.normalize();
rot_angle = velocity * ROTSCALE;
Matrix4d r;
r.makeRotate(rot_angle, rotAxis);
rotation = r * rotation;
rotate_mt->setMatrix(rotation);
}
}
}
break;
case control::SCALING:
{
pixel_diff = curPoint[1] - lastPoint[1];
zoom_factor = 1.0 + pixel_diff * ZOOMSCALE;
if (!lightControl){
Matrix4d s;
s.makeScale(zoom_factor, zoom_factor, zoom_factor);
scaling = scaling * s;
scaling_mt->setMatrix(scaling);
displayCallback();
}
else{
spotLight.setCutOff(spotLight.getCutOff() * zoom_factor);
}
}
break;
}
lastPoint = curPoint;
}
示例2: init
void Window::init(){
// load shader
shader = new Shader("shaders/spotlight.vert", "shaders/spotlight.frag");
//shader->printLog("shader log:");
//system("pause");
/// loading bunny
Parser::parseObj("bunny.obj", bunny_pos, bunny_nor, bunny_pos_ind, bunny_nor_ind, bunny_min, bunny_max);
bunny_tran.makeTranslate(-(bunny_min.x + bunny_max.x) / 2,
-(bunny_min.y + bunny_max.y) / 2, -(bunny_min.z + bunny_max.z) / 2);
bunny_scale = calculateScalingMatrix(width, height, bunny_min, bunny_max);
/// loading bear
Parser::parseObj("bear.obj", bear_pos, bear_nor, bear_pos_ind, bear_nor_ind, bear_min, bear_max);
bear_tran.makeTranslate(-(bear_min.x + bear_max.x) / 2,
-(bear_min.y + bear_max.y) / 2, -(bear_min.z + bear_max.z) / 2);
bear_scale = calculateScalingMatrix(width, height, bear_min, bear_max);
/// loading dragon
Parser::parseObj("dragon.obj", dragon_pos, dragon_nor, dragon_pos_ind, dragon_nor_ind, dragon_min, dragon_max);
dragon_tran.makeTranslate(-(dragon_min.x + dragon_max.x) / 2,
-(dragon_min.y + dragon_max.y) / 2, -(dragon_min.z + dragon_max.z) / 2);
dragon_scale = calculateScalingMatrix(width, height, dragon_min, dragon_max);
//setting up light sources
spotLight.setExponent(1);
spotLight.setCutOff(5);
spotLight.setSpotDirection(spot_direction);
spotLight.setAttenuation(1.0, 0.1, 0.0);
//setting up material for bunny
material.setAmbient(m_ambient);
material.setDiffuse(m_diffuse);
material.setSpecular(m_specular);
material.setShininess(shininess);
//setting up material for bear
b_material.setAmbient(f4(0.2, 0.6, 0.6, 1.0));
b_material.setDiffuse(f4(0.5, 0.5, 0.5, 1.0));
//setting up emissive material for point light
emissive_ma.setAmbient(f4(0.8, 0.8, 0.8, 1.0));
emissive_ma.setDiffuse(diffuse);
emissive_ma.setSpecular(specular);
emissive_ma.setEmission(f4(0.1,0.1,0.1,1.0));
//building scene graph
scaling_mt = new MatrixTransform(Matrix4d());
rotate_mt = new MatrixTransform(Matrix4d());
bunny = new MatrixTransform(bunny_scale * bunny_tran);
root->addChild(rotate_mt);
rotate_mt->addChild(scaling_mt);
scaling_mt->addChild(bunny);
bunny->addChild(new ObjNode(&bunny_pos, &bunny_nor, &bunny_pos_ind, &bunny_nor_ind, bunny_min, bunny_max, &material));
bear = new MatrixTransform(bear_scale * bear_tran);
bear->addChild(new ObjNode(&bear_pos, &bear_nor, &bear_pos_ind, &bear_nor_ind, bear_min, bear_max, &b_material));
dragon = new MatrixTransform(dragon_scale * dragon_tran);
dragon->addChild(new ObjNode(&dragon_pos, &dragon_nor, &dragon_pos_ind, &dragon_nor_ind, dragon_min, dragon_max, &b_material));
Matrix4d t1;
t1.makeTranslate(-3.0, -10.0, 2.0);
pointL = new MatrixTransform(t1);
root->addChild(pointL);
pointL->addChild(new Sphere(0.5, 20, 20, Vector3d(1, 1, 1), draw::SOLID, &emissive_ma));
Vector3d vCone(-3, -10, 0);
vCone.normalize();
Vector3d axis = Vector3d(0, 0, -1) * vCone;
axis.normalize();
Matrix4d rCone;
rCone.makeRotate(acos(vCone.dot(Vector3d(0, 0, -1))) * 180 / M_PI, axis);
Matrix4d t2;
t2.makeTranslate(3, 10, 0);
spotL = new MatrixTransform(t2 * rCone);
root->addChild(spotL);
Material * m_cone = new Material(f4(0.5, 0.6, 0.9, 1.0), f4(0.5, 0.5, 0.5, 1.0), f4(0, 0, 0, 1.0), 20, f4(0, 0, 0, 1.0), f3(0, 0, 0));
spotL->addChild(new Cone(0.5, 1, 20, 20, Vector3d(0.0, 0.0, 0.0),draw::SOLID, m_cone));
}