std::vector en c objectif de la méthode

Im travaillant en objective-C++. La question que je suis coincé, c'est que j'ai besoin de passer un std::vector pour un objectif c de la méthode. Est-ce possible? Ci-dessous mon code actuel où je suis, d'avoir à faire mes calculs sur le vecteur le vecteur de la définition de la méthode (en ajoutant une valeur de décalage pour les membres de la matrice) avant de passer à la méthode comme un C tableau. Idéalement, je voudrais définir les valeurs de décalage dans la deuxième méthode, donc de la séparation de la définition (il y en aura plusieurs)
Le décalage sera variable contrairement à l'exemple ci-dessous.

Donc, plutôt que de transmettre (b2Vec2 *)vect je veux utiliser des vecteurs

- (void)createterrain1 {
using namespace std;
vector<b2Vec2>vecVerts;
vector<int>::size_type i;
vecVerts.push_back(b2Vec2(-1022.5f / 100.0, -20.2f / 100.0));
vecVerts.push_back(b2Vec2(-966.6f / 100.0, -18.0f / 100.0));
vecVerts.push_back(b2Vec2(-893.8f / 100.0, -10.3f / 100.0));
vecVerts.push_back(b2Vec2(-888.8f / 100.0, 1.1f / 100.0));
vecVerts.push_back(b2Vec2(-804.0f / 100.0, 10.3f / 100.0));
vecVerts.push_back(b2Vec2(-799.7f / 100.0, 5.3f / 100.0));
vecVerts.push_back(b2Vec2(-795.5f / 100.0, 8.1f / 100.0));
vecVerts.push_back(b2Vec2(-755.2f/ 100.0, -9.5f / 100.0));
vecVerts.push_back(b2Vec2(-632.2f / 100.0, 5.3f / 100.0));
vecVerts.push_back(b2Vec2(-603.9f / 100.0, 17.3f / 100.0));
vecVerts.push_back(b2Vec2(-536.0f / 100.0, 18.0f / 100.0));
vecVerts.push_back(b2Vec2(-518.3f / 100.0, 28.6f / 100.0));
vecVerts.push_back(b2Vec2(-282.1f / 100.0, 13.1f / 100.0));
vecVerts.push_back(b2Vec2(-258.1f / 100.0, 27.2f / 100.0));
vecVerts.push_back(b2Vec2(-135.1f / 100.0, 18.7f / 100.0));
vecVerts.push_back(b2Vec2(9.2f / 100.0, -19.4f / 100.0));
vecVerts.push_back(b2Vec2(483.0f / 100.0, -18.7f / 100.0));
vecVerts.push_back(b2Vec2(578.4f / 100.0, 11.0f / 100.0));
vecVerts.push_back(b2Vec2(733.3f / 100.0, -7.4f / 100.0));
vecVerts.push_back(b2Vec2(827.3f / 100.0, -1.1f / 100.0));
vecVerts.push_back(b2Vec2(1006.9f / 100.0, -20.2f / 100.0));
vecVerts.push_back(b2Vec2(1023.2fdddddd / 100.0, -20.2f / 100.0));
i = vecVerts.size();
//I would like to pass this sets of calculations to the stitch method below rather
than do it here
vector<b2Vec2>::iterator pos;
//add y offset value to our b2Vec2
for(pos = vecVerts.begin();pos != vecVerts.end();++pos)
{
//get b2Vec2 value at index
b2Vec2 currVert = *pos;
//add y offset (this will come from the sprite image size latterly, set value for testing only
b2Vec2 addVert = b2Vec2(currVert.x,currVert.y + 40 /PTM_RATIO); 
//copy offset added b2Vec2 back to vector as index
pos->b2Vec2::operator=(addVert);
}
//currently using this as kludge to pass my vector to the stitch method
b2Vec2 * chain = &vecVerts[0];
[self stitchterrainvertswith:chain num:i];

C'est ma méthode actuelle de passage dans mon vecteur C de style de tableau

-(void)stitchterrainvertswith:(b2Vec2 *)verts num:(int)num {
//create bodydef
b2BodyDef groundBodyDef;
//set body as static
groundBodyDef.type = b2_staticBody;
//set body position 
groundBodyDef.position.Set(0, 0);
//create body using def
groundBody = world->CreateBody(&groundBodyDef);
//create shapes
b2EdgeShape screenEdge;
b2ChainShape terrain;
terrain.CreateChain(verts, num);
groundBody->CreateFixture(&terrain,0);
//keeps track of max x value for all the ground pieces that are added to the scene
//maxVerts.x += totalXVerts.x;
}

J'ai essayé d'utiliser un objc wrapper pour le std::vector, mais suis un peu perdu, voici mon exemple:

VecWrap.h
#import "Box2D.h"
#include <vector>
struct VecAcc;
@interface VecWrap : NSObject
{
struct VecAcc* vec;
}
@end
VecWrap.MM
#import "VecWrap.h"
struct VecAcc {
std::vector<b2Vec2>data;
};
@implementation VecWrap
-(id)init 
{
vec = 0;
if (self == [super init]) {
vec = new VecAcc;
}
return self;
}
-(void)dealloc 
{
delete vec;
[super dealloc];
}
@end

puis créé la méthode suivante:

-(void)stitchgroundvectswith:(VecAcc*)vecs num:(int)num;

Qui ne fonctionne pas est-ce même possible?

OriginalL'auteur coasty | 2012-01-03