Box2D Forums

It is currently Thu May 23, 2013 4:26 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Sat Mar 15, 2008 9:06 pm 
Offline

Joined: Mon Nov 12, 2007 8:54 am
Posts: 2
Hi I am currently doing a port of Box2D to XNA. I have lots of c# experience but little to none c++ knowledge so I've run into a c++ to c# translation issue... What does the following line of c++ mean, or better yet how does it translate to c#?

// Size the island for the worst case.
b2Island island(m_bodyCount, m_contactCount, m_jointCount, &m_stackAllocator, m_contactListener);

Kind regards,
Johannes


Top
 Profile  
 
PostPosted: Sat Mar 15, 2008 11:47 pm 
Offline

Joined: Tue Sep 25, 2007 1:45 am
Posts: 131
I don't actually know any c#, but I'll give it a shot.

b2Island is the class name, island is the instance name, and the stuff in the brackets is the parameters passed in to the constructor. I believe the main difference is the lack of the 'new' keyword.

The other thing is the '&' symbol which indicates that a pointer will be passed to constructor rather than the object itself.
I had a quick look and I think in c# you would use the 'ref' keyword to the same effect?

So if that's right then it should translate to this:

Code:
// Size the island for the worst case.
b2Island island = new b2Island(m_bodyCount, m_contactCount, m_jointCount, ref m_stackAllocator, m_contactListener);

It probably wouldn't hurt to look in to learning a bit of c++, maybe read up on the differences between the languages, particularly in regard to pointers and references and such.

Hope that helps in some way..
-Matt


Last edited by skatehead on Sat Mar 15, 2008 11:57 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Sat Mar 15, 2008 11:52 pm 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
There is a C# port underway already:

http://www.box2d.org/forum/viewtopic.php?f=5&t=481


Top
 Profile  
 
PostPosted: Sun Mar 16, 2008 12:05 am 
Offline

Joined: Mon Nov 12, 2007 8:54 am
Posts: 2
@skatehead:
Thanks for your reply... Should have looked at the island constructor myself, I guess I better go to bed. ;)

@Erin:
Yeah, thanks... But I think I will make my own port anyways. I mean, it's good practice in C++ as well as understanding the inner workings of your brilliant 2d physics framework. It is also good practice in making performant C# and XNA code. So it's basically a 4-way learning experience, and I'm the type who like learning new stuff. :)


Top
 Profile  
 
PostPosted: Sun Mar 16, 2008 12:29 am 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
Cool, porting Box2D is a great way to learn what makes it tick. If the task starts to feel too big, you can still learn a lot by porting Box2D_Lite: http://www.gphysics.com/downloads


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group