Hi,
I wrote a function to create a 3D arrow made of one cylinder an two cones :
void create3DArrow(Node** inArrowNode, float inSize)
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
//create a 3D arrow with one cylinder and two cones
SharedPtr<Node> mArrowCylinderNode;
SharedPtr<StaticModel> mArrowCylinderObject;
SharedPtr<Node> mArrowCone1Node;
SharedPtr<StaticModel> mArrowCone1Object;
SharedPtr<Node> mArrowCone2Node;
SharedPtr<StaticModel> mArrowCone2Object;
float coneSize = 1.5;
float coneThickness = 1.0;
float coneZ = inSize/2.0 - coneSize/2.0;
float cylinderSize = inSize - 2*coneSize;
float cylinderThickness = 0.5;
mArrowCylinderNode = scene_->CreateChild("ArrowCylinder");
mArrowCylinderObject = mArrowCylinderNode->CreateComponent<StaticModel>();
mArrowCylinderObject->SetModel(cache->GetResource<Model>("Models/Cylinder.mdl"));
mArrowCylinderNode->SetScale(Vector3(cylinderThickness, cylinderSize, cylinderThickness));
mArrowCylinderNode->SetPosition(Vector3(0, 0, 0));
mArrowCone1Node = scene_->CreateChild("ArrowCone1");
mArrowCone1Object = mArrowCone1Node->CreateComponent<StaticModel>();
mArrowCone1Object->SetModel(cache->GetResource<Model>("Models/Cone.mdl"));
mArrowCone1Node->SetScale(Vector3(coneThickness, coneSize, coneThickness));
mArrowCone1Node->SetPosition(Vector3(0, coneZ, 0));
mArrowCone2Node = scene_->CreateChild("ArrowCone2");
mArrowCone2Object = mArrowCone2Node->CreateComponent<StaticModel>();
mArrowCone2Object->SetModel(cache->GetResource<Model>("Models/Cone.mdl"));
mArrowCone2Node->SetScale(Vector3(coneThickness, coneSize, coneThickness));
mArrowCone2Node->SetRotation(Quaternion(180, 0, 0));
mArrowCone2Node->SetPosition(Vector3(0, -coneZ, 0));
*inArrowNode = scene_->CreateChild("Arrow");
(*inArrowNode)->AddChild(mArrowCylinderNode, 0);
(*inArrowNode)->AddChild(mArrowCone1Node, 1);
(*inArrowNode)->AddChild(mArrowCone2Node, 2);
}
So I do :
Node* myArrow;
float arrowSize = 10;
create3DArrow(&myArrow, arrowSize );
And then I can do :
myArrow->SetPosition(...); //the center is the center of the cylinder
myArrow->SetRotation(...);
which gives me for example :
My question is how to modify the size of the cylinder in the arrow to make it longer or smaller once it is created. I don’t want to have class members for the cylinder and the cones as I create several arrows. So how to access the cylinder and the cones in the parent node myArrow to change their scale and position / rotation?
Thanks.