Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Complex object collision system (with bonus resizable array)
Index -> Programming, C++ -> C++ Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Insectoid




PostPosted: Sat Jun 23, 2012 1:44 am   Post subject: Complex object collision system (with bonus resizable array)

I haven't had internet access the last 3 weeks, and I spent a couple of those days working on this. It's a basic collision detection system for complex shapes based on breaking the object up into rectangles ('cause rectangles are easy). It's not perfect (I don't think the collision code even executes), but there are some gems in there. Due to not having internet, I couldn't access the online API, so I couldn't look up the vector class (or whatever the C++ equivalent is), so I had to write my own resizeable array that actually turned out pretty well. Oh, and the demo is console-based. Keep hitting enter to advance the animation.

I've often thought about complex shape collisions, but always quickly dismissed it as too complicated to bother with right now, but recently I had a realization that it's so stupidly simple I absolutely had to hash out a proof-of-concept, and this is it. Don't be fooled by the basic tetris shapes in the demo- this can scale up to very complicated models with hundreds of rectangles very easily (though the code doubtless needs a LOT of optimization- this is really rough).

It looks neat though, and it might be fun to peruse the code if you've never looked into complex collision. My implementation is probably really bad, since I did it completely on my own without even an API to look at.

There are 4 files included:
asciiDraw.cpp: The main test file.
Polygon.cpp: Main class for building complex shapes.
Rectangle.cpp: Basic rectangle class with a collision function in it.
RArray.cpp: Resizable array class because I didn't have the docs for the Vector available.


Compile asciiDraw.cpp like normal and run the file. Hold down Enter to advance the animation. Oh, and your terminal dimensions must be at least 31*31.



polygon.zip
 Description:

Download
 Filename:  polygon.zip
 Filesize:  5.78 KB
 Downloaded:  397 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Sat Jun 23, 2012 8:48 pm   Post subject: RE:Complex object collision system (with bonus resizable array)

Scumbag Insectoid

"I didn't want to do something simple, so I reinvented programming, which urned out pretty well"

Thats what I think when I read that Wink

Anyways it sounds cool but I can't find my C++ stuff -.-'
Insectoid




PostPosted: Sun Jun 24, 2012 5:11 pm   Post subject: Re: Complex object collision system (with bonus resizable array)

Can somebody help me figure out these header files? I originally had class definitions and implementations in the same .cpp file, but now I've split them up into header and source file pairs. The issue now is that I can't get them to properly link together. Header files were never covered in class (well, a little), so I figure now's as good a time as any to really learn 'em.

Here's the situation:
asciiDraw.cpp requires RArray.h, Polygon.h, and Rectangle.h
There's a circular inclusion between Polygon.h and Rectangle.h (I think I've solved this, but it's not compiling so something's wrong)
RArray is a template class, which has special inclusion rules that I probably messed up.

The circular inclusion is caused by Polygon having instances of Rectangles, and Rectangles having a pointer to the parent Polygon. I think I've solved this by including Rectangle.h in Polygon.h, and forward-declaring class Polygon in Rectangle.h. I dunno if this is working or not.

I've kept the RArray implementation in a header file and included that at the bottom of the actual RArray header to try to solve the template problem. I know it's not working, but I don't know how to fix it.
If someone could point me in the right direction, I'd be grateful.



polygon.zip
 Description:

Download
 Filename:  polygon.zip
 Filesize:  10.38 KB
 Downloaded:  356 Time(s)

DemonWasp




PostPosted: Sun Jun 24, 2012 9:00 pm   Post subject: RE:Complex object collision system (with bonus resizable array)

First, you've commented out the #endif in RArray.h . That's...probably a problem.

I don't see anything more, but I also can't test out uncommenting that #endif because I'm in stupid Windows and don't have a C++ compiler handy.
Insectoid




PostPosted: Mon Jun 25, 2012 9:12 am   Post subject: Re: Complex object collision system (with bonus resizable array)

Oh yes. I'd commented out the guard because templates shouldn't be guarded (as far as I know). Guess I forgot to un-comment it when I abandoned that plan. It does not solve the issue. Also, I fixed a few more syntax errors I missed before so the only compilation error should be with the #includes.


polygon.zip
 Description:

Download
 Filename:  polygon.zip
 Filesize:  10.38 KB
 Downloaded:  374 Time(s)

Display posts from previous:   
   Index -> Programming, C++ -> C++ Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: