本文整理汇总了C++中Matrix4d::makeTranslate方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix4d::makeTranslate方法的具体用法?C++ Matrix4d::makeTranslate怎么用?C++ Matrix4d::makeTranslate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix4d
的用法示例。
在下文中一共展示了Matrix4d::makeTranslate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadFiles
void Window::loadFiles(){
cout << "start parsing bunny..." << endl;
Parser::parse("bunny.xyz", bunnyPos, bunnyNor, bunny_xmin, bunny_xmax, bunny_ymin, bunny_ymax, bunny_zmin, bunny_zmax);
tran_bunny.makeTranslate(-(bunny_xmin + bunny_xmax) / 2, -(bunny_ymin + bunny_ymax) / 2, -(bunny_zmin + bunny_zmax) / 2);
tran_bunny.print("translation matrix for bunny:");
cout << "bunny is loaded." << endl;
cout << "start parsing dragon..." << endl;
Parser::parse("dragon.xyz", dragonPos, dragonNor, dragon_xmin, dragon_xmax, dragon_ymin, dragon_ymax, dragon_zmin, dragon_zmax);
tran_dragon.makeTranslate(-(dragon_xmin + dragon_xmax) / 2, -(dragon_ymin + dragon_ymax) / 2, -(dragon_zmin + dragon_zmax) / 2);
tran_dragon.print("translation matrix for dragon:");
cout << "dragon is loaded." << endl;
}
示例2: computeMatrix
void Camera::computeMatrix(){
Vector3d z = e - d;
z.normalize();
Vector3d x = up.cross(z);
x.normalize();
Vector3d y = z.cross(x);
y.normalize();
Matrix4d r;
r.identity();
r.set(0, 0, x[0]);
r.set(1, 0, x[1]);
r.set(2, 0, x[2]);
r.set(0, 1, y[0]);
r.set(1, 1, y[1]);
r.set(2, 1, y[2]);
r.set(0, 2, z[0]);
r.set(1, 2, z[1]);
r.set(2, 2, z[2]);
Matrix4d t;
t.identity();
t.makeTranslate(-e[0], -e[1], -e[2]);
m = r * t;
}
示例3: setCamera
void Camera::setCamera(double eyeX, double eyeY, double eyeZ,
double centerX, double centerY, double centerZ,
double upX, double upY, double upZ){
double f[3];
f[0] = centerX - eyeX;
f[1] = centerY - eyeY;
f[2] = centerZ - eyeZ;
double m_f = sqrt(f[0] * f[0] + f[1] * f[1] + f[2] * f[2]);
f[0] /= m_f;
f[1] /= m_f;
f[2] /= m_f;
double up[3];
up[0] = upX;
up[1] = upY;
up[2] = upZ;
double m_u = sqrt(up[0] * up[0] + up[1] * up[1] + up[2] * up[2]);
up[0] /= m_u;
up[1] /= m_u;
up[2] /= m_u;
double s[3];
s[0] = f[1] * up[2] - f[2] * up[1];
s[1] = f[2] * up[0] - f[0] * up[2];
s[2] = f[0] * up[1] - f[1] * up[0];
double u[3];
u[0] = s[1] * f[2] - s[2] * f[1];
u[1] = s[2] * f[0] - s[0] * f[2];
u[2] = s[0] * f[1] - s[1] * f[0];
Matrix4d r; // inverse rotation
r.identity();
r.set(0, 0, s[0]);
r.set(1, 0, s[1]);
r.set(2, 0, s[2]);
r.set(0, 1, u[0]);
r.set(1, 1, u[1]);
r.set(2, 1, u[2]);
r.set(0, 2, -f[0]);
r.set(1, 2, -f[1]);
r.set(2, 2, -f[2]);
Matrix4d t; // inverse translation
t.identity();
t.makeTranslate(-eyeX, -eyeY, -eyeZ);
m = r * t; // inverse camera
}
示例4: construct
void BuildingConstructor::construct() {
GLdouble currentMaxH = maxH;
GLdouble currentMinH = minH;
GLdouble xTranslation = ((double) rand() * 0.5) / (double) RAND_MAX;
GLdouble zTranslation = ((double) rand() * 0.5) / (double) RAND_MAX;
GLdouble xScaling = 2.0;
GLdouble zScaling = 2.0;
GLdouble rotationAngle = 90.0;
GLdouble lotBias = 0.02;
Matrix4d translation;
Matrix4d scaling;
Matrix4d rotation;
Matrix4d rotation90;
Building* building = NULL;
GLdouble scaleMax = 0.90;
GLdouble scaleMin = 0.5;
double colorH = 1.0;
double colorL = 0.90;
double r = (double) rand() * (colorH + 1.0 - colorL) / (double) RAND_MAX + colorL;
double g = (double) rand() * (colorH + 1.0 - colorL) / (double) RAND_MAX + colorL;
double b = (double) rand() * (colorH + 1.0 - colorL) / (double) RAND_MAX + colorL;
GLuint buildingChoice = rand() * (3 + 1) / RAND_MAX;
GLuint roofChoice = rand() * (5 - 4 + 1) / RAND_MAX + 4;
std::cerr << "buildingChoice: " << buildingChoice << " roofChoice: " << roofChoice << std::endl;
rotation.identity();
rotation90.makeRotateY(rotationAngle);
switch (choice) {
// medium buildings
case 0:
while (buildingChoice == 1) {
buildingChoice = rand() * (3 + 1) / RAND_MAX;
}
std::cerr << "hhhh" << std::endl;
xScaling = (double) rand() * (3.0 + 1.0 - 2.0) / (double) RAND_MAX + 2.0;
zScaling = (double) rand() * (3.0 + 1.0 - 2.0) / (double) RAND_MAX + 2.0;
translation.makeTranslate(xTranslation, 0.0, zTranslation);
scaling.makeScale(xScaling, currentMaxH, zScaling);
building = new Building(buildingChoice, roofChoice, r, g, b, texture, xScaling, currentMaxH, zScaling, translation * scaling);
root->addChild(building->getRoot());
break;
// mid towards out buildings
case 1:
buildingChoice = rand() * (3 + 1 - 1) / RAND_MAX + 1;
xScaling = zScaling = (double) rand() * (1.0 + 1.0 - 0.5) / (double) RAND_MAX + 0.5;
for (int count = 0; count < layerCount - 1; ++count) {
currentMaxH -= ((double) rand() * (scaleMax - scaleMin)) / (double) RAND_MAX + scaleMin;;
xScaling += 0.3;
zScaling += 0.3;
if (xScaling > 3.0 || zScaling > 3.0) {
break;
}
// std::cerr << "zScaling: " << zScaling << std::endl;
scaling.makeScale(xScaling, currentMaxH, zScaling);
building = new Building(buildingChoice, roofChoice, r, g, b, texture, xScaling, currentMaxH, zScaling, scaling);
root->addChild(building->getRoot());
}
break;
// tall buildings with rotation
case 2:
scaling.makeScale(3.0, 1.0, 3.0);
buildingChoice = rand() * (3 + 1 - 1) / RAND_MAX + 1;
building = new Building(buildingChoice, roofChoice, r, g, b, texture, 3.0, 1.0, 3.0, scaling);
root->addChild(building->getRoot());
translation.makeTranslate(xTranslation, 0.0, zTranslation);
scaling.makeScale(xScaling, currentMaxH, zScaling);
building = new Building(buildingChoice, roofChoice, r, g, b, texture, xScaling, currentMaxH, zScaling, translation * scaling);
root->addChild(building->getRoot());
//t s m
xTranslation = 0.5 - lotBias;
zTranslation = 0.0;
zScaling = ((double) rand() * (currentMaxH - currentMinH)) / (double) RAND_MAX + currentMinH;
for (int count = 0; count < layerCount - 1; ++count) {
currentMaxH -= ((double) rand() * (scaleMax - scaleMin)) / (double) RAND_MAX + scaleMin;;
rotation = rotation90 * rotation;
zScaling = ((double) rand() * (scaleMax - scaleMin)) / (double) RAND_MAX + scaleMin;
// std::cerr << "zScaling: " << zScaling << std::endl;
scaling.makeScale(xScaling, currentMaxH, zScaling);
translation.makeTranslate(xTranslation, 0.0, 0.0);
building = new Building(buildingChoice, roofChoice, r, g, b, texture, xScaling, currentMaxH, zScaling, rotation * translation * scaling);
root->addChild(building->getRoot());
}
break;
default:
break;
//.........这里部分代码省略.........
示例5: 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));
}