• entries
743
1924
• views
584744

# Polygons

133 views

Real life - happy. Job really good, people really cool, etc etc.

Dev - not happy.

Basically, I took Olii's tutorial code for collision detection and response and modified it till it worked, then started basing my game round it.

Issues of plagarism aside (and I did credit Olii in my readme), I'm totally uncomfortable with working with stuff I don't properly understand.

So back to the drawing board.

I understand the basic idea behind SAT. I've decided to start with circle-circle collisions.

The following was written entirely out of my head without referring to anything at all and is based upon my understanding of vectors and SAT for circles:

class Vector{public:	Vector(float x=0,float y=0) : X(x),Y(y) { }	const Vector &operator+=(const Vector &V){ X+=V.X; Y+=V.Y; return *this; }	const Vector &operator-=(const Vector &V){ X-=V.X; Y-=V.Y; return *this; }	const Vector &operator*=(float Scalar){ X*=Scalar; Y*=Scalar; return *this; }	Vector operator-(const Vector &V) const { return Vector(X-V.X,Y-V.Y); }	Vector operator*(float Scalar) const { return Vector(X*Scalar,Y*Scalar); }	Vector operator/(float Scalar) const { return Vector(X/Scalar,Y/Scalar); }	float Length() const { return sqrt((X*X)+(Y*Y)); }		float X,Y;};static Vector V1(250,250);static Vector V2(300,300);static float R1=100,R2=20;void Application::Collide(){	Vector V=V2-V1;		if(V.Length()		{		Vector N=V/V.Length(); // normalised vector		float MD=(R1+R2)-V.Length(); // minimum seperation distance		Vector M=N*MD; // normalised vector times MSD		V2+=M*0.5f;		V1-=M*0.5f;		}}

Plugged into an app that draws the circles and updates circle 2 in response to mouse clicks, you can push circle one around with circle two.

I appreciate that this is not earth shattering physics simulation, but I am pretty happy that it is working and did not require any copying of other people's code.

Basically, until I can implement SAT for circle-cirlc and circle-polygon by myself, out of my own head without any reference to other code, all current development is ceased.

[EDIT]

Here's a new demo. Probably a lot less impressive than the last one, but at least this time it is all my own work. Click to place the white circle and click-drag to move it and push the other circles about.

(And here's a good reason to use GET_X_LPARAM() instead of HIWORD() - if you don't understand, then you haven't been there, dude).

As a compete aside, leaking GDI resources sure is fun. I've just spent about three hours wondering why the circles kept turning white and locking up my application.

God bless Task Manager and the capacity to add GDI Resources to the list. Tracked it down in the end.

God, I hate computers. I consider my compulsion to program more of an addiction than a hobby. (Or maybe I mean I consider my addiction to programming more of a compulsion than a hobby).

[LATER]

I'm journalling some drunk thoughts now, but I've thought this through and I am convinced that this is worth posting. I don't want to journal ramblings, but I am convinced that this is worth posting.

Doubt is what drives me.

In comparison to the accomplishments of a lot of people in this community, I consider myself to be, at best, a dull and incompetent programmer. I think that is a fair assessment.

However, if, at any point, I compare what I could do a day ago to what I can do now, I am making quantum leaps every day.

The tiny demo above, pushing circles around with other circles, is an example of something that even a month ago would have been completely beyond me in terms of the fundamental understanding of the principles involved.

Okay, my pushing circles are not Quake 3. I know this.

But I wrote that all from my own head, without any reference to any sources (except for the Windows stuff).

But it is probably because I have spent all day convincing myself that I couldn't write that on my own that I have felt sufficiently driven to sit down and actually do it.

Normally when a project reaches the point where I am convinced I COULD write 100 levels and make it all work, I lose interest.

For as long as there is a doubt in my mind that I am actually capable of doing something, I tend to keep going.

Not really sure what my point is. Struggling to type. Thank you for listening.

Sorry to hear about your physics woes. You certainly aren't alone. I was under the impression that you pumped out that smooth-runnin' physics demo from the ground up after reading Oli's articles, so I'm "glad" that I'm not the only one finding the understanding the comprehension of 'proper' physics as time-consuming work.

Best of luck! If it starts to take longer than you'd like, then don't be afraid to opt for a simplified approach. I've been finding out the hard way that if you fudge around with a system (especially physics, it seems) for too long without a reasonable amount of movement forward, it's hard to get your mind off of it and motivated towards the other 99% of the game. [grin]

Quote:
 Original post by HopeDagger I was under the impression that you pumped out that smooth-runnin' physics demo from the ground up after reading Oli's articles

I can only hope that the community admires my honesty [smile].

Quote:
 Original post by EasilyConfused I can only hope that the community admires my honesty [smile].

I never accused you of lieing; more like misinterpretation on my behalf.

Quote:
 Original post by EasilyConfused In comparison to the accomplishments of a lot of people in this community, I consider myself to be, at best, a dull and incompetent programmer. I think that is a fair assessment.

The first step is to have more confidence in yourself, and more pride in your abilities. What you've managed so far is something that a LOT of people dream about: you've already managed to complete and release a whole game. What you may think of as 'lowly math' or whatsuch are concepts that a lot of people struggle with.

Hold your head up high, friend, and stop doubting yourself. Every step you take forward gives you one more footstep in the ground to look back at and be proud of.

Quote:
 Normally when a project reaches the point where I am convinced I COULD write 100 levels and make it all work, I lose interest.

Well, that doesn't surprise me. After all, that's the hardest part. After I've written all of my engine work and understand 100% how the game and its mechanics work, who WOULD want to start cranking out content for it? There's no surprises or anything new to learn; it's just content gruntwork. [grin] Just gotta grin and bear it.

Keep developing, EC!

Quote:
 Original post by HopeDagger I never accused you of lieing; more like misinterpretation on my behalf.

I know. I'd been drinking a bit last night. Just ignore my ramblings.

Thanks for all the words of encouragment.

## Create an account

Register a new account

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.