本文整理汇总了C++中MeshObject::setMaterial方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshObject::setMaterial方法的具体用法?C++ MeshObject::setMaterial怎么用?C++ MeshObject::setMaterial使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshObject
的用法示例。
在下文中一共展示了MeshObject::setMaterial方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setItem
bool MaterialSlot::setItem(Item* item)
{
if (!Slot::setItem(item))
{
return false;
}
if (item)
{
try
{
CeGuiString mat = item->getProperty("material").toString();
CeGuiString mesh = item->getSubmeshName();
///@todo: what to do if actor is null?, think about changing the inventory of an gameobject not in scene
if (mOwner->getActor())
{
MeshObject* mo = dynamic_cast<MeshObject*>(
mOwner->getActor()->getControlledObject());
MergeableMeshObject* mmo = dynamic_cast<MergeableMeshObject*>(
mo);
if (mmo && !mesh.empty())
{
mmo->replaceSubmesh(mSubmesh, mesh.c_str());
}
if (mo)
{
mo->setMaterial(mat.c_str(), mSubmesh);
}
}
}
catch (const IllegalArgumentException&)
{
LOG_ERROR(Logger::RULES, "Item " + item->getName() + " has no property material.");
}
catch (const WrongFormatException&)
{
LOG_ERROR(Logger::RULES, "Item " + item->getName() + " has a property material, but it is no string property.");
}
}
else
{
///@todo reset material?
}
return true;
}
示例2: main
int main(int argc, const char * argv[]) {
// Initialize glfw
if (!glfwInit()){
std::cerr << "Failed to initialize glfw" << std::endl;
exit(EXIT_FAILURE);
}
// Set the error callback for glfw
glfwSetErrorCallback(error_callback);
// Set window settings
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
GLFWwindow *window = glfwCreateWindow(800,600, "OpenGL Renderer", NULL, NULL);
if (!window) {
std::cerr << "Could not create glfw window!" << std::endl;
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetKeyCallback(window, key_callback);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
int width, height;
glfwGetFramebufferSize(window, &width, &height);
glViewport(0, 0, width, height);
float ratio = width / (float) height;
Camera cam(glm::vec3(0,0,-2));
cam.setProjMatrix(ratio);
DefaultMaterial m(glm::vec3(.2f,.2f,.9f));
MeshObject cube;
cube.setMaterial(&m);
SceneNode cubeNode(&cube);
cubeNode.setTransform(glm::scale(glm::mat4(), glm::vec3(2)));
double lastFrameTime = glfwGetTime();
double xpos, ypos;
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
double currentFrameTime = glfwGetTime();
double delta = currentFrameTime - lastFrameTime;
lastFrameTime = currentFrameTime;
cam.translate(glm::vec3(delta * camXSpeed, delta * camYSpeed, delta * camZSpeed));
glfwGetCursorPos(window, &xpos, &ypos);
// Cursor rotation is currently broken.
//cam.rotateFromCursor(2*xpos/width - 1, 2*ypos/height - 1);
cubeNode.render(window, cam.getViewMatrix(), cam.getProjMatrix());
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
示例3: readMeshs
//.........这里部分代码省略.........
// Get file name
XmlAttr * file;
xmlAttribute(file, textureNode);
// Create texture
Texture texture(GL_TEXTURE0, std::string(file->value()));
// Set texture
mesh->setTexture(texture);
}
// Set normal map
XmlNode * normalMapNode = meshNode->first_node("normal-map");
if (normalMapNode) {
// Get file name
XmlAttr * file;
xmlAttribute(file, normalMapNode);
// Create texture
Texture normalMap(GL_TEXTURE2, std::string(file->value()));
// Set texture
mesh->setNormalMap(normalMap);
}
// Set material
XmlNode * material = meshNode->first_node("material");
if (material) {
// Create material
Material * m = new Material();
// Set emissive
XmlNode * emissive = material->first_node("emissive");
if (emissive) {
XmlAttr * r, *g, *b;
xmlAttribute(r, emissive);
xmlAttribute(g, emissive);
xmlAttribute(b, emissive);
// Set diffuse
m->setEmissive(atof(r->value()), atof(g->value()),
atof(b->value()));
}
// Read ambient
XmlNode * ambient = material->first_node("ambient");
if (ambient) {
XmlAttr * r, *g, *b;
xmlAttribute(r, ambient);
xmlAttribute(g, ambient);
xmlAttribute(b, ambient);
// Set diffuse
m->setAmbient(atof(r->value()), atof(g->value()),
atof(b->value()));
}
// Read diffuse
XmlNode * diffuse = material->first_node("diffuse");
if (diffuse) {
XmlAttr * r, *g, *b;
xmlAttribute(r, diffuse);
xmlAttribute(g, diffuse);
xmlAttribute(b, diffuse);
// Set diffuse
m->setDiffuse(atof(r->value()), atof(g->value()),
atof(b->value()));
}
// Read specular
XmlNode * specular = material->first_node("specular");
if (specular) {
XmlAttr * r, *g, *b;
xmlAttribute(r, specular);
xmlAttribute(g, specular);
xmlAttribute(b, specular);
// Set diffuse
m->setSpecular(atof(r->value()), atof(g->value()),
atof(b->value()));
}
// Read specular
XmlNode * shininess = material->first_node("shininess");
if (shininess) {
XmlAttr * value;
xmlAttribute(value, shininess);
// Set diffuse
m->setShininess(atof(value->value()));
}
// Set material
mesh->setMaterial(m);
}
// Read Scripts
XmlNode * scripts = meshNode->first_node("scripts");
readScripts(scene, mesh, scripts);
// Get next cube
meshNode = meshNode->next_sibling("mesh");
}
}