I'm attempting to generate and render a forest of trees. Each trees have branches that radiate from the center of the tree at various angles and heights. But rotating (using setRotation()) either the IMeshSceneNode representing the branches or it's parents yields strange results.
To represent the branches I create an IMesh and a texture re-use like so:
Code: Select all
f32 branch_length = 14.9f; // Height of the texture image but also length of the branch
scene::IMesh* branch_plane = geometryCreator->createPlaneMesh(
core::dimension2df(10.f, branch_length), // 10 is the width of the texture image and width of the branch
core::dimension2du(1, 1) // I only need 1x1 flat
);
irr::video::ITexture* branchTexture =
driver->getTexture((exe_folder + "../media/branch.png").c_str());
To "attach" the branch to the tree I create an empty ISceneNode in the center of the trunk at the height that I want the branch to be. This branch node has the tree as its parent and would act as a pivot to simplify the future rotations I want to do. I then create an IMeshSceneNode for the branch in a similar way to how I created the tree. This branch mesh node has the branch node as its parent. I use setPosition() to the end of the branch coincide with the position of its parent branch node. Finally I try to rotate the parent node so that the branch bends downward... but nothing happens. See below for the important code doing what I describe above:
Code: Select all
scene::ISceneNode* bnode = SceneManager->addEmptySceneNode(tree); // Create branch node to rotate branch around
bnode->setPosition(
core::vector3df(0, 1000, 0) // Move branch to desired height on tree in the center of the trunk
);
// Add branch branch node
scene::IMeshSceneNode* branch = SceneManager->addMeshSceneNode(
branch_plane,
bnode
);
// Add texture, and set material properties etc... I've left this out because it isn't relevant
branch->setPosition(
core::vector3df(0.f, 0.f, branch_length/2.f) // Move branch out from the center of the tree
);
bnode->setRotation(core::vector3df(45.f, 0.f, 0.f)); // Rotate branch 45 degrees around the x-axis... or not
Code: Select all
bnode->setRotation(core::vector3df(0.f 0.f, 45.f));
Clearly I have missed something along the way. I've spent hours searching the forum but came up with nothing that addressed my issue. If anybody can provide advice to lead me on the right path I would be greatly appreciative.
Thanks very much!