About Monkey 2 › Forums › Monkey 2 Programming Help › mojo3d: Entity in view?
This topic contains 26 replies, has 4 voices, and was last updated by
DruggedBunny
12 months ago.
-
AuthorPosts
-
April 21, 2018 at 10:53 pm #14448
Trying to implement it myself — I have added the class in the bullet module. I decided to make a new “constraint” class for mojo3d but when I call on the bullet command btPoint2PointConstraint, I get:
bullet3-2.85.1/src/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h:77:2: note: no known conversion for argument 1 from ‘btRigidBody*’ to ‘btRigidBody&’
It passes the btRigidBody(s) and btVector3(s) but appears Var is still not implemented so I am unsure how to pass references instead of pointers.
Any ideas?
April 21, 2018 at 11:35 pm #14450Can you post the stuff you’ve added to bullet.monkey2 (or all of it)?
April 21, 2018 at 11:50 pm #14452It’s not anything so far —
Bullet:
Monkey123456789101112Class btTypedObject Extends btObjectEndClass btTypedConstraint Extends btTypedObjectEndClass btPoint2PointConstraint Extends btTypedConstraintMethod New( rbA:btRigidBody, rbB:btRigidBody, pivotInA:btVector3, pivotInB:btVector3 )Method New( rbA:btRigidBody, pivotInA:btVector3 )Endmojo3d/scene/components/constraint:
Monkey1234567891011121314151617181920Namespace mojo3dPrivateClass Constraint Extends ComponentEndClass Point2PointConstraint Extends ConstraintMethod New( rigid1:btRigidBody, rigid2:btRigidBody, pos1:Vec3f, pos2:Vec3f)Local btVec1:=New btVector3(pos1.x, pos1.y, pos1.z)Local btVec2:=New btVector3(pos2.x, pos2.y, pos2.z)_btConstraint = New btPoint2PointConstraint(rigid1, rigid2, btVec1, btVec2)EndField _btConstraint:btPoint2PointConstraintEndApril 22, 2018 at 12:25 am #14453Hmm, that’s weird, bullet is using references instead of pointers here.
The easiest way to deal with this right now is probably to just add pointer versions of the ctors, eg:
btPoint2PointConstraint(btRigidBody* rbA,btRigidBody* rbB, const btVector3& pivotInA,const btVector3& pivotInB):
btPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB){}btPoint2PointConstraint(btRigidBody* rbA,const btVector3& pivotInA):
btPoint2PointConstraint(*rbA,pivotInA){}Add this directly to the btPoint2PointConstraint.h file below the existing ctors – I haven’t tested it but it compiles at least. The nicer way is probably to subclass btPoint2PointConstraint and add the new ctors there, but this should get you going for now.
No idea why he’s done it this way, the joys of c++!
April 22, 2018 at 12:29 am #14454Actually, I’m up for having a go at getting a point2point constraint style component (or whatever) going right now, got nothing else on.
April 22, 2018 at 12:48 am #14455Aww Yiss!
April 22, 2018 at 12:58 am #14456I know little to nothing about constraints though! Should I just start with the simple 1 body, 1 pivot point2point type? How does/should this work? What would be a good little demo for this?
April 22, 2018 at 2:39 am #14457Maybe DruggedBunny can add some input but this is what I have been looking at:
btPoint2PointConstraint Class Reference
Snippet of Panda3D’s Implementation
Bullet – Chain Tutorial (Using Point2Point/Ball Socket Constraints)
You could start with either but I feel like the 2 body-2pivot point2point will help you see if it’s actually working or not – not really sure when someone would use 1 body-1 pivot.
I was thinking of the actual user-facing code looking something like:
Monkey123456789101112131415161718192021222324Function Setup()Local Cone1:=Model.CreateCone( 2.5, 5, Axis.Y, 32, New PbrMaterial( Color.Red ), Null )Cone1.Move( 0, 20, 0 )Local Cone1Rigid:=New RigidBody( Cone1 )Local Cone1Tip:= New Vec3f '(Position of tip of cone)Local Cone2:=Model.CreateCone( 2.5, 5, Axis.Y, 32, New PbrMaterial( Color.Green ), Null )Cone2.Move( 0, 20, 0 )Cone2.Rotate( 0, 0, 180 )Local Cone2Rigid:=New RigidBody( Cone2 )Local Cone2Tip:= New Vec3f '(Position of tip of cone)'Local Link:Constraint = New Point2PointConstraint(Cone1Rigid, Cone2Rigid, Cone1Tip, Cone2Tip) ...OrLocal Link:Constraint = New BallSocketConstraint(Cone1Rigid, Cone2Rigid, Cone1Tip, Cone2Tip)#remPossible Commands:Constraint.SetPivot(someVec3, Null) 'set PivotA and keep/ignore PivotBConstraint.GetPivot(pivA, pivB) 'return pivots/vectorsConstraint.SetLimits() 'not 100% on how limits would work#endEndGoing to be honest I have never really dealt with constraints and if you need me to find some more examples/references I absolutely will. Having said all that, Point2Point looks like it really dives right into it and I think once you get this, other constraints like Hinge etc. should be a bit easier – if you’re up for the challenge!
Edit: Couple more links:
Bullet Manual – Page 23 (Constraints)
Bullet – Bridge Tutorial (Uses Point2Point Constraints)
April 22, 2018 at 5:07 am #14458Attempt #1 is now up at develop!
There’s a simple test in the tests dir called ‘constraints.monkey2’. It’s just a basic chain of cubes, but it seems to work OK.
One weird thing is the chain should be ‘anchored’ by the cube at the top, and it sort of is, however the bottom cubes shouldn’t touch the ground but they do a little, not sure what’s up there yet…
April 22, 2018 at 5:18 pm #14467This is great! Thank you so much Mark!
April 22, 2018 at 5:55 pm #14469Cool, works here. It looks correct — guessing the constraints have a little ‘flex’ in them at first glance, rather than being set to a fixed distance? Will dig in…
EDIT: Hmm, see what you mean…
April 22, 2018 at 8:18 pm #14471Little bit of debugging output in attached image… not sure what it means yet!
Once settled, there’s (as expected) ~1.2 distance between each box, with 10 boxes, but their y-position isn’t at the original y-position, so I think the constraints must have a default ‘looseness’ to them. Tried the bullet docs, but they’re impenetrable and don’t actually detail what the constraint settings are for (ERP??).
Attachments:
-
AuthorPosts
You must be logged in to reply to this topic.
