Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 671 672 [673] 674 675 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 890485 times)

Gamerlord

  • Bay Watcher
  • Novice GM
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10080 on: October 05, 2016, 12:08:48 am »

Get Visual Studio Community, yeah.
I just tried Visual Studio Community and the same damn KB2999226 thing happened.

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10081 on: October 05, 2016, 12:43:12 am »

Get windows 10?
Logged

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #10082 on: October 05, 2016, 10:52:59 am »

Spoiler (click to show/hide)

So I'm trying to detect collisions between the two convex polygons at the top left. The magenta polygon is the Minkowski difference of the other polygons (derived by inverting polygon 2 and merging the list of edges, sorted by angle). If the polygon (translated by the relative positions of the input polygons) crosses over the origin (cyan cross), that means they are intersecting.

I got the shape completely right, but for some reason it doesn't line up correctly with the origin. I tried computing the centroid and offsetting by that, which almost works, but it's still off by a bit somehow:
Spoiler (click to show/hide)

The cross should be right over that closest vertex here, but for some reason the polygon is shifted slightly to the left. I just can't seem to find a formula that offsets it for the right amount for any pair of polygons.

Any ideas?
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10083 on: October 05, 2016, 11:10:11 am »

Spoiler (click to show/hide)

So I'm trying to detect collisions between the two convex polygons at the top left. The magenta polygon is the Minkowski difference of the other polygons (derived by inverting polygon 2 and merging the list of edges, sorted by angle). If the polygon (translated by the relative positions of the input polygons) crosses over the origin (cyan cross), that means they are intersecting.

I got the shape completely right, but for some reason it doesn't line up correctly with the origin. I tried computing the centroid and offsetting by that, which almost works, but it's still off by a bit somehow:
Spoiler (click to show/hide)

The cross should be right over that closest vertex here, but for some reason the polygon is shifted slightly to the left. I just can't seem to find a formula that offsets it for the right amount for any pair of polygons.

Any ideas?

The Minkowski difference A - B is the set of all pointwise differences {a - b : a in A, b in B}. A vertex of the difference must be the difference of two vertices. For example, if a is the topmost vertex of A, and b is the bottommost vertex of B, then a-b is the topmost vertex of A-B. However not all differences of vertices are vertices of the difference. Make sure that the vertices you're using for aligment actually correspond to each other.

Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10084 on: October 05, 2016, 11:12:21 am »

Get Visual Studio Community, yeah.
I just tried Visual Studio Community and the same damn KB2999226 thing happened.
That's not good.

Have you tried searching it?
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #10085 on: October 05, 2016, 01:30:15 pm »

The Minkowski difference A - B is the set of all pointwise differences {a - b : a in A, b in B}. A vertex of the difference must be the difference of two vertices. For example, if a is the topmost vertex of A, and b is the bottommost vertex of B, then a-b is the topmost vertex of A-B. However not all differences of vertices are vertices of the difference. Make sure that the vertices you're using for aligment actually correspond to each other.

Yeah, that's the problem. I start with convex polygons whose edges are sorted so that the edge with the smallest theta comes first, and I merge the lists. Each vertex is just offset from the previous one, so the only offset I need to compute is the first one. So right now, the first vertex I add is at the origin. That point could either be from polygon A or B, so which points should I be subtracting to get the offset for it?
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

lethosor

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10086 on: October 05, 2016, 01:50:27 pm »

I found a decent, extensive set of tutorials, but they require Visual Windows.
I'd be wary of any tutorials that require a specific IDE. If they're tutorials for using a specific IDE, that's fine, but if they're tutorials for C++ in general that "require" Visual Studio, either they really don't (but are just using VS to demonstrate), or they're using VS-specific stuff that will cause you massive trouble if you ever work with another environment.
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10087 on: October 05, 2016, 02:20:36 pm »

The Minkowski difference A - B is the set of all pointwise differences {a - b : a in A, b in B}. A vertex of the difference must be the difference of two vertices. For example, if a is the topmost vertex of A, and b is the bottommost vertex of B, then a-b is the topmost vertex of A-B. However not all differences of vertices are vertices of the difference. Make sure that the vertices you're using for aligment actually correspond to each other.

Yeah, that's the problem. I start with convex polygons whose edges are sorted so that the edge with the smallest theta comes first, and I merge the lists. Each vertex is just offset from the previous one, so the only offset I need to compute is the first one. So right now, the first vertex I add is at the origin. That point could either be from polygon A or B, so which points should I be subtracting to get the offset for it?

If you're sorting the edges by unsigned bearing (0° to 360°), then the first point of A-B is a-b, where a is the furthest vertex of A in the 270° direction, and b the is furthest vertex of B in the 90° direction. If there are multiple furthest vertices, then choose from them such that a is as far as possible along the 180° direction, and b is as far as possible along the 0° direction.

If you're sorting by signed bearing (-180° to 180°), then you should choose them the other way around.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10088 on: October 05, 2016, 07:28:51 pm »

I found a decent, extensive set of tutorials, but they require Visual Windows.
I'd be wary of any tutorials that require a specific IDE. If they're tutorials for using a specific IDE, that's fine, but if they're tutorials for C++ in general that "require" Visual Studio, either they really don't (but are just using VS to demonstrate), or they're using VS-specific stuff that will cause you massive trouble if you ever work with another environment.

Or the things they teach you will end up (if not already) being out of date or incomplete about the features of that IDE.

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #10089 on: October 05, 2016, 08:38:15 pm »

I just looped through every possible combination of a-b, none of them offsets the polygon for the correct amount. Thanks for the help anyway, I'll try to think of something else.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10090 on: October 06, 2016, 01:01:26 am »

Anyone ever have an issue where getting (using an actual getter for an object) gets you something, like an int let's say, but when you test to see if that int is 0 or below it fails to register?

Here's a code snippet btw

Spoiler (click to show/hide)
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10091 on: October 06, 2016, 01:05:21 am »

Your while loop looks suspect.

In English, your while loop means "keep looping while player 1 has some hitpoints, or player 2 has some hitpoints". i.e. the battle won't end until both are dead.

you really want the behavior "keep looping while player 1 has hitpoints, and player 2 has hitpoints", i.e. keep fighting as long as both players are able to fight.

It's a subtle difference in logic but makes all the difference. Fights don't keep going until both sides are dead, they keep going while both side are alive. This is a key skill: being able to interpret your code as English, then logically follow how different values will affect the flow of the program.
« Last Edit: October 06, 2016, 01:23:27 am by Reelya »
Logged

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10092 on: October 06, 2016, 01:20:31 am »

I honestly feel ashamed..*sigh*

Thank you Reelya. I
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10093 on: October 06, 2016, 02:10:03 am »

Don't be. The and/or thing happens to a lot of people. Mainly because it's often opposite to how people think of and/or in normal conversation.

Imagine "The petshop sells cats and dogs" vs "The petshop sells cats or dogs". Here, both "and" and "or" probably mean "and" (has-cats && has-dogs). Then consider "you can have cats and dogs" vs "you can have cats or dogs". Here, "and" is close to logical OR (you can get both or either), and "or" is close to XOR (you can get one but not the other).

Originally this did confuse me, but I learned to read out if-statements as English and just got used to what sense or/and were in.
« Last Edit: October 06, 2016, 02:34:50 am by Reelya »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10094 on: October 06, 2016, 05:37:07 am »

Here, both "and" and "or" probably mean "and" (has-cats && has-dogs)

unless, of course, "cats" and "dogs" are both represented as different bits in some 8-bit data structure, in which case you actually want cats || dogs

(e.g. if cats==00000001 and dogs==00000010, both would be cats||dogs==00000011)
Pages: 1 ... 671 672 [673] 674 675 ... 796