Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
LightReaper
May 3, 2007

Edited out, problem solved.

LightReaper fucked around with this message at 16:03 on Apr 19, 2010

Adbot
ADBOT LOVES YOU

Screeb
Dec 28, 2004

status: jiggled

LightReaper posted:

That fixed it up a treat, you are a legend! Can't believe I overlooked something so simple but that seems to be the case almost always when coding.

Glad you got it working. I'll let someone else help with your next problem. It's a bit more involved unless you can find some prewritten code that works.

Morpheus
Apr 18, 2008

My favourite little monsters

LightReaper posted:

Collision stuff

What I'm going to explain is all 2D stuff, but I think it works the same way in 3D.

What you're going to want to do is project the circle's center onto each side of the rectangle you're colliding with. This is done by...hmm I wonder if I can explain this without visual aids.

You need to imagine there's a triangle between your circle's center, a corner of your rectangle (that's part of the side you're projecting onto), and the point on the rectangle's side that's closest to your sphere, which we don't know yet.


Ah crap here's some code.
code:
	Vector2 lineDirection = lineEnd - lineStart; //return the direction of the plane of intersection 
	Vector2 diff = Center - lineStart; //difference between the circle's center and the start of the line

         //this represents the scalar to apply to 'diff' in order to get the exact distance between the corner and
         //the point of intersection
        float t = DotProduct(diff, lineDirection) / DotProduct(lineDirection, lineDirection);
	

	if (t < 0.0f){ t = 0.0f; }
	if (t > 1.0f){ t = 1.0f;}
		
	Vector2 closest = lineStart + t * lineDirection;
What 'closest' will return is the point on the rectangle's side that is closest to the circle. Then it's just a hop, skip, and a jump to check to see if the circle's close enough to collide. And 't' is also known as the scalar projection (of the sphere's center onto the box's side).

Handling collision is a whole new bucket of...beans? I don't know, it's late. Anyway. That involves stopping the sphere at exactly the point of collision, then imparting force on it to simulate 'skidding' across the box. I can't explain that too well.

Morpheus fucked around with this message at 09:05 on Apr 14, 2010

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!
I recommend you do a little research on how dot products work, and why they are used here. I know when I had to solve a similar problem (in 2D) the first time I was confused as gently caress. I had no idea why it worked, or what changes I would need to make to fix or modify anything. Once I got what a dot product did to vectors, it become a trivial piece of code.

Null Pointer
May 20, 2004

Oh no!

Pfhreak posted:

I recommend you do a little research on how dot products work, and why they are used here.

I recommend taking MIT Linear Algebra (18.06) OpenCourseWare. Linear algebra is the most important thing to understand if you are making a game. It'll help you more than just learning about the dot product.

LightReaper
May 3, 2007

Edited out, problem solved.

LightReaper fucked around with this message at 16:03 on Apr 19, 2010

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again
So I finally got my image to load using FreeImage without crashing, but it's not drawing correctly when I try to apply it as a texture. It makes the spheres I'm trying to draw around it completely black. My code:

code:
fibmp_asteroid = FreeImage_Load(FIF_BMP, "C:\\tga\\asteroid.bmp"); 
imageData = (GLbyte *) FreeImage_GetBits(fibmp_asteroid);
astBmpWidth = (GLsizei)FreeImage_GetWidth(fibmp_asteroid);
astBmpHeight = (GLsizei)FreeImage_GetHeight(fibmp_asteroid);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16, astBmpWidth, astBmpHeight, 0, GL_RGB,  GL_UNSIGNED_BYTE, imageData); 
	
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		
glEnable(GL_TEXTURE_2D);
Any ideas what I did wrong?

Dransparency
Jul 19, 2006

Stavros posted:

So I finally got my image to load using FreeImage without crashing, but it's not drawing correctly when I try to apply it as a texture. It makes the spheres I'm trying to draw around it completely black. My code:

code:
fibmp_asteroid = FreeImage_Load(FIF_BMP, "C:\\tga\\asteroid.bmp"); 
imageData = (GLbyte *) FreeImage_GetBits(fibmp_asteroid);
astBmpWidth = (GLsizei)FreeImage_GetWidth(fibmp_asteroid);
astBmpHeight = (GLsizei)FreeImage_GetHeight(fibmp_asteroid);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16, astBmpWidth, astBmpHeight, 0, GL_RGB,  GL_UNSIGNED_BYTE, imageData); 
	
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		
glEnable(GL_TEXTURE_2D);
Any ideas what I did wrong?

Are you specifying the texture coordinates at each vertex?

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
There are a lot of things that could be going wrong there. Did you bind a texture before uploading it?

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again
Yeah I'm pretty sure it's the lack of texture coordinates. From what I read, it looks like you call glTexCoord functions during creation of vertices. I used glutSolidSphere to make spheres that I'm trying to texture, so I think I need to implement my own spheres with vertices before I go about texturing.

LightReaper
May 3, 2007

Edited out, problem solved.

LightReaper fucked around with this message at 16:04 on Apr 19, 2010

gwar3k1
Jan 10, 2005

Someday soon
I'm new to games programming / XNA and I'm a bit stuck with using animated sprites, or at least resting an animation once it hits its final frame.

Am I wrong for assuming the following code shouldn't loop the animation if the last frame in the set (as defined by LastFrame) has already been drawn? When I compile, the animation is continuously looping, when it should stop after the third frame.

code:
        public void UpdateFrame(float elapsed, int lastframe)
        {
            timeElapsed += elapsed;
            if (timeElapsed > timePerFrame)
            {
                if (lastframe >= 1)
                {
                    if (iFrame < lastframe)
                    {
                        iFrame++;
                        iFrame = iFrame % iFrameCount;
                        timeElapsed -= timePerFrame;
                    }
                }
                else
                {
                    iFrame++;
                    iFrame = iFrame % iFrameCount;
                    timeElapsed -= timePerFrame;
                }
            }
        }
edit: Figured it out. I hadn't changed my enum state to accomodate for the fact the animation had changed. The game kept looping the frame definition because I was holding the key but. Mediocrity here I come.

gwar3k1 fucked around with this message at 12:33 on Apr 16, 2010

MasterSlowPoke
Oct 9, 2005

Our courage will pull us through
Is lastFrame = iFrameCount - 1?
oh

MasterSlowPoke fucked around with this message at 12:35 on Apr 16, 2010

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.
I'm trying to make a user input manager that would scan the keyboard/mouse, match keypresses or mouse movements to a set of allowed player commands, and then raise events corresponding to those commmands. For example if the W key is pressed then raise the PlayerMovedForward event and have the Player object consume the event by changing the player position.

Simple cases like the one described above are easy enough to implement. Things get much more complex when I try to add in features like custom control mapping, allowing multiple different inputs to trigger the same action, or having a UI element that triggers actions when clicked on. My attempts so far to just brute-force a solution end up tightly coupling the different objects in the program which makes it difficult to add new stuff.

Are there any standard 'best practice' type ways to handle user input in a general way? It seems like this should be a problem with a well-known solution since every game has to have a user input system, but so far most everything I've found on the web is just hard coding whatever WASD type controls they are using into the Update loop.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Why not write a mapping that takes raw keys and returns actions? I mean, all you have to do is have a dictionary that takes "KEY_W" and turns it into "MovedForward". It gets a little more complicated if you want to support joysticks though (the joystick would handle all movement, not just forward movement). That's easy too, though. Just register sets of keys as your "movement" keys, e.g. WASD => Move.

Lurking Haro
Oct 27, 2009

PDP-1 posted:

I'm trying to make a user input manager that would scan the keyboard/mouse, match keypresses or mouse movements to a set of allowed player commands, and then raise events corresponding to those commmands. For example if the W key is pressed then raise the PlayerMovedForward event and have the Player object consume the event by changing the player position.

Simple cases like the one described above are easy enough to implement. Things get much more complex when I try to add in features like custom control mapping, allowing multiple different inputs to trigger the same action, or having a UI element that triggers actions when clicked on. My attempts so far to just brute-force a solution end up tightly coupling the different objects in the program which makes it difficult to add new stuff.

Are there any standard 'best practice' type ways to handle user input in a general way? It seems like this should be a problem with a well-known solution since every game has to have a user input system, but so far most everything I've found on the web is just hard coding whatever WASD type controls they are using into the Update loop.

Why don't you use a map or something similar.
That way you have configurable keys and they can call the same event.

Let the UI element call the event by it self when it's clicked. I don't know why you would to want to code that into the input manager.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.

Avenging Dentist posted:

Why not write a mapping that takes raw keys and returns actions? I mean, all you have to do is have a dictionary that takes "KEY_W" and turns it into "MovedForward". It gets a little more complicated if you want to support joysticks though (the joystick would handle all movement, not just forward movement). That's easy too, though. Just register sets of keys as your "movement" keys, e.g. WASD => Move.

For simple cases you can just map Keys->Actions and Actions->Events and then chain the two maps to get Keys->Events. That part isn't a problem. The problem is trying to mix different input types, like the keyboard/joystick in your example.

The difference between joystick and keyboard inputs is that the joystick returns an analog value while the keyboard key is just pressed/not-pressed, so you have two different sets of event arguments - JoystickEventArgs and KeyboardEventArgs. Both the event source and handler have to agree on how these EventArgs classes are defined, so the Player class and the UserInputManager class are no longer independent.

It's not the end of the world to have to couple the classes together a little bit, it just struck me as inelegant and I figured I'd check around to see if there was some better solution.

Lurking Haro posted:

Let the UI element call the event by it self when it's clicked. I don't know why you would to want to code that into the input manager.

My thought was that the input manager would be the only thing checking the mouse state to detect a click and then it would pass some kind of "the user clicked you at location X,Y" to the UI element to let it figure out what to do from there.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

PDP-1 posted:

The difference between joystick and keyboard inputs is that the joystick returns an analog value while the keyboard key is just pressed/not-pressed, so you have two different sets of event arguments - JoystickEventArgs and KeyboardEventArgs.

Why would you need that? Like I said, register grouped keys together. Then when you hit WASD, it creates a coordinate pair in [-1,1] x [-1,1] just like a joystick would. The only difference is that you'll always have 1, 0, -1 as values.

The movement case is actually one of the easier ones, since in reality you don't want to do it as an event, since the state generally persists across frames (i.e. if you hold W, you keep moving forward, and when you stop holding W, you stop moving). This is markedly different from event-based keys like the (semi-auto) "fire" button, where you tap it each time you want an event to occur. That is, with movement you're concerned about the state of the button, not the change in state.

Avenging Dentist fucked around with this message at 21:43 on Apr 19, 2010

Lurking Haro
Oct 27, 2009

PDP-1 posted:

For simple cases you can just map Keys->Actions and Actions->Events and then chain the two maps to get Keys->Events. That part isn't a problem. The problem is trying to mix different input types, like the keyboard/joystick in your example.

The difference between joystick and keyboard inputs is that the joystick returns an analog value while the keyboard key is just pressed/not-pressed, so you have two different sets of event arguments - JoystickEventArgs and KeyboardEventArgs. Both the event source and handler have to agree on how these EventArgs classes are defined, so the Player class and the UserInputManager class are no longer independent.

It's not the end of the world to have to couple the classes together a little bit, it just struck me as inelegant and I figured I'd check around to see if there was some better solution.

Why not use analog movement events for the keyboard as well? The corresponding keyboard key simply has a set value.

^^^^^
What he said

Lurking Haro fucked around with this message at 21:46 on Apr 19, 2010

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.

Avenging Dentist posted:

Why would you need that? Like I said, register grouped keys together. Then when you hit WASD, it creates a coordinate pair in [-1,1] x [-1,1] just like a joystick would. The only difference is that you'll always have 1, 0, -1 as values.

Lurking Haro posted:

Why not use analog movement events for the keyboard as well? The corresponding keyboard key simply has a set value.

Ah, I get it now. This is definitely an interesting idea and I'll give it a try. Thanks for the suggestions, both of you.

The_Frag_Man
Mar 26, 2005

Can you guys recommend some game engine specific books that are any good?

ChadyG
Aug 2, 2004
egga what?

The_Frag_Man posted:

Can you guys recommend some game engine specific books that are any good?

http://www.gameenginebook.com/
This one is the best I've read in terms of general 3D game engine construction.

If you're looking for a specific topic I really like the Morgan Kaufman series in 3D technology. For some reason the following link doesn't include the AI book and a few others.
http://www.elsevier.com/wps/find/bookdescription.cws_home/BS_M038/description#description

The_Frag_Man
Mar 26, 2005

ChadyG posted:

http://www.gameenginebook.com/
This one is the best I've read in terms of general 3D game engine construction.

Thanks for the recommendation. I've actually bought this a week ago but haven't begun reading it yet.

very
Jan 25, 2005

I err on the side of handsome.
I know this was from a couple pages ago, but the Blender 2.5 alpha's interface is really nice. Every command can be found through a type-to-search interface. So if you know you need to extrude, use the search to type "extrude" to find the shortcut key or just use the function from there. I don't know how stable it is, though. I like it much better than Maya, which I find to be as cryptic as anything else.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.
Does anyone know what is going on with the XNA 4.0 release? A developer blog from March 9 said that it would be coming out 'within a month' but as of today the download page only shows a preliminary version targeted at the Windows Mobile 7 platform.

Tax Oddity
Apr 8, 2007

The love cannon has a very short range, about 2 feet, so you're inevitably out of range. I have to close the distance.

PDP-1 posted:

Does anyone know what is going on with the XNA 4.0 release? A developer blog from March 9 said that it would be coming out 'within a month' but as of today the download page only shows a preliminary version targeted at the Windows Mobile 7 platform.

I recall reading that when they said "within a month" they were referring to exactly that, a preliminary version targeting the Windows Mobile 7 platform. Apparently the full version, with support for the 360, is meant to be released about six months from now.

GuyGizmo
Feb 26, 2003

stupid babies need the most attention
I'm starting to mull over what language / development environment to use for a graphically intense 2D game. I'd love to use Python, but I'm not too clear on what kind of capabilities it has in terms of utilizing modern graphics cards. Is it possible to, for example, make a game like Braid in it? i.e. a game that makes use of multiple parallaxing layers consisting of sprites, high resolution static graphics, polygonal objects, and advanced shader features? There's tons of game engines for Python but it's hard for me to figure out if any of them are useful for making a game like that.

haveblue
Aug 15, 2005



Toilet Rascal
You can do all of that except possibly the shaders in Python, so if you're just getting into game dev should be fine.

I wouldn't be surprised if it can do shaders anyway and I just don't know about it.

Iron Squid
Nov 23, 2005

by Ozmaugh
Has anyone used Game Maker software? I'd like to make some simple games, and my knowledge of programming goes no further than a year of college C++ that were taken almost a decade ago.

I'm not trying to recreate anything as pretty as Crysis or whatnot. Maybe something like a really basic version of Civ or whatever.

DeathBySpoon
Dec 17, 2007

I got myself a paper clip!
XNA and C# is always a great place to start. You can do some pretty fancy things in it, and it's very well documented.

Iron Squid
Nov 23, 2005

by Ozmaugh

DeathBySpoon posted:

XNA and C# is always a great place to start. You can do some pretty fancy things in it, and it's very well documented.

What are the pros and cons of this versus Game Maker? Also, the C# development software isn't free, is it?

Bakkon
Jun 7, 2006

SQUIRTLE SQUAD

Iron Squid posted:

What are the pros and cons of this versus Game Maker? Also, the C# development software isn't free, is it?

Knowledge of C# and XNA is actually applicable to getting a real job. And no, C#/XNA is completely free unless you plan to develop for the Xbox 360.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Also Game Maker is bad.

Iron Squid
Nov 23, 2005

by Ozmaugh

Bakkon posted:

Knowledge of C# and XNA is actually applicable to getting a real job. And no, C#/XNA is completely free unless you plan to develop for the Xbox 360.

I have no desire to get a job designing games. I thought MS charged for Visual Studio.

Nippashish
Nov 2, 2005

Let me see you dance!

Iron Squid posted:

What are the pros and cons of this versus Game Maker? Also, the C# development software isn't free, is it?

Game maker is far too simple to do anything vaguely civ-like. Game maker is appropriate for games on the complexity level of simple platformers.

MasterSlowPoke
Oct 9, 2005

Our courage will pull us through
Visual Studio is free unless you want features like a button to restart a debug run.

Iron Squid
Nov 23, 2005

by Ozmaugh

Nippashish posted:

Game maker is far too simple to do anything vaguely civ-like. Game maker is appropriate for games on the complexity level of simple platformers.

XNA looks better the more I look at it. If I code a game for Windows with it, is it pretty easy to port over to the Xbox? I'm assuming it is.

Now to find a high-end graphic designer who will work for free with only an iffy promise of a percentage of profits at some vague point down the road! :toot:

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.

Iron Squid posted:

I have no desire to get a job designing games. I thought MS charged for Visual Studio.
Microsoft charges for Visual Studio, but gives away a thing called Visual Studio Express for free. The free version is remarkably feature rich - you won't miss any of the paid version features if you're just messing around as a one person team at home.

If you want to try it out the things to download are:
1) Visual Studio Express 2008 C# Edition
2) XNA Game Studio 3.1

Install those and then check out some of the tutorials, like this one for 2D games.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Iron Squid posted:

I have no desire to get a job designing games. I thought MS charged for Visual Studio.

Good because most people won't hire you for game programming if all you know is C# either.

Adbot
ADBOT LOVES YOU

No Safe Word
Feb 26, 2005

Avenging Dentist posted:

Also Game Maker is bad.

Um, anything that can produce Barkley Shut Up and Jam: Gaiden is good in my book

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply