本文整理汇总了C++中TriangleMesh::transform方法的典型用法代码示例。如果您正苦于以下问题:C++ TriangleMesh::transform方法的具体用法?C++ TriangleMesh::transform怎么用?C++ TriangleMesh::transform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TriangleMesh
的用法示例。
在下文中一共展示了TriangleMesh::transform方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseMesh
Actor* Parser::parseMesh(xml_node_iterator sceneElement)
{
// setting the mesh
const char* filename = sceneElement->attribute("file").value();
TriangleMesh* mesh = MeshReader().execute(filename);
Primitive* primitive = new TriangleMeshShape(mesh);
xml_node op;
if ((op = sceneElement->child("transform")) != NULL) {
vec3 position(0, 0, 0);
quat q(vec3(0, 0, 0));
vec3 scale(1, 1, 1);
float x, y, z;
xml_object_range<xml_node_iterator> transformations = op.children();
for (xml_node_iterator transformation = transformations.begin(); transformation != transformations.end(); ++transformation)
{
if (strcmp(transformation->name(), "position") == 0)
{
const char * stringTranslation = transformation->text().as_string();
sscanf(stringTranslation, "%f %f %f", &x, &y, &z);
vec3 translationVec(x, y, z);
position = translationVec;
}
else if (strcmp(transformation->name(), "scale") == 0)
{
float s_ = transformation->text().as_float();
vec3 newS(s_, s_, s_);
scale = newS;
}
else if (strcmp(transformation->name(), "rotation") == 0)
{
float angle = transformation->child("angle").text().as_float();
const char * _Axis = transformation->child("axis").text().as_string();
sscanf(_Axis, "%f %f %f", &x, &y, &z);
vec3 axis(x, y, z);
q = quat(axis, angle);
}
mesh->transform(mat4::TRS(position, q, scale));
}
}
if ((op = sceneElement->child("material")) != NULL) {
Material * material = parseMaterial(op);
primitive->setMaterial(material);
}
else
{
Material * material = MaterialFactory::New();
primitive->setMaterial(material->getDefault());
}
Actor* act = new Actor(*primitive);
act->setName(filename);
return act;
}
示例2: parseSphere
Actor* Parser::parseSphere(xml_node_iterator sceneElement)
{
// default values
vec3 center(0, 0, 0);
REAL radius = 1.0;
int meridians = 16;
// opt values
xml_node op;
op = sceneElement->child("center");
REAL x, y, z;
if (op != NULL)
{
const char* center_vector = op.text().as_string();
sscanf(center_vector, "%f %f %f", &x, &y, &z);
center.set(x, y, z);
}
op = sceneElement->child("radius");
if (op != NULL)
radius = op.text().as_float();
op = sceneElement->child("meridians");
if (op != NULL)
meridians = op.text().as_int();
// now, lets make the mesh of Sphere
TriangleMesh* sphereMesh = MeshSweeper::makeSphere(center, radius, meridians);
Primitive* primitive = new TriangleMeshShape(sphereMesh);
if ((op = sceneElement->child("transform")) != NULL) {
vec3 position(0, 0, 0);
quat q(vec3(0, 0, 0));
vec3 scale(1, 1, 1);
float x, y, z;
xml_object_range<xml_node_iterator> transformations = op.children();
for (xml_node_iterator transformation = transformations.begin(); transformation != transformations.end(); ++transformation)
{
if (strcmp(transformation->name(), "position") == 0)
{
const char * stringTranslation = transformation->text().as_string();
sscanf(stringTranslation, "%f %f %f", &x, &y, &z);
vec3 translationVec(x, y, z);
position = translationVec;
}
else if (strcmp(transformation->name(), "scale") == 0)
{
float s_ = transformation->text().as_float();
vec3 newS(s_, s_, s_);
scale = newS;
}
else if (strcmp(transformation->name(), "rotation") == 0)
{
float angle = transformation->child("angle").text().as_float();
const char * _Axis = transformation->child("axis").text().as_string();
sscanf(_Axis, "%f %f %f", &x, &y, &z);
vec3 axis(x, y, z);
q = quat(axis, angle);
}
sphereMesh->transform(mat4::TRS(position, q, scale));
}
}
if ((op = sceneElement->child("material")) != NULL) {
Material * material = parseMaterial(op);
primitive->setMaterial(material);
}
else
{
Material * material = MaterialFactory::New();
primitive->setMaterial(material->getDefault());
}
Actor* act = new Actor(*primitive);
act->setName("sphere");
return act;
}