Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 557 558 [559] 560 561 ... 796

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

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8370 on: October 30, 2015, 02:22:47 pm »

Let me try explaining it this way.

Lets say you have three names and one score to each.

The first two names show up once. Which is good that's what I want. But the third (or really last line) is repeated. It's strange because it's only that one line is repeated.


Fixed.

EDIT: I tested it and it does in fact print only the last line twice. Which makes me even more annoyed at you because I asked specifically for clarification about that specific issue, and you only made it more confusing. I have to ask, are you doing this on purpose?

Relace the while statement with:

while (!infile.eof())

Case closed. No more chatting.

No I don't do this on purpose I just have a habit of asking questions and typing fast without looking. Like how I just did above. Thank you for your help and sorry for being vague.
« Last Edit: October 30, 2015, 02:24:21 pm by 3man75 »
Logged

Malus

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8371 on: October 30, 2015, 04:24:35 pm »

Alright, so lemme try to work this out. I do some raytracing with the object's velocity vector, find the first thing it intersects and the normal of the collision (which would just be a horizontal or vertical line with AABBs, regardless of the ray angle, I think?), then zero the vector along that normal I calculated. So in the case of moving down and to the right, my vector would end up pointing straight to the right instead. Then I repeat until there are no intersections with the ray.
Yup, that's the idea.
Quote
Also, I assume that zeroing the vector along an axis involves vector multiplication (dot product or cross product), but I'm not sure of the exact operations I should be doing here. It would be extremely useful if I could get this working with slopes.
You can multiply it by the "swap" of the normal. This is usually what we mean when we talk about transposing a vector. You can go into the math, but in programming terms, it boils down to this: if the normal vector is {x, y}, then you want to multiply the velocity vector by {y, x}.

You can see how this achieves the effect.
Quote
EDIT: also I just realized I don't even know where to trace the ray from. Should it be from the AABB's corner which is pointing in the direction of the velocity vector? This might be more difficult than I thought.
There's a really useful thing called the "Minkowski sum". In the context of collision detection, instead of checking whether both AABBs collide by iterating over the corners, you collapse one of them down to a point, then add the width and height to the other one, and check whether the point is within the new, expanded rectangle. I'd do the velocity vector ray trace from the point.

Here's a relevant stackoverflow: http://stackoverflow.com/questions/16198437/minkowski-sum-for-rectangle-intersection-calculation

It's kind of annoying to find the normal of a slope under an AABB system, but you can still do it... it just means storing more data than you are presently (or extrapolating the slope from the pixels). With an AABB system you just don't know enough to properly find the normal of a collision surface. You could do something real janky like flag the stairs/ramp as a diagonal, assume a 45 degree slope, find the normal of that... but it's not really clean. Basically your code would look like:
Code: [Select]
if(GetCollision(entityA, entityB)
{
    if(entityA.isSlope || entityB.isSlope)
        ResolveJankyCollision(entityA, entityB);
    else
        ResolveAACollision(entityA, entityB)
}
If you're just working on a 2D platformer that doesn't need ultra robust physics (i.e., convex polygon collision detection), this is probably what you want to do. But I'd focus on getting regular AABB working first before implementing special cases like this.

Someone who's better at math than me, feel free to chime in. I am only distantly familiar with what I'm talking about.
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8372 on: October 31, 2015, 02:46:45 pm »

Also, I assume that zeroing the vector along an axis involves vector multiplication (dot product or cross product), but I'm not sure of the exact operations I should be doing here. It would be extremely useful if I could get this working with slopes.
You can multiply it by the "swap" of the normal. This is usually what we mean when we talk about transposing a vector. You can go into the math, but in programming terms, it boils down to this: if the normal vector is {x, y}, then you want to multiply the velocity vector by {y, x}.
That really really doesn't make any sense. What you actually need to do: If your velocity vector is v and your unit normal vector is n, then zeroing v along n is done by taking v-n*(v.n).
Logged

Malus

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8373 on: October 31, 2015, 06:18:04 pm »

That really really doesn't make any sense. What you actually need to do: If your velocity vector is v and your unit normal vector is n, then zeroing v along n is done by taking v-n*(v.n).
Oops, you're right. I skipped a few steps. My reasoning was something like this:
v's motion on the normal's axis has to be zero.
So construct a basis with the normal, where it's orthonormal with regards to another vector (e.g., {0, 1}).
Now project the velocity vector onto this basis and multiply (hadamard) it with the perpendicular vector (continuing from above, it'd be {1, 0}), thus zeroing it along the original normal.

If you're only dealing with AABBs (so your normals are already orthonormal) then those steps are done for you, so you can just grab the perpendicular vector and hadamard the velocity vector with it. Basically your normals are guaranteed to be either {0, 1} or {1, 0} and you want to multiply the velocity vector by the one that it isn't, hence the weird terminology with the "swap".
Edit: though that's not at all accurate either as it doesn't hold true for higher dimensions. You *really* want to multiply by the boolean negation of the normal vector. So if you have a 3D normal that's {1, 0, 0} you want to multiply the velocity vector by {0, 1, 1}. Or just throw it all into your formula and get the solution with half the hassle :P
« Last Edit: October 31, 2015, 10:49:07 pm by Malus »
Logged

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #8374 on: November 01, 2015, 12:38:00 pm »

Well, I got predictive collision detection to work at least, using this article as a guide. I never really understood how swept collision worked until now, and it does indeed prevent that "quantum tunneling" effect you get with fast-moving objects. Most importantly, though, I can get the collision normal from this.

Now for the hard part: I need to adapt this to a simulation where many objects are floating around. I already have a quadtree implementation, but I need to figure out a way to determine which objects aren't colliding anymore during this frame and cull them. That's easier said than done when collisions can result in a changed velocity vector, leading to more collisions. I guess I'll just have to re-run the check every time an object changes its course.

EDIT: WAIT A SECOND the code in that link contains this:
Code: [Select]
    var denominator:Float = r * s;
    ...
    if (denominator == 0)
    {
        // lines are parallel
        return Math.POSITIVE_INFINITY;
    }

The dot product is zero if the lines are perpendicular, not parallel. I replaced s with the reciprocal of s, and the function works fine now.

EDIT2: okay, it still has problems. There's something screwy about the code in that link.
« Last Edit: November 01, 2015, 01:28:30 pm by Gatleos »
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

Urist McManiac

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8375 on: November 02, 2015, 06:51:20 am »

Fellow Bay12ers, I have a question:

I recently got interested in programming/coding again, thanks to a friend. The thing is, I don't know where to start. I did have some programming classes in high school, so I know most of the "basics" and I'm quite sure I'd have an easy time learning a proper programming language. However, everything else is completely new form me. Ideally, I'd like to learn C/C++.

So I'd like to ask the coders of Bay12 if they have any ideas/suggestion on where to start (and with what). Are there any good websites/tutorials or books (preferably availabe for free) you could recommend?



Logged

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8376 on: November 02, 2015, 08:02:52 am »

Spoiler (click to show/hide)

When the information is exported onto testscore2 it does samantha coy twice.
To clarify what the actual issue was here, infile is still good after the last line and doesn't fail until it tries to read again. The alternative solution to Reelya's is to do your reading before the check:
Code: [Select]
...
infile >> firstName >> lastName >> testScore;
while (infile)
{
outfile << left << setw(12) << firstName << setw(12) << lastName
<< right << setw(4) << testScore << endl;
infile >> firstName >> lastName >> testScore;
}
...
« Last Edit: November 02, 2015, 08:04:35 am by Bumber »
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #8377 on: November 02, 2015, 11:20:49 pm »

Fellow Bay12ers, I have a question:

I recently got interested in programming/coding again, thanks to a friend. The thing is, I don't know where to start. I did have some programming classes in high school, so I know most of the "basics" and I'm quite sure I'd have an easy time learning a proper programming language. However, everything else is completely new form me. Ideally, I'd like to learn C/C++.

So I'd like to ask the coders of Bay12 if they have any ideas/suggestion on where to start (and with what). Are there any good websites/tutorials or books (preferably availabe for free) you could recommend?
C (and C derivatives) are arse for learning unless you already have some experience, are very persistent, or have a good teacher.
Python is a great language to learn, it's easy and simple and all that. The only time you'd want to not use it is for CPU-intensive number crunching. A few people don't like it because they're gay it does some weird things with C-like language conventions.
C# (or Java, but C# is better) is pretty good if you want to jump into something a little more... not Python.
All three have extensive documentation and dozens of tutorials floating around. I'm sue you can find one that works for you.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8378 on: November 02, 2015, 11:24:31 pm »

python is the most popular language for CPU-intensive number crunching (I.E physics calculations) among non-programmers (I.E scientists) these days AFAIK

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8379 on: November 02, 2015, 11:29:08 pm »

Yeah, the neat thing with Python is that a ton of the number crunching things you might want to do already have modules that are basically wrappers for implementations in much more efficient languages, so you get a lot of Python's ease of use with most of the efficiency of C or whatever. The only hangup would be if you want to implement your own very weird number-crunching, in which case you'll need to write that very efficient implementation anyway. Python's popularity does good work.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8380 on: November 02, 2015, 11:35:01 pm »

A lot of number-crunching is actually done in Fortran, too, in addition to C and Python.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8381 on: November 02, 2015, 11:45:24 pm »

COBOL is what you want for number-crunching.

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #8382 on: November 03, 2015, 12:52:05 am »

COBOL is cheating
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8383 on: November 03, 2015, 03:45:44 am »

i've had a very pervasive error that i couldn't figure out

well i figured out why i couldn't figure it out



so uh

WHY WHY WHY WHY WHY WHY WHY WHY WHY WHY WHY WHY WHY

EDIT: HOLY FUCKING SHIT NaN IS A NUMBER

so yeah you need to use a function (isNaN) to determine whether a number is not a number
« Last Edit: November 03, 2015, 03:55:54 am by Putnam »
Logged

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8384 on: November 03, 2015, 05:30:08 am »

i've had a very pervasive error that i couldn't figure out

well i figured out why i couldn't figure it out



so uh

WHY WHY WHY WHY WHY WHY WHY WHY WHY WHY WHY WHY WHY

EDIT: HOLY FUCKING SHIT NaN IS A NUMBER

so yeah you need to use a function (isNaN) to determine whether a number is not a number
Sort of, yeah. There's more than one NaN:
Code: [Select]
0x7FF0000000000000 = 1 x 2^1024 = +∞
0x7FF8000000000000 = 1.5 x 2^1024 = NaN
0x7FFC000000000000 = 1.75 x 2^1024 = NaN
They're any floating point number greater than 2^1024.

No idea why NaN==NaN is false. It must not bother to change the non-exponent bits or automatically fail. I wonder what happens if you use less than or greater than. A consistent 'false' would validate the automatic fail theory.
« Last Edit: November 03, 2015, 05:38:46 am by Bumber »
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?
Pages: 1 ... 557 558 [559] 560 561 ... 796