本文整理汇总了C++中Matrix4d::makeScale方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix4d::makeScale方法的具体用法?C++ Matrix4d::makeScale怎么用?C++ Matrix4d::makeScale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix4d
的用法示例。
在下文中一共展示了Matrix4d::makeScale方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reshapeCallback
// Called whenever the window size changes
void Window::reshapeCallback(int new_width, int new_height)
{
width = new_width;
height = new_height;
limit = width * height * 3 - 2;
delete[] pixels;
delete[] zbuffer;
pixels = new float[width * height * 3];
zbuffer = new float[(width + 1) * (height + 1)];
viewport = Projection::viewport(0, 0, width, height);
viewport.print("view port");
projection = Projection::perspective(60, double(width) / double(height), 1.0, 1000.0);
projection.print("projection");
//Matrix4d t;
//t.makeTranslate(0, 0, -20);
//projection = projection * t;
// calculate scaling matrix for bunny
double x = (bunny_xmax - bunny_xmin) / 2;
double y = (bunny_ymax - bunny_ymin) / 2;
double z = (bunny_zmax - bunny_zmin) / 2;
double a = z / y;
double ymax = 20 / (a + 1 / tan(30 * M_PI / 180));
double sy = ymax / y; // scaling factor according to y
double xmax = ymax * (double)width / (double)height; //scaling factor according to x
double sx = xmax / x;
double min = sy < sx ? sy : sx;
scale_bunny.makeScale(min, min, min);
// calculate scaling matrix for dragon
x = (dragon_xmax - dragon_xmin) / 2;
y = (dragon_ymax - dragon_ymin) / 2;
z = (dragon_zmax - dragon_zmin) / 2;
a = z / y;
ymax = 20 / (a + 1 / tan(30 * M_PI / 180));
xmax = ymax * (double)width / (double)height;
sy = ymax / y;
sx = xmax / x;
min = sy < sx ? sy : sx;
scale_dragon.makeScale(min, min, min);
//scale_dragon.print("scaling matrix for dragon:");
}
示例2: keyboardCallback
void Window::keyboardCallback(unsigned char key, int, int)
{
switch (key){
case '1':
bunny = true;
break;
case '2':
bunny = false;
break;
case 's':
temp.makeScale(0.9, 0.9, 0.9);
scaling.multiply(temp);
break;
case 'S':
temp.makeScale(1.1, 1.1, 1.1);
scaling.multiply(temp);
break;
case 27:
exit(0);
}
}
示例3: 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;
}
示例4: calculateScalingMatrix
Matrix4d Window::calculateScalingMatrix(int w, int h, Coordinate3d min, Coordinate3d max){
double x = (max.x - min.x) / 2;
double y = (max.y - min.y) / 2;
double z = (max.z - min.z) / 2;
//cout << "x : " << x << " y : " << y << " z : " << z << endl;
double a = z / y;
double ymax = 20 / (a + 1 / tan(30 * M_PI / 180));
double sy = ymax / y;
double xmax = ymax * double(w) / double(h);
double sx = xmax / x;
double factor = sy < sx ? sy : sx;
Matrix4d s;
s.makeScale(factor, factor, factor);
return s;
}
示例5: 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;
//.........这里部分代码省略.........