Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 124 125 [126] 127 128 ... 796

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

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1875 on: March 02, 2012, 01:41:57 am »

Thank you all for your input
My first 2d project I used SDL,  I'm not quite ready to start my second,  But I was doing some research for when the time came to start it,  I think I'm going to stop learning SDL and switch to OpenGL for my graphics.  And depending on how far I want to take my next project I may need 2 or 3 3d assets (which is why I looked into openGL to begin with)
Gatleos, I may call upon you when the time comes.
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1876 on: March 02, 2012, 03:32:47 am »

OpenGL has a far greater learning curve than the blitting functions in SDL, and as far as I know it doesn't directly support loading images from files (I rigged up an image loading function for this, if you want it). But once you actually get everything set up (and there's a lot, trust me) you'll never go back to SDL rendering.
http://www.lonesock.net/soil.html
SOIL: the Simple OpenGL Image Library. One function call, and BAM, you've got your texture loaded in and ready for use.

Though depending on the system/compiler/IDE you are using, you may or may not need to recompile the library, but that's just a matter of tossing the pre-made project files they give with it into your stuff. For example, with Visual Studio 2010, the lib gives the most hideous errors (__alloca multiply defined? the hell? Ye gods, it's stack memory allocation related!), but simply open their VS9 project in VS10, build as library, and it works just great.

The thing to remember with OpenGL: if there is something you want to do that the base OpenGL functionality overlooks, there is a library for it. In particular, GLUT and GLEW go pretty much hand in hand with it. GLEW being required for OpenGL's full feature set, and GLUT being very useful for creating the window for you.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1877 on: March 02, 2012, 04:29:30 am »

Wouldn't it be easier to generate those via volumetric carving instead of 3D noise?
Yeeesss... But where's the fun in that? ;)  No, you're right, I'll probably get a 2d modifier first (but that one's hard to do since its actually a sphere I'm working on, so I need to curve the x/y)

You can look at it here: http://http.developer.nvidia.com/GPUGems3/gpugems3_ch01.html
Ooh, thanks for that. If only I read that earlier, now I just re-invented the wheel :( This is exactly what I was aiming for.

So you're working with voxel data? If you are, good job on the surface generator, are you using marching cubes algorithm or something?
No real voxels, but marching cubes+geometric "volumes", and the terrain paging is an octree. The yellow plastic color is a placeholder texture, but already generated as well.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

malloc

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1878 on: March 02, 2012, 07:39:44 am »

The thing to remember with OpenGL: if there is something you want to do that the base OpenGL functionality overlooks, there is a library for it. In particular, GLUT and GLEW go pretty much hand in hand with it. GLEW being required for OpenGL's full feature set, and GLUT being very useful for creating the window for you.

I recommend freeGLUT over glut any day. Yeah, it's essentially the same, but the old GLUT library is closed source and old.
Better than GLUT is perhaps SDL. It's better in the sense that's it's open sourced. But still, it's old and not really ideal for OOP (Neither is glut btw!)

If you want a more modern open source library for all your base needs, try out SFML. http://www.sfml-dev.org/
But, if you use it, I download their codebase and compile it yourself. The reason for this is that the last stable build, version 1.6, simply freezes when used on a machine with a newer AMD card.
Logged

DrPoo

  • Bay Watcher
  • In Russia Putin strikes meteor
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1879 on: March 02, 2012, 08:12:54 am »

Why didnt the rogue infinite recursive loop cross the road?
Logged
Would the owner of an ounce of dignity please contact the mall security?

malloc

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1880 on: March 02, 2012, 10:54:47 am »

Because it caused a stack overflow and the thread was terminated? 
Logged

DrPoo

  • Bay Watcher
  • In Russia Putin strikes meteor
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1881 on: March 02, 2012, 12:21:46 pm »

Because it caused a stack overflow and the thread was terminated?

I think so, i just forgot the joke :(
Logged
Would the owner of an ounce of dignity please contact the mall security?

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #1882 on: March 02, 2012, 01:45:02 pm »

Here's my current collision detection function. Keep in mind that it's meant to detect and respond to collision between a dynamic AABB and a static upper-left-facing axis-aligned right triangle, and I haven't optimized anything yet. SDL_Rect &d is the AABB's bounding box, and SDL_Rect &s is the triangle's. The "vect" type you see in there is just a simple class for dealing with 2d vectors I made.
Code: [Select]
void colltl(SDL_Rect &d,SDL_Rect &s)
{
int x2d=d.x+d.w;
int x2s=s.x+s.w;
int r=x2s-d.x;
int l=x2d-s.x;
if(l<=0||r<=0)return;//X-axis intersection?
int y2s=s.y+s.h;
int y2d=d.y+d.h;
int dn=y2s-d.y;
int u=y2d-s.y;
if(u<=0||dn<=0)return;//Y-axis intersection?
vect v(s.h,s.w);//Create axis perpendicular to triangle hypotenuse
v=vect::unit(v);//Normalize axis to unit vector
float dmax=v.dotprod(x2d,y2d);//Project bottom right corner of AABB onto axis
float smin=v.dotprod(x2s,s.y);//Project top right corner of triangle onto axis
if(dmax<=smin)return;//Hypotenuse normal intersection?
l=clamp(l,0,256);
r=clamp(r,0,256);
u=clamp(u,0,256);
dn=clamp(dn,0,256);
int sep=min(min(l,r),min(u,dn));//Determine smallest axis of intersection
if(sep==u)d.y-=u;
else if(sep==dn)d.y+=dn;
else if(sep==l)d.x-=l;
else d.x+=r;
}
I first rule out the x and y axes, to make sure the bounding boxes are intersecting in the first place. Next, I create an axis perpendicular to the hypotenuse of the triangle and project the bottom right corner of the AABB and the top right corner of the triangle onto it using dot product. Then I compare the two to see if the shapes intersect along the hypotenuse.

After I make sure the shapes intersect along all axes, I determine the smallest axis of intersection and project the AABB out along that axis. But I've hit a problem that I can't seem to get around: how can I project it out along the hypotenuse axis? After those calculations I'm left with a scalar value for the intersection along the hypotenuse axis (that is dmax minus smin, see lines 15-16), but I need to know the pixel-distance in x and y values to project it out. Is there a quick and accurate way to determine that?

Or just tell me I'm doing it completely wrong. I'd love to know. :)
« Last Edit: March 02, 2012, 01:55:23 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

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #1883 on: March 03, 2012, 03:08:36 am »

I am officially having the WEIRDEST error I have ever seen. Okay, so the code crashes with a run-time exception. When I have it "try and catch" around the area I have narrowed down to the exception, an area no exception should possibly be emerging, that part of the code runs without throwing. However OpenGL starts complaining about not being able to get a context. The OpenGL rendering code being in a completely unrelated area of the program 0_o

Okay, the OpenGL error is because the program doesn't realise, due to that "erroring but impossible to error code" throwing, stopping it from running. Code which doesn't throw a catchable error when surrounded by a try-catch block but just carries on going and skips the try/catch.

Holy shit, I have created a Schroedinger bug that only happens when not being watched 0_o
« Last Edit: March 03, 2012, 03:16:41 am by MorleyDev »
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1884 on: March 03, 2012, 03:23:40 am »

I am officially having the WEIRDEST error I have ever seen. Okay, so the code crashes with a run-time exception. When I have it "try and catch" around the area I have narrowed down to the exception, an area no exception should possibly be emerging, that part of the code runs without throwing. However OpenGL starts complaining about not being able to get a context. The OpenGL rendering code being in a completely unrelated area of the program 0_o
Methinks you are making too many assumptions. First possibly incorrect assumption: the area in question is assumed to be the only area causing runtime exceptions. Second possibly incorrect assumption: the area in question is assumed to always cause an exception. Third possible incorrect assumption: the root cause of the exceptions is located in the place in which they occur.

A lot of runtime exceptions are the result of accessing memory which is properly set up to be accessed. Something like an array whose bounds you are exceeding, a pointer to out of scope or delete'd memory, or to unallocated memory could be the cause. It could even be some uninitialized OpenGL value which needed to be set but wasn't.
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #1885 on: March 03, 2012, 03:30:17 am »

The problem was a dangling reference (the risks of refactoring code to suit a slightly modified purpose I guess, you forget to change one return type...). What I don't get is why the tracing always stopped right above the block of code I narrowed it down to despite several traces found below that block of code but before the return not being called, and why it would flat-out crash without an apparently completely unrelated try-catch block, but those are mystery for the ages I guess...

Mostly just curious to see if it works, I was trying to make a system where you could spread 2D rendering over an unknown number of threads by splitting it into a series of render to textures and spread those over the threads, and have a single render task at the end drawing however many textures were made, sorting the textures based upon the passed "height" (with higher heights being drawn first). That last render can occur concurrently with the logic for the next frame.

You could probably do something similar with 3D by splitting the rendering into various depth ranges and drawing those.

So it goes
[Logic][Render Last Frame]
[-Pre-Render Next Frame-]
[Logic][Render Last Frame]
[-Pre-Render Next Frame-]
...

The problems were occurring in the system for recycling old textures so it can run efficiently without the costly operations of destroying and recreating new textures. When it failed, the system wasn't recognising that unused textures were lying around so it was grabbing new ones, hence the eventual running out of VRAM and being unable to grab a context.

I could improve the system a lot though some of them would require a complete rewrite but hey, now I know it works...For example, it just grows a texture if it can't fit the newly desired size instead of trying to find one of appropriate size first, and every "begin/end" block tries to grab an unused texture when it could try and grab one that's already been drawn too and just add more information...

Basically, I'm fed up of every program I write using only 12% of my CPU even when number crunching, so playing around with some task based systems.
« Last Edit: March 03, 2012, 04:05:09 am by MorleyDev »
Logged

malloc

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1886 on: March 03, 2012, 09:27:38 am »

Hello Gatleos, I was meaning to answer your question much earlier as I kinda said would be posting some different intersection code snippets, but I sadly had a case of a female friend demanding my attention for the night.

Anyway. I finally think I understand what you are trying to do:
You are trying to, move the box towards the slope, and it should "slide" up the slope based on projecting the vector upon the "slope vector"?
If I understood correctly then you are going about collision response a bit wrong, especially with what you want to do.


Anyway, I will write in c++ psuedo code what you should probably do to resolve the collision. Please note, I am assuming that the vector * vector type translates to dot product.

Code: [Select]
//The will calculate a movement vector based on if it collides with a slope.
vect MoveResolveAABBSlopeSolveCollision(rect & A, rect & tri, vect & move){
      if(move.x == 0) return move;
      //Returns intersection point between the AABB A and slope tri, based on vector move.

      //Here we are essentially just setting up some variables, if you wan't to know what is going on I could explain, but it's a lengthily explanation so I think I'll just skip it for now.
      vect h_inverted(- tri.h, tri.w);
     
      float hm  = 1 / (h_inverted * move);
      float hp = h_inverted * tri.point;
      float t; //Here we are going to store the factor the movement vector needs to be to intersect.

     

      //Calculate intesection distance between the movement and slope.
      if(dir.x < 0){ //We come from right
            t = (hp - (A.p) * h_inverted) * hm;
      }
      if(dir.x > 0){ //We come form left
            t = (hp - (A.p + vect(A.w, 0)) * h_inverted) * hm;
      }
     
      if(t >= 1 && t < 0){ //The movement vector and slope do not intersect
           return move;
      }

      //Alright, now that we know they intersect. Let's project the movement vector onto the slope.
      vect h(tri.w, tri.h);
     
      vect intersection_p = ((h * move) / (h*h)) * h + tri.p;

      //We return a new movement vector projected onto the slope for a "sliding" effect.
      return intersection_p;
}

//How to use the code.
//This is basic physics, movement should be calculated after all forces have been summed. This means force should be reset before each update!
player.movementVector = vect(0,0);

//....//

//Handle input!
if(keydown(left))
    player.movementVector += vect( player.speed, 0);

if(keydown(right))
    player.movementVector += vect(- player.speed, 0);
//....//

tile & tile_we_moved_to = FindTileOnGrid(player.position + player.speed);


//....//

//I assume this is the collision resolving code
if(tile_we_moved_to == slope){
     //Alright, we collided with a slope. Let's move our object towards the slope:
     player.position += MoveResolveAABBSlopeSolveCollision(player.boundingbox, tile_we_moved_to.boundingbox, player.movementVector);
}
Please note, the code is not really "checked" as such, but rather I wrote the code from thinking about the problem and solving it. It should work as I've done something similar in the past. Also, this can be done much more effectively, but it's simplified so it's easier to follow.

If you can't get it to work, you are free to ask if you have any questions.
« Last Edit: March 03, 2012, 09:47:35 am by malloc »
Logged

Salmonpunch

  • Bay Watcher
  • Fishing poles are for the weak.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1887 on: March 03, 2012, 10:25:42 am »

Im poking my head into coding, through HTML, Gamemaker 8 pro (not as simple as the title makes it sound, its a 2d game engine not one of those precoded level creators trying to pass off as a programming software like "engine 001"), and Flash CS5.

My love for coding is all very odd because while I don't suck at math, its sure as hell not my strongest subject.
Logged
This is Gabe Newell, a vast humanoid. He undulates rhythmically. Beware his deadly release schedule!
Oh look, more apocalypse in my cereal.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #1888 on: March 03, 2012, 10:39:52 am »

I played with GameMaker. From what I can tell it is still not that well optimised and ill-suited for anything large in scale. Do-able, but much better toolkits out there. OK for prototyping, wouldn't make a full game in it.

My love for coding is all very odd because while I don't suck at math, its sure as hell not my strongest subject.

Well maths is to coding as physics is to masturbation...or something like that. Most of the maths you need for most programs is GCSE level at best, if that.  And the 'discrete maths' you come across isn't exactly regular maths, it's algorithms and the like so usually easier to wrap your head around.
« Last Edit: March 03, 2012, 10:45:32 am by MorleyDev »
Logged

malloc

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1889 on: March 03, 2012, 10:52:39 am »

@Salmonpunch
If you're just interested in coding, and not game creation pe say, I suggest not getting too comfortable in game maker. It simplifies a lot of concepts, and teaches some very bad habits. I personally had a very hard time getting rid off these habits back when I was still young and new to coding. But if you are just interested in creating some games. And more interested in the end result than in the process. Then Game Maker is an okay game engine, it's very easy to use, and you can make some cool stuff in it. But yes, it does not have a "Create my game" button.

Perhaps if you learn one of the more advanced languages first I think it will be safe to learn game maker. Like action script, which Flash makes use of.

Mathematics are not really required to code. You can develop applications just fine without it. Mathematics is however very useful, a lot of the problems you can think out can be solved by having a good knowledge of mathematics and a good sense for problem solving.


@Moley
Well maths is to coding as physics is to masturbation...or something like that.

Physics is to math, as sex is to masturbation?
Soo, then, mathematics is to programming, as masturbation is to an orgy?
Logged
Pages: 1 ... 124 125 [126] 127 128 ... 796