Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 112 113 [114] 115 116 ... 795

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

Sirus

  • Bay Watcher
  • Resident trucker/goddess/ex-president.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1695 on: February 26, 2012, 12:16:02 am »

I assume that he's talking about how two moving shapes on screen will react then they touch each other. That's what I learned from Game Maker, anyway.
Logged
Quote from: Max White
And lo! Sirus did drive his mighty party truck unto Vegas, and it was good.

Star Wars: Age of Rebellion OOC Thread

Shadow of the Demon Lord - OOC Thread - IC Thread

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1696 on: February 26, 2012, 12:16:42 am »

What you do when a collision has been detected. Collision detection is a some what easy exercise, while collision response can be a little more tricky. If you want to hit something and not go through it, you need to figure out not only where you hit it, but also when, so that in case you hit something else, you know what one to react to.

It is like collision detection's older brother.

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1697 on: February 26, 2012, 12:23:42 am »

I see. I was asking because I came up with a way to calculate the area of intersection between 2 AABBs, and was wondering if it would help with collision response.
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1698 on: February 26, 2012, 12:24:33 am »

Totally! If you would like to go over it, I would be all ears, and I'm sure any other game makers out there would be interested too.

Sirus

  • Bay Watcher
  • Resident trucker/goddess/ex-president.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1699 on: February 26, 2012, 12:28:38 am »

I had a general question about C: How would one call functions from different source files? I've got a rough idea for a text-based dungeon crawler floating in my head, and it'd probably be much cleaner to keep things like monsters and loot in separate files.
Logged
Quote from: Max White
And lo! Sirus did drive his mighty party truck unto Vegas, and it was good.

Star Wars: Age of Rebellion OOC Thread

Shadow of the Demon Lord - OOC Thread - IC Thread

fergus

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1700 on: February 26, 2012, 12:30:33 am »

You #include the header files (can I assume you know how header files work?), like you would with built-in libraries, but surround the name with "" instead of <>.

e.g.
Code: [Select]
#include "loot.h"
Logged
BY THE GODS! THIS QUOTE MADE MY SIG BOX HAVE A SCROLL BAR! HAPPY DAYS INDEED!
BY THE GODS! YOU HAVE TOO MANY SIGS!

Sirus

  • Bay Watcher
  • Resident trucker/goddess/ex-president.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1701 on: February 26, 2012, 12:34:11 am »

I have no idea how header files work. Hopefully we'll cover that later in the semester :P
Logged
Quote from: Max White
And lo! Sirus did drive his mighty party truck unto Vegas, and it was good.

Star Wars: Age of Rebellion OOC Thread

Shadow of the Demon Lord - OOC Thread - IC Thread

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1702 on: February 26, 2012, 12:43:44 am »

Alright, my algorithm is as follows:
  • Get the difference between the minimum x value of the 2 AABBs and the maximum x value of the 2 AABBs
  • Subtract this difference from the combined widths of the 2 AABBs in the x direction
  • If the result is less than or equal to zero, return with a value of zero
  • Do steps 1 through 3 for the y dimension
  • Multiply the results for the x and y dimensions to get the area of intersection
Here is some code that should demonstrate what I'm talking about:
Code: [Select]
float intersectionArea(Box b1,Box b2)
{
    float xdist,ydist,xlen,ylen,xs,ys;
    xdist=(b1.x2>b2.x2)?b1.x2:b2.x2-(b1.x1<b2.x1)?b1.x1:b2.x1;
    xlen=(b1.x2-b1.x1)+(b2.x2-b2.x1);
    xs=xlen-xdist;
    if(xs<0) return 0;
    ydist=(b1.y2>b2.y2)?b1.y2:b2.y2-(b1.y1<b2.y1)?b1.y1:b2.y1;
    ylen=(b1.y2-b1.y1)+(b2.y2-b2.y1);
    ys=ylen-ydist;
    if(ys<0) return 0;
    return xs*ys;
}
(this is assuming that 'Box' is a struct or class with the x1,x2,y1,y2 representing the positions of the left,right,top and bottom sides respectively).
Logged

fergus

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1703 on: February 26, 2012, 12:50:01 am »

I have no idea how header files work. Hopefully we'll cover that later in the semester :P
It's basically just a file with the function prototypes in. Wikipedia page
Logged
BY THE GODS! THIS QUOTE MADE MY SIG BOX HAVE A SCROLL BAR! HAPPY DAYS INDEED!
BY THE GODS! YOU HAVE TOO MANY SIGS!

Sirus

  • Bay Watcher
  • Resident trucker/goddess/ex-president.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1704 on: February 26, 2012, 01:01:20 am »

I have no idea how header files work. Hopefully we'll cover that later in the semester :P
It's basically just a file with the function prototypes in. Wikipedia page
Alright. Yay for learning more functions! Time to put this project on the back-burner.
Logged
Quote from: Max White
And lo! Sirus did drive his mighty party truck unto Vegas, and it was good.

Star Wars: Age of Rebellion OOC Thread

Shadow of the Demon Lord - OOC Thread - IC Thread

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #1705 on: February 26, 2012, 07:09:52 am »

Collision detection, particularly with static sloped surfaces, is something I've been struggling with lately too. Like Max said, the internet tends to get cluttered with tutorials for colliding concave dodecahedrons with toruses in a 3D environment with arbitrary gravity and friction values. I just want to push a moving AABB out of a static right triangle, jeez!
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

malloc

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1706 on: February 26, 2012, 08:34:44 am »

The reason why many tutorials on collision detection are written in a cryptic and almost impossible to understand manner is actually quite simple.

It's because you don't have enough understand of geometry. More specifically vector calculus, and, if the author is a real dick, linear algebra or even higher level stuff.

Often the authors of these tutorials are university/college students or majors. They learn that the solution is not as important as how you derived the solution. So, they often go into great length to explain how the solution is derived.

This becomes especially annoying if the author is good at mathematics. As HE will use advanced mathematical terms and rules. Often not caring to explain them. For anyone not familiar with higher level math, a double integral mixed in with matrix math looks more like a cryptic message than anything meaningful.

These tutorials are not written in layman terms. Many won't even show an implementation. If they do it's often written in very smart c ++, so it's extremely fast and contains four blocks of assembly code mixed in with template meta programming for extremely fast execution.

Anyway, point is, want to do programming, and especially game programming. Better get familiar with mathematics.

Gatleos, if you are just using simple slopes, you could technically just compute the height at any point on the slope.

If we say point A is height 10 and B is height 0, then it descents linearly from A to B. Essentially, you just truncate your AABB from A to B, and calculate the maximum height at the lower bound of the AABB.
It's simple and with some fiddling it will work just fine.

For more advanced and general collision, use learn about ray/shape intersection. This should give you a good idea on how to do more useful shape collision sweeps.

If anyone wants, I could write some collision detection example codes. Like, ray/sphere intersection, ray/plane and ray/triangle?
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1707 on: February 26, 2012, 10:13:00 am »

If you want collision detection/resolution without needing to understand the math, that is why god invented libraries.
« Last Edit: February 26, 2012, 10:32:09 am by GlyphGryph »
Logged

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #1708 on: February 26, 2012, 10:18:03 am »

It's not the collision detection so much as collision resolution I'm having trouble with. I can't seem to reliably calculate the projection vector to pull the shapes apart when they collide, I keep getting objects teleporting all over the place. And my brain started bleeding when I looked up sweeping shapes over paths for collision.

If you could do a little tutorial, that'd be great. :)
If you want collision detection without needing to understand the math, that is why god invented libraries.
That's the thing though, I'd really prefer to learn the concept myself so that I can apply it in a situation where a big, all-purpose collision detection library might not fit.
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

malloc

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1709 on: February 26, 2012, 10:44:08 am »

If you could do a little tutorial, that'd be great.
Okay, how is the slope and box defined and how do you "move" the box?
« Last Edit: February 26, 2012, 10:55:24 am by malloc »
Logged
Pages: 1 ... 112 113 [114] 115 116 ... 795