SpiderPig Posted May 2 Share Posted May 2 I don't know if such a joint exists, but what I need is something that will allow me to spin a planet around with a kinematic joint and have all physics objects on the surface of that planet not move. In the video here gravity goes to the centre of the sphere. You can see once the small spheres come to a rest I start to spin the large sphere with the kinematic joint and the spheres on the surface begin to rotate. I understand that this is probably the correct behavior due to inertia and what not but I want to turn it off! I need a joint that I can use to parent lots of objects to one main physics object, that regardless of how I move that larger object the child physics objects will be constrained to it - but still react to physics! Pretty much being able to use Entity::SetParent() but not breaking physics, and having physics being able to run in local space to the parent. Is this something newton can do? I might post in the forums on Newton as well. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted May 2 Author Share Posted May 2 This might do what I need. http://www.newtondynamics.com/wiki/index.php/NewtonConstraintCreateUserJoint I think we need a joint in Ultra that allows us to parent a physics object to anther physics object and still have everything work. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted May 3 Author Share Posted May 3 Looks like I got what I want working with this. auto pivot = CreatePivot(world); pivot->SetPosition(child->GetPosition(true), true); pivot->SetMass(1.0f); auto plane_joint = CreatePlaneJoint(p2, p2 - p1, pivot, child); auto slider_joint = CreateSliderJoint(p1, p2 - p1, planet, pivot); This means the child object still reacts to all physics, movement on all three axis and I'm pretty sure it's doing rotation on all 3 axis too... and when it collides with the planet sphere (which gravity is acting towards) it will stop moving and then move perfectly with the planet as it rotates. I don't really like using multiple joints, so if a joint can be made to do this. That'd be awesome. Quote Link to comment Share on other sites More sharing options...
Josh Posted May 9 Share Posted May 9 It's called a "fixed joint" sometimes, and although Newton does not support this, it might be possible to implement a custom one. (Copying this code here for future reference) //http://newtondynamics.com/forum/viewtopic.php?f=15&t=4056 void NewtonDynamicsJoint::NewtonUserBilateralCallBack(const NewtonJoint* newtonjoint, dFloat timestep, int threadIndex) { dFloat matrix0[16]; dFloat matrix1[16]; Mat4 mat0,mat1; Vec3 desiredposition; float dpf[3]; Vec3 p0,p1; float pf0[3],pf1[3]; float dist=5000; float stiffness=1; const NewtonBody* childbody = NewtonJointGetBody0(newtonjoint); const NewtonBody* parentbody = NewtonJointGetBody1(newtonjoint); Mat4 identity; dFloat axis[3]; float trans[3]; NewtonDynamicsJoint* newtondynamicsjoint = (NewtonDynamicsJoint*)NewtonJointGetUserData(newtonjoint); NewtonBodyGetMatrix(parentbody, matrix0); NewtonBodyGetMatrix(childbody, matrix1); mat0=Mat4(matrix0); mat1=Mat4(matrix1); float row[4]; Vec3 mat0trans = mat0.GetTranslation(); Vec3 mat1trans = mat1.GetTranslation(); desiredposition = Transform::Point(newtondynamicsjoint->fixedjointchildrelativeposition,mat0,identity); dpf[0]=desiredposition.x; dpf[1]=desiredposition.y; dpf[2]=desiredposition.z; //Set the position - transform desired position from parent to world and add linear rows NewtonUserJointSetRowStiffness(newtonjoint,stiffness); axis[0]=1; axis[1]=0; axis[2]=0; NewtonUserJointAddLinearRow( newtonjoint, &matrix1[12], dpf, axis); NewtonUserJointSetRowStiffness(newtonjoint,stiffness); axis[0]=0; axis[1]=1; axis[2]=0; NewtonUserJointAddLinearRow( newtonjoint, &matrix1[12], dpf, axis); NewtonUserJointSetRowStiffness(newtonjoint,stiffness); axis[0]=0; axis[1]=0; axis[2]=1; NewtonUserJointAddLinearRow( newtonjoint, &matrix1[12], dpf, axis); //Set rotation p0 = mat0trans + Transform::Vector(newtondynamicsjoint->fixedjointparentrelativeaxes[2],mat0,identity) * dist; p1 = mat1trans + Transform::Vector(newtondynamicsjoint->fixedjointchildrelativeaxes[2],mat1,identity) * dist; pf0[0]=p0.x; pf0[1]=p0.y; pf0[2]=p0.z; pf1[0]=p1.x; pf1[1]=p1.y; pf1[2]=p1.z; NewtonUserJointSetRowStiffness(newtonjoint,stiffness); trans[0]=mat0.j.x; trans[1]=mat0.j.y; trans[2]=mat0.j.z; NewtonUserJointAddLinearRow(newtonjoint, pf1, pf0, trans ); NewtonUserJointSetRowStiffness(newtonjoint,stiffness); trans[0]=mat0.i.x; trans[1]=mat0.i.y; trans[2]=mat0.i.z; NewtonUserJointAddLinearRow(newtonjoint, pf1, pf0, trans ); p0 = mat0trans + Transform::Vector(newtondynamicsjoint->fixedjointparentrelativeaxes[1],mat0,identity) * dist; p1 = mat1trans + Transform::Vector(newtondynamicsjoint->fixedjointchildrelativeaxes[1],mat1,identity) * dist; pf0[0]=p0.x; pf0[1]=p0.y; pf0[2]=p0.z; pf1[0]=p1.x; pf1[1]=p1.y; pf1[2]=p1.z; NewtonUserJointSetRowStiffness(newtonjoint,stiffness); trans[0]=mat0.k.x; trans[1]=mat0.k.y; trans[2]=mat0.k.z; NewtonUserJointAddLinearRow (newtonjoint, pf1, pf0, trans ); } pHySiQuE Posts: 608 Joined: Fri Sep 02, 2011 9:54 pm fixedjointchildrelativeposition=Transform::Point(entity[0]->GetPosition(true),NULL,entity[1]); fixedjointchildrelativeaxes[0]=Transform::Vector(1,0,0,NULL,entity[0]); fixedjointchildrelativeaxes[1]=Transform::Vector(0,1,0,NULL,entity[0]); fixedjointchildrelativeaxes[2]=Transform::Vector(0,0,1,NULL,entity[0]); fixedjointparentrelativeaxes[0]=Transform::Vector(1,0,0,NULL,entity[1]); fixedjointparentrelativeaxes[1]=Transform::Vector(0,1,0,NULL,entity[1]); fixedjointparentrelativeaxes[2]=Transform::Vector(0,0,1,NULL,entity[1]); newtonjoint = NewtonConstraintCreateUserJoint(((NewtonDynamicsSimulation*)world->simulation)->newtonworld,6,NewtonUserBilateralCallBack,NULL,((NewtonDynamicsBody*)entity[0]->body)->body, ((NewtonDynamicsBody*)entity[1]->body)->body); NewtonJointSetUserData(newtonjoint, this); 1 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...
SpiderPig Posted May 9 Author Share Posted May 9 Awesome! I might actually be able to test that code out. Quote Link to comment Share on other sites More sharing options...
Josh Posted May 9 Share Posted May 9 I don't think you can because it is part of a custom joint in Newton. 1 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...
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.