Llist& Llist::operator = (Llist& rho) { if (rho.GetFirst() == NULL) { ClearList(); return *this; } // check to see if this object is equal to the right hand object if (this != &rho) { ClearList(); Node* oldNode = rho.GetFirst(); //clone the old head node _headNode = oldNode->Clone(); //get the next old node oldNode = oldNode->GetNextNode(); //clone the next old node Node* newNode = oldNode->Clone(); //set Next Node for head node _headNode->SetNextNode(newNode); //set prev node for next node to the new _headNode newNode->SetPrevNode(_headNode); //get the pointer to the next node in the old list oldNode = oldNode->GetNextNode(); while (oldNode != NULL) { //clone the old Node Node* nextNode = oldNode->Clone(); //set the next node of newNode newNode->SetNextNode(nextNode); //set the prev node of nextNode to newNode nextNode->SetPrevNode(newNode); //point newNode to nextNode //TODO check this newNode = nextNode; //get the pointer to the next node in the old list oldNode = oldNode->GetNextNode(); } _endNode = newNode; _nodeCount = rho.GetCount(); } //Return a reference to this object. return *this; }
Llist::Llist(Llist& lst) { //--- Test for empty list ------------ if (lst._headNode == NULL) return; // check to see if this object is equal to the right hand object if (this != &lst) { ClearList(); Node* oldNode = lst.GetFirst(); //clone the old head node _headNode = oldNode->Clone(); //get the next old node oldNode = oldNode->GetNextNode(); //clone the next old node Node* newNode = oldNode->Clone(); //set Next Node for head node _headNode->SetNextNode(newNode); //set prev node for next node to the new _headNode newNode->SetPrevNode(_headNode); //get the pointer to the next node in the old list oldNode = oldNode->GetNextNode(); while (oldNode != NULL) { //clone the old Node Node* nextNode = oldNode->Clone(); //set the next node of newNode newNode->SetNextNode(nextNode); //set the prev node of nextNode to newNode nextNode->SetPrevNode(newNode); //point newNode to nextNode //TODO check this newNode = nextNode; //get the pointer to the next node in the old list oldNode = oldNode->GetNextNode(); } _endNode = newNode; _nodeCount = lst.GetCount(); } //print out the copy constructor message string classname = typeid(*this).name(); cout << classname << COPY_CONSTRUCTOR << endl; }
bool CloneNode() { Node *srcNode = new Node(); srcNode->SetName("Tested Node"); Node *dstNullNode = dynamic_cast<Node *>(srcNode->Clone()); Node *dstNode = NULL; dstNode = dynamic_cast<Node *>(srcNode->Clone(dstNode)); if(dstNode && dstNullNode) { bool compareResult = (dstNode->GetName() == dstNullNode->GetName()); SafeRelease(srcNode); SafeRelease(dstNode); SafeRelease(dstNullNode); return compareResult; } return false; }
Llist* Llist::Clone() { //clone this list object, return a pointer to the clone Node* oldNode = _headNode; //clone the old head node Node* newHead = oldNode->Clone(); //get the next old node oldNode = oldNode->GetNextNode(); //clone the next old node Node* newNode = oldNode->Clone(); //set Next Node for head new head node newHead->SetNextNode(newNode); //set prev node for next node to the new _headNode newNode->SetPrevNode(newHead); //get the pointer to the next node in the old list oldNode = oldNode->GetNextNode(); //copy the rest of the list while (oldNode != NULL) { //clone the old Node Node* nextNode = oldNode->Clone(); //set the next node of newNode newNode->SetNextNode(nextNode); //set the prev node of nextNode to newNode nextNode->SetPrevNode(newNode); //point newNode to nextNode //TODO check this newNode = nextNode; //get the pointer to the next node in the old list oldNode = oldNode->GetNextNode(); } Node* newEnd = newNode; Llist* newList = new Llist(_nodeCount); newList->SetFirst(newHead); newList->SetLast(newEnd); //Return a reference to the new Llist return newList; }
//================================================================================= // Note that we don't provide any mechanism for invalidating cache entries // when the file on disk is modified in a way that it doesn't match what // we have loaded in cache memory. Node* Context::TreeCacheLookup( const Path& path ) { if( !treeCacheMap ) return 0; std::string key; if( !path.GetPath( key, true ) ) return 0; TreeCacheMap::iterator iter = treeCacheMap->find( key ); if( iter == treeCacheMap->end() ) return 0; Node* root = iter->second; Node::CopyParameters copyParameters; Node* clone = root->Clone( *this, copyParameters ); return clone; }
// the constructor CCDIKSolver::CCDIKSolver(Actor* actor, Node* startNode, Node* endNode, bool cloneNodes) : Controller( actor ) { mStartNode = startNode; mEndNode = endNode; // if we want to clone the IK chain if (cloneNodes) { mEndNode_Clone = endNode->Clone(actor); Node *tempNode = mEndNode_Clone; Node *i = endNode->GetParent(); while (i != startNode) { tempNode->SetParent(i->Clone(actor)); tempNode->GetParent()->AddChild(tempNode); tempNode = tempNode->GetParent(); i = i->GetParent(); } mStartNode_Clone = mStartNode->Clone(actor); tempNode->SetParent(mStartNode_Clone); mStartNode_Clone->AddChild(tempNode); mStartNode_Clone->SetParent(startNode->GetParent()); // when cloning nodes, one iteration is enough to find the new solution mMaxIterations = 1; } else { mEndNode_Clone = mEndNode; mStartNode_Clone = mStartNode; // The solver usually doesn't take more than 10 iterations to find the solution if its in reach. // Its usually below 5. If this is set higher, then the solver will meerly take longer to realise // that it cant reach the goal. mMaxIterations = 10; } mHasSolution = false; mDistThreshold = 0.1f; mDoJointLimits = true; mGoal.Set(0, 0, 0); }
//================================================================================= /*virtual*/ bool Node::Copy( const Node* node, Context& context, const CopyParameters& copyParameters ) { if( copyParameters.copyIdentityInfo ) { // Copy the name. name = node->name; // Copy the explanations. In the idea of clonnig a template tree, // this explanation text will become very redundant and in that way, // potentially take up a lot of space unecessarily. for( int index = 0; index < EXPLANATION_COUNT; index++ ) explanation[ index ] = node->explanation[ index ]; } // We don't know who are parent is yet unless we're just copying the node value. if( copyParameters.copyChildrenDisposition != COPY_NODE_AND_LEAVE_CHILDREN_UNTOUCHED ) parent = 0; // Remove children in preparation for copying over a new set of children, or do so if told to do so. if( copyParameters.copyChildrenDisposition == COPY_NODE_AND_CHILDREN || copyParameters.copyChildrenDisposition == COPY_NODE_AND_REMOVE_ALL_CHILDREN ) DeleteChildren(); // Clone the children of the given node if told to do so. if( node->children && copyParameters.copyChildrenDisposition == COPY_NODE_AND_CHILDREN ) { children = new std::list< Node* >(); for( List::iterator iter = node->children->begin(); iter != node->children->end(); iter++ ) { Node* child = *iter; Node* clone = child->Clone( context, copyParameters ); if( !clone ) return context.IssueError( "Failed to clone node \"%s\" of type \"%s\".", child->name.c_str(), child->GetType().c_str() ); children->push_back( clone ); clone->parent = this; } } // Clone any meta-data. if( node->metaData && copyParameters.copyMetaData ) { if( !metaData ) { Context::MetaDataCreatorFunc metaDataCreatorFunc = context.GetMetaDataCreatorFunc(); if( metaDataCreatorFunc ) metaData = metaDataCreatorFunc(); else return context.IssueError( "Failed to copy meta-data of node \"%s\" of type \"%s\", because there is no meta-data creator function.", name.c_str(), GetType().c_str() ); if( !metaData ) return context.IssueError( "Failed to copy meta-data of node \"%s\" of type \"%s\", because the meta-data creator failed.", name.c_str(), GetType().c_str() ); metaData->PostCreate( this ); } if( !metaData->Copy( node->metaData, context ) ) return context.IssueError( "Failed to copy meta-data of node \"%s\" of type \"%s\".", name.c_str(), GetType().c_str() ); } return true; }
void Urho2DConstraints::CreateScene() { scene_ = new Scene(context_); scene_->CreateComponent<Octree>(); scene_->CreateComponent<DebugRenderer>(); auto* physicsWorld = scene_->CreateComponent<PhysicsWorld2D>(); // Create 2D physics world component physicsWorld->SetDrawJoint(true); // Display the joints (Note that DrawDebugGeometry() must be set to true to acually draw the joints) drawDebug_ = true; // Set DrawDebugGeometry() to true // Create camera cameraNode_ = scene_->CreateChild("Camera"); // Set camera's position cameraNode_->SetPosition(Vector3(0.0f, 0.0f, 0.0f)); // Note that Z setting is discarded; use camera.zoom instead (see MoveCamera() below for example) camera_ = cameraNode_->CreateComponent<Camera>(); camera_->SetOrthographic(true); auto* graphics = GetSubsystem<Graphics>(); camera_->SetOrthoSize((float)graphics->GetHeight() * PIXEL_SIZE); camera_->SetZoom(1.2f * Min((float)graphics->GetWidth() / 1280.0f, (float)graphics->GetHeight() / 800.0f)); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.2) is set for full visibility at 1280x800 resolution) // Set up a viewport to the Renderer subsystem so that the 3D scene can be seen ea::shared_ptr<Viewport> viewport(new Viewport(context_, scene_, camera_)); auto* renderer = GetSubsystem<Renderer>(); renderer->SetViewport(0, viewport); Zone* zone = renderer->GetDefaultZone(); zone->SetFogColor(Color(0.1f, 0.1f, 0.1f)); // Set background color for the scene // Create 4x3 grid for (unsigned i = 0; i<5; ++i) { Node* edgeNode = scene_->CreateChild("VerticalEdge"); auto* edgeBody = edgeNode->CreateComponent<RigidBody2D>(); if (!dummyBody) dummyBody = edgeBody; // Mark first edge as dummy body (used by mouse pick) auto* edgeShape = edgeNode->CreateComponent<CollisionEdge2D>(); edgeShape->SetVertices(Vector2(i*2.5f -5.0f, -3.0f), Vector2(i*2.5f -5.0f, 3.0f)); edgeShape->SetFriction(0.5f); // Set friction } for (unsigned j = 0; j<4; ++j) { Node* edgeNode = scene_->CreateChild("HorizontalEdge"); /*RigidBody2D* edgeBody = */edgeNode->CreateComponent<RigidBody2D>(); auto* edgeShape = edgeNode->CreateComponent<CollisionEdge2D>(); edgeShape->SetVertices(Vector2(-5.0f, j*2.0f -3.0f), Vector2(5.0f, j*2.0f -3.0f)); edgeShape->SetFriction(0.5f); // Set friction } auto* cache = GetSubsystem<ResourceCache>(); // Create a box (will be cloned later) Node* box = scene_->CreateChild("Box"); box->SetPosition(Vector3(0.8f, -2.0f, 0.0f)); auto* boxSprite = box->CreateComponent<StaticSprite2D>(); boxSprite->SetSprite(cache->GetResource<Sprite2D>("Urho2D/Box.png")); auto* boxBody = box->CreateComponent<RigidBody2D>(); boxBody->SetBodyType(BT_DYNAMIC); boxBody->SetLinearDamping(0.0f); boxBody->SetAngularDamping(0.0f); auto* shape = box->CreateComponent<CollisionBox2D>(); // Create box shape shape->SetSize(Vector2(0.32f, 0.32f)); // Set size shape->SetDensity(1.0f); // Set shape density (kilograms per meter squared) shape->SetFriction(0.5f); // Set friction shape->SetRestitution(0.1f); // Set restitution (slight bounce) // Create a ball (will be cloned later) Node* ball = scene_->CreateChild("Ball"); ball->SetPosition(Vector3(1.8f, -2.0f, 0.0f)); auto* ballSprite = ball->CreateComponent<StaticSprite2D>(); ballSprite->SetSprite(cache->GetResource<Sprite2D>("Urho2D/Ball.png")); auto* ballBody = ball->CreateComponent<RigidBody2D>(); ballBody->SetBodyType(BT_DYNAMIC); ballBody->SetLinearDamping(0.0f); ballBody->SetAngularDamping(0.0f); auto* ballShape = ball->CreateComponent<CollisionCircle2D>(); // Create circle shape ballShape->SetRadius(0.16f); // Set radius ballShape->SetDensity(1.0f); // Set shape density (kilograms per meter squared) ballShape->SetFriction(0.5f); // Set friction ballShape->SetRestitution(0.6f); // Set restitution: make it bounce // Create a polygon Node* polygon = scene_->CreateChild("Polygon"); polygon->SetPosition(Vector3(1.6f, -2.0f, 0.0f)); polygon->SetScale(0.7f); auto* polygonSprite = polygon->CreateComponent<StaticSprite2D>(); polygonSprite->SetSprite(cache->GetResource<Sprite2D>("Urho2D/Aster.png")); auto* polygonBody = polygon->CreateComponent<RigidBody2D>(); polygonBody->SetBodyType(BT_DYNAMIC); auto* polygonShape = polygon->CreateComponent<CollisionPolygon2D>(); // TODO: create from ea::vector<Vector2> using SetVertices() polygonShape->SetVertexCount(6); // Set number of vertices (mandatory when using SetVertex()) polygonShape->SetVertex(0, Vector2(-0.8f, -0.3f)); polygonShape->SetVertex(1, Vector2(0.5f, -0.8f)); polygonShape->SetVertex(2, Vector2(0.8f, -0.3f)); polygonShape->SetVertex(3, Vector2(0.8f, 0.5f)); polygonShape->SetVertex(4, Vector2(0.5f, 0.9f)); polygonShape->SetVertex(5, Vector2(-0.5f, 0.7f)); polygonShape->SetDensity(1.0f); // Set shape density (kilograms per meter squared) polygonShape->SetFriction(0.3f); // Set friction polygonShape->SetRestitution(0.0f); // Set restitution (no bounce) // Create a ConstraintDistance2D CreateFlag("ConstraintDistance2D", -4.97f, 3.0f); // Display Text3D flag Node* boxDistanceNode = box->Clone(); Node* ballDistanceNode = ball->Clone(); auto* ballDistanceBody = ballDistanceNode->GetComponent<RigidBody2D>(); boxDistanceNode->SetPosition(Vector3(-4.5f, 2.0f, 0.0f)); ballDistanceNode->SetPosition(Vector3(-3.0f, 2.0f, 0.0f)); auto* constraintDistance = boxDistanceNode->CreateComponent<ConstraintDistance2D>(); // Apply ConstraintDistance2D to box constraintDistance->SetOtherBody(ballDistanceBody); // Constrain ball to box constraintDistance->SetOwnerBodyAnchor(boxDistanceNode->GetPosition2D()); constraintDistance->SetOtherBodyAnchor(ballDistanceNode->GetPosition2D()); // Make the constraint soft (comment to make it rigid, which is its basic behavior) constraintDistance->SetFrequencyHz(4.0f); constraintDistance->SetDampingRatio(0.5f); // Create a ConstraintFriction2D ********** Not functional. From Box2d samples it seems that 2 anchors are required, Urho2D only provides 1, needs investigation *********** CreateFlag("ConstraintFriction2D", 0.03f, 1.0f); // Display Text3D flag Node* boxFrictionNode = box->Clone(); Node* ballFrictionNode = ball->Clone(); boxFrictionNode->SetPosition(Vector3(0.5f, 0.0f, 0.0f)); ballFrictionNode->SetPosition(Vector3(1.5f, 0.0f, 0.0f)); auto* constraintFriction = boxFrictionNode->CreateComponent<ConstraintFriction2D>(); // Apply ConstraintDistance2D to box constraintFriction->SetOtherBody(ballFrictionNode->GetComponent<RigidBody2D>()); // Constraint ball to box //constraintFriction->SetOwnerBodyAnchor(boxNode->GetPosition2D()); //constraintFriction->SetOtherBodyAnchor(ballNode->GetPosition2D()); //constraintFriction->SetMaxForce(10.0f); // ballBody.mass * gravity //constraintDistance->SetMaxTorque(10.0f); // ballBody.mass * radius * gravity // Create a ConstraintGear2D CreateFlag("ConstraintGear2D", -4.97f, -1.0f); // Display Text3D flag Node* baseNode = box->Clone(); auto* tempBody = baseNode->GetComponent<RigidBody2D>(); // Get body to make it static tempBody->SetBodyType(BT_STATIC); baseNode->SetPosition(Vector3(-3.7f, -2.5f, 0.0f)); Node* ball1Node = ball->Clone(); ball1Node->SetPosition(Vector3(-4.5f, -2.0f, 0.0f)); auto* ball1Body = ball1Node->GetComponent<RigidBody2D>(); Node* ball2Node = ball->Clone(); ball2Node->SetPosition(Vector3(-3.0f, -2.0f, 0.0f)); auto* ball2Body = ball2Node->GetComponent<RigidBody2D>(); auto* gear1 = baseNode->CreateComponent<ConstraintRevolute2D>(); // Apply constraint to baseBox gear1->SetOtherBody(ball1Body); // Constrain ball1 to baseBox gear1->SetAnchor(ball1Node->GetPosition2D()); auto* gear2 = baseNode->CreateComponent<ConstraintRevolute2D>(); // Apply constraint to baseBox gear2->SetOtherBody(ball2Body); // Constrain ball2 to baseBox gear2->SetAnchor(ball2Node->GetPosition2D()); auto* constraintGear = ball1Node->CreateComponent<ConstraintGear2D>(); // Apply constraint to ball1 constraintGear->SetOtherBody(ball2Body); // Constrain ball2 to ball1 constraintGear->SetOwnerConstraint(gear1); constraintGear->SetOtherConstraint(gear2); constraintGear->SetRatio(1.0f); ball1Body->ApplyAngularImpulse(0.015f, true); // Animate // Create a vehicle from a compound of 2 ConstraintWheel2Ds CreateFlag("ConstraintWheel2Ds compound", -2.45f, -1.0f); // Display Text3D flag Node* car = box->Clone(); car->SetScale(Vector3(4.0f, 1.0f, 0.0f)); car->SetPosition(Vector3(-1.2f, -2.3f, 0.0f)); auto* tempSprite = car->GetComponent<StaticSprite2D>(); // Get car Sprite in order to draw it on top tempSprite->SetOrderInLayer(0); // Draw car on top of the wheels (set to -1 to draw below) Node* ball1WheelNode = ball->Clone(); ball1WheelNode->SetPosition(Vector3(-1.6f, -2.5f, 0.0f)); Node* ball2WheelNode = ball->Clone(); ball2WheelNode->SetPosition(Vector3(-0.8f, -2.5f, 0.0f)); auto* wheel1 = car->CreateComponent<ConstraintWheel2D>(); wheel1->SetOtherBody(ball1WheelNode->GetComponent<RigidBody2D>()); wheel1->SetAnchor(ball1WheelNode->GetPosition2D()); wheel1->SetAxis(Vector2(0.0f, 1.0f)); wheel1->SetMaxMotorTorque(20.0f); wheel1->SetFrequencyHz(4.0f); wheel1->SetDampingRatio(0.4f); auto* wheel2 = car->CreateComponent<ConstraintWheel2D>(); wheel2->SetOtherBody(ball2WheelNode->GetComponent<RigidBody2D>()); wheel2->SetAnchor(ball2WheelNode->GetPosition2D()); wheel2->SetAxis(Vector2(0.0f, 1.0f)); wheel2->SetMaxMotorTorque(10.0f); wheel2->SetFrequencyHz(4.0f); wheel2->SetDampingRatio(0.4f); // ConstraintMotor2D CreateFlag("ConstraintMotor2D", 2.53f, -1.0f); // Display Text3D flag Node* boxMotorNode = box->Clone(); tempBody = boxMotorNode->GetComponent<RigidBody2D>(); // Get body to make it static tempBody->SetBodyType(BT_STATIC); Node* ballMotorNode = ball->Clone(); boxMotorNode->SetPosition(Vector3(3.8f, -2.1f, 0.0f)); ballMotorNode->SetPosition(Vector3(3.8f, -1.5f, 0.0f)); auto* constraintMotor = boxMotorNode->CreateComponent<ConstraintMotor2D>(); constraintMotor->SetOtherBody(ballMotorNode->GetComponent<RigidBody2D>()); // Constrain ball to box constraintMotor->SetLinearOffset(Vector2(0.0f, 0.8f)); // Set ballNode position relative to boxNode position = (0,0) constraintMotor->SetAngularOffset(0.1f); constraintMotor->SetMaxForce(5.0f); constraintMotor->SetMaxTorque(10.0f); constraintMotor->SetCorrectionFactor(1.0f); constraintMotor->SetCollideConnected(true); // doesn't work // ConstraintMouse2D is demonstrated in HandleMouseButtonDown() function. It is used to "grasp" the sprites with the mouse. CreateFlag("ConstraintMouse2D", 0.03f, -1.0f); // Display Text3D flag // Create a ConstraintPrismatic2D CreateFlag("ConstraintPrismatic2D", 2.53f, 3.0f); // Display Text3D flag Node* boxPrismaticNode = box->Clone(); tempBody = boxPrismaticNode->GetComponent<RigidBody2D>(); // Get body to make it static tempBody->SetBodyType(BT_STATIC); Node* ballPrismaticNode = ball->Clone(); boxPrismaticNode->SetPosition(Vector3(3.3f, 2.5f, 0.0f)); ballPrismaticNode->SetPosition(Vector3(4.3f, 2.0f, 0.0f)); auto* constraintPrismatic = boxPrismaticNode->CreateComponent<ConstraintPrismatic2D>(); constraintPrismatic->SetOtherBody(ballPrismaticNode->GetComponent<RigidBody2D>()); // Constrain ball to box constraintPrismatic->SetAxis(Vector2(1.0f, 1.0f)); // Slide from [0,0] to [1,1] constraintPrismatic->SetAnchor(Vector2(4.0f, 2.0f)); constraintPrismatic->SetLowerTranslation(-1.0f); constraintPrismatic->SetUpperTranslation(0.5f); constraintPrismatic->SetEnableLimit(true); constraintPrismatic->SetMaxMotorForce(1.0f); constraintPrismatic->SetMotorSpeed(0.0f); // ConstraintPulley2D CreateFlag("ConstraintPulley2D", 0.03f, 3.0f); // Display Text3D flag Node* boxPulleyNode = box->Clone(); Node* ballPulleyNode = ball->Clone(); boxPulleyNode->SetPosition(Vector3(0.5f, 2.0f, 0.0f)); ballPulleyNode->SetPosition(Vector3(2.0f, 2.0f, 0.0f)); auto* constraintPulley = boxPulleyNode->CreateComponent<ConstraintPulley2D>(); // Apply constraint to box constraintPulley->SetOtherBody(ballPulleyNode->GetComponent<RigidBody2D>()); // Constrain ball to box constraintPulley->SetOwnerBodyAnchor(boxPulleyNode->GetPosition2D()); constraintPulley->SetOtherBodyAnchor(ballPulleyNode->GetPosition2D()); constraintPulley->SetOwnerBodyGroundAnchor(boxPulleyNode->GetPosition2D() + Vector2(0.0f, 1.0f)); constraintPulley->SetOtherBodyGroundAnchor(ballPulleyNode->GetPosition2D() + Vector2(0.0f, 1.0f)); constraintPulley->SetRatio(1.0); // Weight ratio between ownerBody and otherBody // Create a ConstraintRevolute2D CreateFlag("ConstraintRevolute2D", -2.45f, 3.0f); // Display Text3D flag Node* boxRevoluteNode = box->Clone(); tempBody = boxRevoluteNode->GetComponent<RigidBody2D>(); // Get body to make it static tempBody->SetBodyType(BT_STATIC); Node* ballRevoluteNode = ball->Clone(); boxRevoluteNode->SetPosition(Vector3(-2.0f, 1.5f, 0.0f)); ballRevoluteNode->SetPosition(Vector3(-1.0f, 2.0f, 0.0f)); auto* constraintRevolute = boxRevoluteNode->CreateComponent<ConstraintRevolute2D>(); // Apply constraint to box constraintRevolute->SetOtherBody(ballRevoluteNode->GetComponent<RigidBody2D>()); // Constrain ball to box constraintRevolute->SetAnchor(Vector2(-1.0f, 1.5f)); constraintRevolute->SetLowerAngle(-1.0f); // In radians constraintRevolute->SetUpperAngle(0.5f); // In radians constraintRevolute->SetEnableLimit(true); constraintRevolute->SetMaxMotorTorque(10.0f); constraintRevolute->SetMotorSpeed(0.0f); constraintRevolute->SetEnableMotor(true); // Create a ConstraintRope2D CreateFlag("ConstraintRope2D", -4.97f, 1.0f); // Display Text3D flag Node* boxRopeNode = box->Clone(); tempBody = boxRopeNode->GetComponent<RigidBody2D>(); tempBody->SetBodyType(BT_STATIC); Node* ballRopeNode = ball->Clone(); boxRopeNode->SetPosition(Vector3(-3.7f, 0.7f, 0.0f)); ballRopeNode->SetPosition(Vector3(-4.5f, 0.0f, 0.0f)); auto* constraintRope = boxRopeNode->CreateComponent<ConstraintRope2D>(); constraintRope->SetOtherBody(ballRopeNode->GetComponent<RigidBody2D>()); // Constrain ball to box constraintRope->SetOwnerBodyAnchor(Vector2(0.0f, -0.5f)); // Offset from box (OwnerBody) : the rope is rigid from OwnerBody center to this ownerBodyAnchor constraintRope->SetMaxLength(0.9f); // Rope length constraintRope->SetCollideConnected(true); // Create a ConstraintWeld2D CreateFlag("ConstraintWeld2D", -2.45f, 1.0f); // Display Text3D flag Node* boxWeldNode = box->Clone(); Node* ballWeldNode = ball->Clone(); boxWeldNode->SetPosition(Vector3(-0.5f, 0.0f, 0.0f)); ballWeldNode->SetPosition(Vector3(-2.0f, 0.0f, 0.0f)); auto* constraintWeld = boxWeldNode->CreateComponent<ConstraintWeld2D>(); constraintWeld->SetOtherBody(ballWeldNode->GetComponent<RigidBody2D>()); // Constrain ball to box constraintWeld->SetAnchor(boxWeldNode->GetPosition2D()); constraintWeld->SetFrequencyHz(4.0f); constraintWeld->SetDampingRatio(0.5f); // Create a ConstraintWheel2D CreateFlag("ConstraintWheel2D", 2.53f, 1.0f); // Display Text3D flag Node* boxWheelNode = box->Clone(); Node* ballWheelNode = ball->Clone(); boxWheelNode->SetPosition(Vector3(3.8f, 0.0f, 0.0f)); ballWheelNode->SetPosition(Vector3(3.8f, 0.9f, 0.0f)); auto* constraintWheel = boxWheelNode->CreateComponent<ConstraintWheel2D>(); constraintWheel->SetOtherBody(ballWheelNode->GetComponent<RigidBody2D>()); // Constrain ball to box constraintWheel->SetAnchor(ballWheelNode->GetPosition2D()); constraintWheel->SetAxis(Vector2(0.0f, 1.0f)); constraintWheel->SetEnableMotor(true); constraintWheel->SetMaxMotorTorque(1.0f); constraintWheel->SetMotorSpeed(0.0f); constraintWheel->SetFrequencyHz(4.0f); constraintWheel->SetDampingRatio(0.5f); constraintWheel->SetCollideConnected(true); // doesn't work }
virtual void ApplyNode(Node &node) { assert(root); root->AddChild(node.Clone()); }