本文整理汇总了C++中Matrix4::applyMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix4::applyMatrix方法的具体用法?C++ Matrix4::applyMatrix怎么用?C++ Matrix4::applyMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix4
的用法示例。
在下文中一共展示了Matrix4::applyMatrix方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getNormal
Position3d Cube::getNormal(Position3d point)
{
Matrix4 worldToLocalCoordinate = transform.getInverseRotationMatrix()
* transform.getInverseScalMatrix()
* transform.getInverseTranslationMatrix();
Position3d localPoint = worldToLocalCoordinate.applyMatrix(point);
Position3d localNormal;
if ((localPoint.get_x() > -1.0f - ZERO_THRESHOLD) && (localPoint.get_x() < -1.0f + ZERO_THRESHOLD))
{
localNormal = Position3d(-1.0f, 0.0f, 0.0f);
}
else if ((localPoint.get_x() > 1.0f - ZERO_THRESHOLD) && (localPoint.get_x() < 1.0f + ZERO_THRESHOLD))
{
localNormal = Position3d(1.0f, 0.0f, 0.0f);
}
else if ((localPoint.get_y() > -1.0f - ZERO_THRESHOLD) && (localPoint.get_y() < -1.0f + ZERO_THRESHOLD))
{
localNormal = Position3d(0.0f, -1.0f, 0.0f);
}
else if ((localPoint.get_y() > 1.0f - ZERO_THRESHOLD) && (localPoint.get_y() < 1.0f + ZERO_THRESHOLD))
{
localNormal = Position3d(0.0f, 1.0f, 0.0f);
}
else if ((localPoint.get_z() > -1.0f - ZERO_THRESHOLD) && (localPoint.get_z() < -1.0f + ZERO_THRESHOLD))
{
localNormal = Position3d(0.0f, 0.0f, -1.0f);
}
else if ((localPoint.get_z() > 1.0f - ZERO_THRESHOLD) && (localPoint.get_z() < 1.0f + ZERO_THRESHOLD))
{
localNormal = Position3d(0.0f, 0.0f, 1.0f);
}
// returns direction
Matrix4 localToWorldCoordinate = transform.getScalMatrix() * transform.getRotationMatrix();
Position3d worldNormal = localToWorldCoordinate.applyMatrix(localNormal);
worldNormal.normalize();
return worldNormal;
}
示例2: textureColor
ColorRgba Cube::textureColor(QImage texture, Position3d* point)
{
Matrix4 worldToLocalCoordinate = transform.getInverseRotationMatrix()
* transform.getInverseScalMatrix()
* transform.getInverseTranslationMatrix();
Position3d localPoint = worldToLocalCoordinate.applyMatrix(*point);
if ( ((localPoint.get_x() > -1.0f - ZERO_THRESHOLD) && (localPoint.get_x() < -1.0f + ZERO_THRESHOLD))
|| ((localPoint.get_x() > 1.0f - ZERO_THRESHOLD) && (localPoint.get_x() < 1.0f + ZERO_THRESHOLD)) )
{
// normalize
float tex_y = (localPoint.get_y() + 1.0f) / 2.0f;
float tex_z = (localPoint.get_z() + 1.0f) / 2.0f;
int h = (int)(tex_y * (float)texture.height());
int w = (int)(tex_z * (float)texture.width());
if (h < 0) h = 0;
if (h >= texture.height()) h = texture.height() - 1;
if (w < 0) w = 0;
if (w >= texture.width()) w = texture.width() - 1;
QRgb rgb = texture.pixel(w, h);
QColor color(rgb);
return ColorRgba(color.redF(), color.greenF(), color.blueF());
}
else if ( ((localPoint.get_y() > -1.0f - ZERO_THRESHOLD) && (localPoint.get_y() < -1.0f + ZERO_THRESHOLD))
|| ((localPoint.get_y() > 1.0f - ZERO_THRESHOLD) && (localPoint.get_y() < 1.0f + ZERO_THRESHOLD)) )
{
// normalize
float tex_x = (localPoint.get_x() + 1.0f) / 2.0f;
float tex_z = (localPoint.get_z() + 1.0f) / 2.0f;
int h = (int)(tex_z * (float)texture.height());
int w = (int)(tex_x * (float)texture.width());
if (h < 0) h = 0;
if (h >= texture.height()) h = texture.height() - 1;
if (w < 0) w = 0;
if (w >= texture.width()) w = texture.width() - 1;
QRgb rgb = texture.pixel(w, h);
QColor color(rgb);
return ColorRgba(color.redF(), color.greenF(), color.blueF());
}
else if ( ((localPoint.get_z() > -1.0f - ZERO_THRESHOLD) && (localPoint.get_z() < -1.0f + ZERO_THRESHOLD))
|| ((localPoint.get_z() > 1.0f - ZERO_THRESHOLD) && (localPoint.get_z() < 1.0f + ZERO_THRESHOLD)) )
{
// normalize
float tex_x = (localPoint.get_x() + 1.0f) / 2.0f;
float tex_y = (localPoint.get_y() + 1.0f) / 2.0f;
int h = (int)(tex_y * (float)texture.height());
int w = (int)(tex_x * (float)texture.width());
if (h < 0) h = 0;
if (h >= texture.height()) h = texture.height() - 1;
if (w < 0) w = 0;
if (w >= texture.width()) w = texture.width() - 1;
QRgb rgb = texture.pixel(w, h);
QColor color(rgb);
return ColorRgba(color.redF(), color.greenF(), color.blueF());
}
}
示例3: interceptedWithRay
Position3d* Cube::interceptedWithRay(Position3d rayOrigin, Position3d rayDirection)
{
Matrix4 worldToLocalCoordinate = transform.getInverseRotationMatrix() * transform.getInverseScalMatrix();
Position3d localRayDirection = worldToLocalCoordinate.applyMatrix(rayDirection);
worldToLocalCoordinate *= transform.getInverseTranslationMatrix();
Position3d localRayOrigin = worldToLocalCoordinate.applyMatrix(rayOrigin);
// vector ray direction
d_x = localRayDirection.get_x();
d_y = localRayDirection.get_y();
d_z = localRayDirection.get_z();
// ray initial point
o_x = localRayOrigin.get_x();
o_y = localRayOrigin.get_y();
o_z = localRayOrigin.get_z();
//LOG("x: " << d_x << "\ty: " << d_y << "\tz: " << d_z);
bool hittedX = false;
bool hittedY = false;
bool hittedZ = false;
if (d_x < 0.0f)
{
hittedX = checkRayPlusPlaneX();
}
else
{
hittedX = checkRayMinusPlaneX();
}
if (d_y < 0.0f)
{
hittedY = checkRayPlusPlaneY();
}
else
{
hittedY = checkRayMinusPlaneY();
}
if (d_z < 0.0f)
{
hittedZ = checkRayPlusPlaneZ();
}
else
{
hittedZ = checkRayMinusPlaneZ();
}
float t = MAX_VALUE;
if (hittedX)
{
if (hittedY)
{
if (hittedZ)
{
t = tx <= ty ? tx : ty;
t = tz <= t ? tz : t;
}
else
{
t = tx <= ty ? tx : ty;
}
}
else
{
if (hittedZ)
{
t = tx <= tz ? tx : tz;
}
else
{
t = tx;
}
}
}
else
{
if (hittedY)
{
if (hittedZ)
{
t = ty <= tz ? ty : tz;
}
else
{
t = ty;
}
}
//.........这里部分代码省略.........