Create stick joint in iOS at runtime question?

Miasmos Games

  • Posts: 878
They are coming, but not in 2.0 Not entirely sure when they're coming yet as I believe they haven't been scheduled to a specific release.

Cupcake Bounce

Future Freak

  • Posts: 413
I'm trying to create some joints at runtime for IOS and have been using this that Jon posted up:

- (b2RevoluteJoint*)createHingeJoint:(b2Body*)one two:(b2Body*)two pt:(b2Vec2*)pt jointID:(int)jointID collide:(BOOL)collide limit:(BOOL)limit motor:(BOOL)motor lower:(float)lower upper:(float)upper torque:(float)torque speed:(float)speed;

I've got my jointed character with a head and a body set up as:

[[Game game] createHingeJoint:_Head.body two:_Body1.body pt:_Body1.currOrigin jointID:[[Game game] nextJointID] collide:false limit:true motor:false lower:-1.5f upper:1.5f torque:0.1f speed: 0.0f];

What I'm trying to achieve is a chain type effect (it's actually a worm) and would like to be able to overlap the (multiple) body parts.   

I'm currently using the currOrigin of my body actor as the pivot point but how can I hard code values into pt: to offset it from the origin?  e.g. b2Vec2(5,-5) to move the pivot points  off-centre

If I do this, I get an error:  cannot convert 'b2Vec2' to 'b2Vec2*' in argument passing

captaincomic

  • *
  • Posts: 6108
https://github.com/jesses/wck/wiki/box2d-flash-alchemy-port
Quote
Short Answer: Use V2, don’t use b2Vec2.

Long Answer: The b2Vec2 class is used to reference a C++ b2Vec2 vector. For example, when a AS3 b2BodyDef is created, it has a property called position, of type b2Vec2, which references the C++ position property of the C++ b2BodyDef which is also created. b2Vec2 takes a pointer as it’s only constructor parameter and expects that to point to a memory address of an already existing C++ b2Vec2 object.

So you probably have to use
Code: [Select]
new V2(5,-5)

Future Freak

  • Posts: 413
Been pulling my hair out (due to lack of obj c knowledge) - would appreciate some pointers. I've tried the following:


Code: [Select]
[[Game game] createHingeJoint:_Head.body two:_Body1.body pt:new V2(0,0) jointID:[[Game game] nextJointID] collide:false limit:true motor:false lower:-0.5f upper:0.5f torque:0.1f speed: 0.0f];

error: expected type-specifier before 'V2'
error: expected `:' before '(' token

Code: [Select]
[[Game game] createHingeJoint:_Head.body two:_Body1.body pt:V2(0,0) jointID:[[Game game] nextJointID] collide:false limit:true motor:false lower:-0.5f upper:0.5f torque:0.1f speed: 0.0f];

'V2' was not declared in this scope


Code: [Select]
b2Vec2 myVec;
myVec.Set(0,0);
[[Game game] createHingeJoint:_Head.body two:_Body1.body pt:myVec jointID:[[Game game] nextJointID] collide:false limit:true motor:false lower:-0.5f upper:0.5f torque:0.1f speed: 0.0f];

error: cannot convert 'b2Vec2' to 'b2Vec2*' in argument passing


Code: [Select]
b2Vec2* myVec;
myVec.Set(0,0);
[[Game game] createHingeJoint:_Head.body two:_Body1.body pt:myVec jointID:[[Game game] nextJointID] collide:false limit:true motor:false lower:-0.5f upper:0.5f torque:0.1f speed: 0.0f];

error: request for member 'Set' in 'myVec', which is of non-class type 'b2Vec2*'

Code: [Select]
myVec = new V2(0,0;
[[Game game] createHingeJoint:_Head.body two:_Body1.body pt:myVec jointID:[[Game game] nextJointID] collide:false limit:true motor:false lower:-0.5f upper:0.5f torque:0.1f speed: 0.0f];

error: 'myVec' was not declared in this scope
error: expected type-specifier before 'V2'
error: expected `;' before 'V2'

captaincomic

  • *
  • Posts: 6108
Ahhhh, sorry! I'm confusing things. Please forget what I said in my last post, this was about the Flash port of Box2D, and does not apply to iOS.

I don't have time to test this now, but try this:
Code: [Select]
b2Vec2* myVec = new b2Vec2(0,0);
[[Game game] createHingeJoint:_Head.body two:_Body1.body pt:myVec jointID:[[Game game] nextJointID] collide:false limit:true motor:false lower:-0.5f upper:0.5f torque:0.1f speed: 0.0f];

Future Freak

  • Posts: 413
Thank you loads for your help - b2Vec2* myVec = new b2Vec2(0,0);  works perfectly.