I am realize rope based on Newton. But I have probleb...

Discussion about everything. New games, 3d math, development tips...
Post Reply
Magnet
Posts: 101
Joined: Wed Sep 27, 2006 7:32 pm

I am realize rope based on Newton. But I have probleb...

Post by Magnet »

I am realize rope beased on Newton Physic.
I am create many small objects (size=1,1,1) and connect it by ball constraint.

Code: Select all

ISceneManager* smgr = device->getSceneManager();
	//Create Rope connected to prev box
	NewtonBody *link0,*link1;
	link0 = firstSegment.Body;
	vector3df lastPos = firstSegment.Node->getPosition();
	for(int i=0;i<Count;i++)
	{
		NewtonCollision* collision = NewtonCreateBox(nWorld,1, 1, 1 , NULL); 
		link1 = NewtonCreateBody (nWorld, collision);
		NewtonBodySetLinearDamping (link1, 0.2f);
		vector3df angularDamp (0.2f, 0.2f, 0.2f);
		NewtonBodySetAngularDamping (link1, &angularDamp.X);
		vector3df newPos = lastPos;
		matrix4 mat;
		newPos+=segmentOffset;
		ISceneNode* node = smgr->addCubeSceneNode(1);
		node->setPosition(newPos);
		mat.setTranslation(newPos);
		NewtonBodySetUserData(link1, node);
		NewtonBodySetMatrix(link1, &mat.M[0]);
		NewtonBodySetMassMatrix (link1, 1, 1.0f, 1.0f, 1.0f);
		NewtonBodySetTransformCallback(link1, FishungLineSetMeshTransformEvent);
		NewtonBodySetForceAndTorqueCallback(link1, FishungLineApplyForceAndTorqueEvent);	
		NewtonReleaseCollision (nWorld, collision);		
		SFishungLineSegment segment;
		segment.Joint=NewtonConstraintCreateBall (nWorld, &lastPos.X,link0, link1);
		segment.Body = link1;
		segment.Node = node;
		Segments.push_back(segment);
		lastPos = newPos;
		link0 = link1;
	}
To and of rope I am connect Big object - size=(10,10,10)

I am test it. It looks a real. But when bigobject touch small objects, my project is crashed. :-(
Image

I am debugged project and has noticed: project crash on

Code: Select all

NewtonUpdate(nWorld, 0.01);
Why such can occur?

My project:
http://www.webpolit.com/irr/NewtonRope.rar

Please help me.
Magnet
Posts: 101
Joined: Wed Sep 27, 2006 7:32 pm

Post by Magnet »

I am noticed that error occurs when any objects touch.
My callback is incorrect?

Code: Select all

void FishungLineApplyForceAndTorqueEvent (const NewtonBody* body) 
{ 
	try
	{
		float mass; 
		float Ixx; 
		float Iyy; 
		float Izz; 
		float force[3]; 
		float torque[3]; 

		NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz); 

		force[0] = 0.0f; 
		force[1] = NEWTON_GRAVITY * mass; 
		force[2] = 0.0f; 

		torque[0] = 0.0f; 
		torque[1] = 0.0f; 
		torque[2] = 0.0f; 

		NewtonBodyAddForce (body, force); 
		NewtonBodyAddTorque (body, torque); 
	}
	catch (char *c)
	{
		
	}
}
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

Post by belfegor »

You could try getting answer in newton forum(if you havent) if no one here
can help you.I was also planning to use newton but i am stuck with other things right now.Sorry for not be of any help to you.
Small FPS demo made using Irrlicht&NewtonDEMO
InfoHERE
Its at very early stage but i think im crazy enough to finish it all alone.
Magnet
Posts: 101
Joined: Wed Sep 27, 2006 7:32 pm

Post by Magnet »

I am noticed: if this error is appears when I remove joints:

Code: Select all

void CFishungLine::RemoveLineSegments( int Count )
{
	UnconnectEndSegment();
	for(int i=0;i<Count;i++)
	{
		SFishungLineSegment *seg = &Segments[Segments.size()-1];
		NewtonDestroyBody(nWorld, seg->Body);
                //if I am comment it, programm works is succesful
		//NewtonDestroyJoint(nWorld,seg->Joint);
		seg->Node->remove();
		Segments.pop_back();
	}
	ConnectEndSegment();
}
Why appears error when I am using NewtonDestroyJoint
Magnet
Posts: 101
Joined: Wed Sep 27, 2006 7:32 pm

Post by Magnet »

If I comment

Code: Select all

NewtonDestroyJoint(nWorld,seg->Joint); 
Newton will work correctly?
Post Reply