Gilmer Posted April 29, 2011 Share Posted April 29, 2011 Hi, i'm trying do a rope system, and I found this topic: http://leadwerks.com...h__1#entry23004 And I used the example of MasteR. Had some bugs, and I fix it. But the problem that I'm having, I can't move the first node, like move a Entity. It move, but have a little "delay" in your movement. I dont know if is cause he's as TBody. I tried use CalcBodyVelocity() and AddBodyForce() too, but I dont had luck. My code is this, i need so much this. Just for clarity, I wanna use this as a cloth fence, where the extremities will fixed, and in the center will fall. Then the nodes of rope, will be the "bones" to model. But this model will move, then the rope with nodes need move together, in the same position. Here is my code, if need, I try explain in other way...thanks [Cable.h] #include "leo.h" class CPhysicsCable { private: int pNodes; TVec3 pStartPoint; TVec3 pEndPoint; float pThickness; bool pAttached; float pLength; TVec3 nodePos; TVec3 Calc; public: TEntity *pBodyNodes; TEntity *pMeshNodes; TVec3 TempPos; TEntity start; TEntity end; TEntity firstJoint; TEntity pPivotStart; TEntity pPivotEnd; CPhysicsCable(TVec3 aStart, TVec3 aEnd, float aThickness, int aNodes, bool aAttached,TEntity aPivotStart,TEntity aPivotEnd) { pNodes = aNodes; pStartPoint = aStart; pEndPoint = aEnd; pThickness = aThickness; pAttached = aAttached; pLength = 0.0; pMeshNodes = new TEntity[pNodes]; pBodyNodes = new TEntity[pNodes]; pPivotStart = aPivotStart; pPivotEnd = aPivotEnd; Create(); } void Create() { start = CreateBodyBox(0.1, 0.1, 0.1, 0); end = CreateBodyBox(0.1, 0.1, 0.1, 0); PositionEntity(start, pStartPoint); PositionEntity(end, pEndPoint); pLength = EntityDistance(start, end)/pNodes; pMeshNodes[0] = CreateCylinder(6, 1, 0); TMaterial material = LoadMaterial("abstract::Cable_node.mat"); PaintEntity(pMeshNodes[0],material); ScaleEntity(pMeshNodes[0], Vec3(pThickness, pLength, pThickness)); pBodyNodes[0] = CreateBodyBox(pThickness, pLength, pThickness); SetBodyMass(pBodyNodes[0], 0.1); EntityType(pBodyNodes[0], 1); EntityParent(pMeshNodes[0], pBodyNodes[0]); PositionEntity(pBodyNodes[0], pStartPoint, 1); PointEntity(pBodyNodes[0], end, 1); PointEntity(pBodyNodes[0], end, 2); PointEntity(pBodyNodes[0], end, 3); TurnEntity(pBodyNodes[0], Vec3(90.0, 0.0, 0.0), 0); MoveEntity(pBodyNodes[0], Vec3(0.0, pLength/2.0, 0.0), 0); firstJoint = CreateJointBall(start, pBodyNodes[0], pStartPoint, Vec3(0.0, 0.0, 0.0)); SetBallJointLimits(firstJoint, 180.0, 180.0, 180.0); for(int i=1; i<pNodes; i++) { pMeshNodes[i] = CopyEntity(pMeshNodes[0]); pBodyNodes[i] = CopyEntity(pBodyNodes[0]); EntityParent(pMeshNodes[i], pBodyNodes[i]); PositionEntity(pBodyNodes[i], EntityPosition(pBodyNodes[i-1]), 1); PointEntity(pBodyNodes[i], end, 1); PointEntity(pBodyNodes[i], end, 2); PointEntity(pBodyNodes[i], end, 3); TurnEntity(pBodyNodes[i], Vec3(90.0, 0.0, 0.0), 0); MoveEntity(pBodyNodes[i], Vec3(0.0, pLength, 0.0), 0); nodePos = EntityPosition(pBodyNodes[i]); TEntity nodeJoint = CreateJointBall(pBodyNodes[i-1], pBodyNodes[i], Vec3(nodePos.X, nodePos.Y, nodePos.Z+(pLength/2.0)), Vec3(0.0, 0.0, 0.0)); SetBallJointLimits(nodeJoint, 0.0, 180.0, 180.0); } if(pAttached==1) { TEntity lastJoint = CreateJointBall(pBodyNodes[pNodes-1], end, pEndPoint, Vec3(0.0, 0.0, 0.0)); SetBallJointLimits (lastJoint, 180.0, 180.0, 180.0); } } void Update() { PositionEntity(start,EntityPosition(pPivotStart)); }; [main] #include "engine.h" #include "Cable.h" int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ) { Initialize() ; RegisterAbstractPath("D:/Projetos/Rally"); SetAppTitle( "Cables" ) ; Graphics( 800, 600 ) ; AFilter() ; TFilter() ; TLight light; TMesh ground; TMaterial material; TFramework framework=CreateFramework(); TLayer layer = GetFrameworkLayer(0); TCamera camera=GetLayerCamera(layer); light=CreateDirectionalLight(); RotateEntity(light,Vec3(45,45,45)); PositionEntity(camera,Vec3(0,0,-2)); float sx = -2; float sy = 1; float sz = 2; float ex = 2; float ey = 1; float ez = 2; TEntity c=CreateCube(); PositionEntity(c,Vec3(sx,sy,sz)); ScaleEntity(c,Vec3(0.2,0.2,0.2)); TEntity c2=CreateCube(); PositionEntity(c2,Vec3(ex,ey,ez)); ScaleEntity(c2,Vec3(0.2,0.2,0.2)); TVec3 startPos = Vec3(sx,sy,sz); TVec3 endPos = Vec3(2,1,2); CPhysicsCable* Cable = new CPhysicsCable(startPos,endPos,0.1,50,1,c,c2); TEntity sphere = CreateSphere(); ScaleEntity(sphere,Vec3(0.3,0.3,0.3)); TVec3 CalcPos; SetBodyVelocity(Cable->pBodyNodes[0],Vec3(100,100,100)); // Game loop while( !KeyHit() && !AppTerminate() ) { if( !AppSuspended() ) // We are not in focus! { //Move if(KeyDown(KEY_RIGHT)==1){ sx = sx + 0.1; ex = ex + 0.1; } if(KeyDown(KEY_LEFT)==1){ sx = sx - 0.1; ex = ex - 0.1; } PositionEntity(c,Vec3(sx,sy,sz)); Cable->Update(); // Update timing and world UpdateAppTime(); UpdateWorld(AppSpeed()) ; // Render RenderFramework(); UpdateFramework(); //Texts DrawText(10,25,"%f",(EntityPosition(Cable->pPivotStart)).X); // Send to screen Flip(0) ; } } // Done return Terminate() ; } Quote Link to comment Share on other sites More sharing options...
Josh Posted April 29, 2011 Share Posted April 29, 2011 If you are using calcvelocity any time, multiply the force you add by the body's mass. However...why not just make the mass of the first and last bodies 0, so they are static? Or if you want them attached to something, make a joint between the end and the body it's attached to. I'm not sure why you need to reposition the first body each frame. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Gilmer Posted May 3, 2011 Author Share Posted May 3, 2011 Thanks Josh...im was trying somethings here, and it working now... Quote Link to comment Share on other sites More sharing options...
Road Kill Kenny Posted July 26, 2011 Share Posted July 26, 2011 Hi, I am having a problem that sounds similar to this. I have made rope similar to this and added a wrecking ball to the end of it. I set it up so you can move the start node body (kinda like a crane) but there is a huuuuge delay between the start node moving and the first link in the rope catching up to it. Its almost like the joint is stretching under force. Is there anyway to stop the joint from stretching. I want to have a crane with a wrecking ball crane and I want the start of the cable to be 1 for 1 with the the attachment to the crane and not being delayed. I noticed on the Newton wiki that there are some extra commands for joints that don't seem to have corresponding commands in leadwerks. Short Story: Is there a way to make ball joints not stretch under force? Quote STS - Scarlet Thread Studios AKA: Engineer Ken Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now! Link to comment Share on other sites More sharing options...
Canardia Posted July 26, 2011 Share Posted July 26, 2011 SetJointStiffness() Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Road Kill Kenny Posted July 27, 2011 Share Posted July 27, 2011 Thanks, that would make sense but for some reason it makes no difference. The joints still stretch. Here is my code for creating a joint and Setting its stiffness maybe I'm doing something wrong. TJoint ropeAnchorStart = CreateJointBall(rStartNode, ropeBodySegs[i], ropeInit, Vec3(0,0,0)); SetBallJointLimits(ropeAnchorStart, 180,180,180); SetJointStiffness(ropeAnchorStart,1); On another note, that command doesn't seem to be on the wiki even though it is an engine command. Quote STS - Scarlet Thread Studios AKA: Engineer Ken Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now! Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.