• What do you need help with? V. 3.0
    4,884 replies, posted
  • [QUOTE=NotoriousSpy;30180737]How would I move an item along a vector. I have a starting vector and a destination vector. I know how to move it in the direction, but I'm not sure how to move it directly onto the other vector, or to check when it's close (to check for overlap).[/QUOTE] Do you mean interpolation? Linear interpolation between two vectors, [i]v&#8320;[/i] and [i]v&#8321;[/i]: [i]v(x) = x*v&#8321; + (1-x)v&#8320;[/i], [i]0<=x<=1[/i]
  • Tried to compile my game project in release (which didn't throw any errors). It works just fine since I have all the SDKs that I need. I did link and add all the dll files that I would need so it should work on all computers (also added the dll's to the release version). Also uninstalled all the SDKs (DirectX 10 sdk and FMOD sdk), restarted my computer and tried to run the application just to be sure and it worked just fine. I gave two other people the application so they could try it out but they both experienced the same problem, "The procedure entry point __CxxFrameHandler3 could not be located in the dynamic link library msvcrt.dll.". Have anyone else experienced a similar problem? What's missing?
  • I am looking to make a 2D graphical sidescroller just for experience, I'm learning C++ at the moment and would like to know which API I should be using and why? I've read that XNA is good for beginners but it's for C# or so I've heard. I'm learning C++ just fine, got pointers and object-oriented programming down just fine without any hitches so I'd prefer not to get any "learn C# first" replies unless there is a better reason.
  • [QUOTE=Kondor58;30184797]I am looking to make a 2D graphical sidescroller just for experience, I'm learning C++ at the moment and would like to know which API I should be using and why? I've read that XNA is good for beginners but it's for C# or so I've heard. I'm learning C++ just fine, got pointers and object-oriented programming down just fine without any hitches so I'd prefer not to get any "learn C# first" replies unless there is a better reason.[/QUOTE] You could use HGE. It's easy to start with. If you know pointers you know how to use HGE. Link: [B][url]http://hge.relishgames.com/[/url][/B] If you want to get a bit more experience I recommend you start with DirectX directly. The DirectX sprites aren't really hard to work with as long as you know what a SRT matrix is (would recommend HGE for starters though).
  • [QUOTE=Sakarias88;30185634]You could use HGE. It's easy to start with. If you know pointers you know how to use HGE. Link: [B][url]http://hge.relishgames.com/[/url][/B] If you want to get a bit more experience I recommend you start with DirectX directly. The DirectX sprites aren't really hard to work with as long as you know what a SRT matrix is (would recommend HGE for starters though).[/QUOTE] Thanks, this is really useful. By the way is there a generally recommended site for DirectX tutorials if I decide to use that?
  • [QUOTE=Sakarias88;30184505] Have anyone else experienced a similar problem? What's missing?[/QUOTE] They probably don't have the latest C++ runtime
  • Anyone know the actual code that would be used for limiting the FPS? I remember reading somewhere that it was something like if(frame time < desired frame time) thread.sleep(100); Or something like that
  • [QUOTE=Richy19;30187068]Anyone know the actual code that would be used for limiting the FPS? I remember reading somewhere that it was something like if(frame time < desired frame time) thread.sleep(100); Or something like that[/QUOTE] Should probably put (desired frame time - frame time) in sleep instead.
  • Hey, I can't think at the moment, so I've got an issue. I'm converting code that depends on a capped framerate at 25 to delta-based code. So, for example, you would convert [lua] player_x = player_x + 10 -- to player_x = player_x + 250 * dt [/lua] Here's my issue: There's a value that's multiplied by 0.8 each frame. Like this: [lua] velocity_x = velocity_x * 0.8 [/lua] How would I convert that to delta-based code?
  • [QUOTE=thelinx;30188475]Hey, I can't think at the moment, so I've got an issue. I'm converting code that depends on a capped framerate at 25 to delta-based code. So, for example, you would convert [lua] player_x = player_x + 10 -- to player_x = player_x + 250 * dt [/lua] Here's my issue: There's a value that's multiplied by 0.8 each frame. Like this: [lua] velocity_x = velocity_x * 0.8 [/lua] How would I convert that to delta-based code?[/QUOTE] velocity_x = velocity_x - (velocity_x * (1 - 0.8) * dt)
  • I was using [url]http://www.opentk.com/project/TexLib[/url] to load textures for my openTK project, but after I had set everything up, I noticed that there were errors on every single line refrencing things that had to do with textures. What did I do wrong?
  • [QUOTE=Chris220;30176446]For starters that should be spritestouch() [B]==[/B] true :P As for collision detection, how precise do you need it? If your sprites are generally circular, or rectangular, or any other primitive shape, you can use some very simple collision checks. If you need pixel precision, you can do that as well but it IS slower. So, what do you need. Precise and slow? Or vague and fast.[/QUOTE] Either one, but I want someone to explain to me how it would work so I would actually learn something out of it, not just "here is some code go put it in."
  • I'm having some trouble iterating through a list of objects to render. I keep getting an "Access violation reading location" error. Unfortunately it doesn't seem to get any more specific than that. If I break, it seems to be a problem at renderList.begin() somehow. The piece of code in question: [code]list<struct Node*>::iterator itNode = this->renderList.begin(); while(itNode != this->renderList.end()) { (*itNode)->object->Render(); itNode++; }[/code] Where I declare the list: [code]list<struct Node*> renderList;[/code] Basically I want to have a list (renderList) of Nodes, which contain a position and an object to be rendered, then loop through it and render each node's object. Maybe I'm not going about this the right way at all. It's also entirely possible that I'm just doing something incredibly stupid, especially when it comes to pointers. I'm a bit new to C++, most of my experience is in C# where we're lazy and don't touch any memory-related stuff at all. I tried adding this before where I iterate through the list, assuming it was a problem with me not adding anything to the list thus far, but the only thing that changes is what piece of code I'm directed towards when I break debugging. With this code, the error seems to be in empty() rather than begin(). [code]if (this->renderList.empty()) return;[/code] Any help would be appreciated. I've tried everything and I just can't get it to work, it's driving me insane.
  • [QUOTE=ColdFusion;30188582]velocity_x = velocity_x - (velocity_x * (1 - 0.8) * dt)[/QUOTE] Pretty sure that's not correct. It should be velocity_x = velocity_x * 0.8 ^ dt
  • [QUOTE=amazer97;30195268]Either one, but I want someone to explain to me how it would work so I would actually learn something out of it, not just "here is some code go put it in."[/QUOTE] Well, I'll teach you two vague methods first, and you can see if they're good enough. The first method is circle->circle collision detection. This is arguably the easiest method of collision detection there is. Naturally, this is suited to vaguely circular objects. I'm not very good with words, so I drew you a picture... [img]http://i.imgur.com/MRZKe.png[/img] Square-square collision is coming next, watch this space! [editline]2nd June 2011[/editline] Square-square collision is ever so slightly more complex than circle-circle, but it's still extremely simple. Also note that this method can be applied to any two rectangles, they don't have to be square and they do not have to be identical to each other. [img]http://i.imgur.com/lPspi.png[/img]
  • [QUOTE=dvondrake;30195351]I'm having some trouble iterating through a list of objects to render. I keep getting an "Access violation reading location" error. Unfortunately it doesn't seem to get any more specific than that. If I break, it seems to be a problem at renderList.begin() somehow. The piece of code in question: [code]list<struct Node*>::iterator itNode = this->renderList.begin(); while(itNode != this->renderList.end()) { (*itNode)->object->Render(); itNode++; }[/code] Where I declare the list: [code]list<struct Node*> renderList;[/code] Basically I want to have a list (renderList) of Nodes, which contain a position and an object to be rendered, then loop through it and render each node's object. Maybe I'm not going about this the right way at all. It's also entirely possible that I'm just doing something incredibly stupid, especially when it comes to pointers. I'm a bit new to C++, most of my experience is in C# where we're lazy and don't touch any memory-related stuff at all. I tried adding this before where I iterate through the list, assuming it was a problem with me not adding anything to the list thus far, but the only thing that changes is what piece of code I'm directed towards when I break debugging. With this code, the error seems to be in empty() rather than begin(). [code]if (this->renderList.empty()) return;[/code] Any help would be appreciated. I've tried everything and I just can't get it to work, it's driving me insane.[/QUOTE] It could indicate that the renderList was not constructed properly. Did you compile in debug-mode? What's the exact error-message? How do you create the class doing the iteration, how do you initialize renderList and how do you modify it?
  • How can I download the latest windows snapshots from [url]http://www.metamodsource.net/mmsdrop/1.8/[/url] and [url]http://www.sourcemod.net/smdrop/1.3/[/url] and save them in a folder somewhere? I'm essentially wanting to create an out of game autoupdate.
  • [QUOTE=Chris220;30196726]Well, I'll teach you two vague methods first, and you can see if they're good enough. The first method is circle->circle collision detection. This is arguably the easiest method of collision detection there is. Naturally, this is suited to vaguely circular objects. I'm not very good with words, so I drew you a picture... [img]http://i.imgur.com/MRZKe.png[/img] Square-square collision is coming next, watch this space! [editline]2nd June 2011[/editline] Square-square collision is ever so slightly more complex than circle-circle, but it's still extremely simple. Also note that this method can be applied to any two rectangles, they don't have to be square and they do not have to be identical to each other. [img]http://i.imgur.com/lPspi.png[/img][/QUOTE] Wow thanks, that makes a lot more sense than another explanation I read, this helps me greatly! Thanks so much!
  • I need some way to limit my framerate for my game to 60. Because I have 850 FPS atm, and my game is running like speedy gonzalez.
  • [QUOTE=amazer97;30199987]Wow thanks, that makes a lot more sense than another explanation I read, this helps me greatly! Thanks so much![/QUOTE] No problem :) If you want to know about any other collision methods (if those two aren't what you're looking for), just ask and I'll see what I can do.
  • [QUOTE=ief014;30126384]No[/QUOTE] Isn't it a joke towards the Linux versioning?
  • [QUOTE=ZeekyHBomb;30196892]It could indicate that the renderList was not constructed properly. Did you compile in debug-mode? What's the exact error-message? How do you create the class doing the iteration, how do you initialize renderList and how do you modify it?[/QUOTE] Oops, I didn't initialize the class doing the iteration. Wow, I feel silly. Thanks for pointing me in the right direction. :smile:
  • Quick Java question: Does the number of functions a non-static class has affect its performance?
  • There was this guide on collision detection with 2d shapes I read a while back, something to do with N or something. Could someone post it if you know what I'm talking about?
  • [QUOTE=Mr. Smartass;30194557]I was using [url]http://www.opentk.com/project/TexLib[/url] to load textures for my openTK project, but after I had set everything up, I noticed that there were errors on every single line refrencing things that had to do with textures. What did I do wrong?[/QUOTE] Retoast. I really want to get this working. I can't really do anything untill I figure out the problem.
  • Probably didn't add the System.Drawing reference to your project. Although, I don't remember it being necessary.
  • Here's the class for the textureloader; [code]using OpenTK.Graphics; using System.Diagnostics; using System.Drawing; using Img = System.Drawing.Imaging; /* Example code: // Setup GL state for ordinary texturing. TexUtil.InitTexturing(); // Load a bitmap from disc, and put it in a GL texture. int tex = TexUtil.CreateTextureFromFile("mybitmapfont.png"); // Create a TextureFont object from the loaded texture. TextureFont texFont = new TextureFont(tex); // Write something centered in the viewport. texFont.WriteStringAt("Center", 10, 50, 50, 0); */ namespace TexLib { /// <summary> /// The TexUtil class is released under the MIT-license. /// /Olof Bjarnason /// </summary> public static class TexUtil { #region Public /// <summary> /// Initialize OpenGL state to enable alpha-blended texturing. /// Disable again with GL.Disable(EnableCap.Texture2D). /// Call this before drawing any texture, when you boot your /// application, eg. in OnLoad() of GameWindow or Form_Load() /// if you're building a WinForm app. /// </summary> public static void InitTexturing() { GL.Disable(EnableCap.CullFace); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); } /// <summary> /// Create an opaque OpenGL texture object from a given byte-array of r,g,b-triplets. /// Make sure width and height is 1, 2, .., 32, 64, 128, 256 and so on in size since all /// 3d graphics cards support those dimensions. Not necessarily square. Don't forget /// to call GL.DeleteTexture(int) when you don't need the texture anymore (eg. when switching /// levels in your game). /// </summary> public static int CreateRGBTexture(int width, int height, byte[] rgb) { return CreateTexture(width, height, false, rgb); } /// <summary> /// Create a translucent OpenGL texture object from given byte-array of r,g,b,a-triplets. /// See CreateRGBTexture for more info. /// </summary> public static int CreateRGBATexture(int width, int height, byte[] rgba) { return CreateTexture(width, height, true, rgba); } /// <summary> /// Create an OpenGL texture (translucent or opaque) from a given Bitmap. /// 24- and 32-bit bitmaps supported. /// </summary> public static int CreateTextureFromBitmap(Bitmap bitmap) { Img.BitmapData data = bitmap.LockBits( new Rectangle(0, 0, bitmap.Width, bitmap.Height), Img.ImageLockMode.ReadOnly, Img.PixelFormat.Format32bppArgb); var tex = GiveMeATexture(); GL.BindTexture(TextureTarget.Texture2D, tex); GL.TexImage2D( TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); bitmap.UnlockBits(data); SetParameters(); return tex; } /// <summary> /// Create an OpenGL texture (translucent or opaque) by loading a bitmap /// from file. 24- and 32-bit bitmaps supported. /// </summary> public static int CreateTextureFromFile(string path) { return CreateTextureFromBitmap(new Bitmap(Bitmap.FromFile(path))); } #endregion private static int CreateTexture(int width, int height, bool alpha, byte[] bytes) { int expectedBytes = width * height * (alpha ? 4 : 3); Debug.Assert(expectedBytes == bytes.Length); int tex = GiveMeATexture(); Upload(width, height, alpha, bytes); SetParameters(); return tex; } private static int GiveMeATexture() { int tex = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, tex); return tex; } private static void SetParameters() { GL.TexParameter( TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); } private static void Upload(int width, int height, bool alpha, byte[] bytes) { var internalFormat = alpha ? PixelInternalFormat.Rgba : PixelInternalFormat.Rgb; var format = alpha ? PixelFormat.Rgba : PixelFormat.Rgb; GL.TexImage2D<byte>( TextureTarget.Texture2D, 0, internalFormat, width, height, 0, format, PixelType.UnsignedByte, bytes); } } public class TextureFont { /// <summary> /// Create a TextureFont object. The sent-in textureId should refer to a /// texture bitmap containing a 16x16 grid of fixed-width characters, /// representing the ASCII table. A 32 bit texture is assumed, aswell as /// all GL state necessary to turn on texturing. The dimension of the /// texture bitmap may be anything from 128x128 to 512x256 or any other /// order-by-two-squared-dimensions. /// </summary> public TextureFont(int textureId) { this.textureId = textureId; } /// <summary> /// Draw an ASCII string around coordinate (0,0,0) in the XY-plane of the /// model space coordinate system. The height of the text is 1.0. /// The width may be computed by calling ComputeWidth(string). /// This call modifies the currently bound /// 2D-texture, but no other GL state. /// </summary> public void WriteString(string text) { GL.BindTexture(TextureTarget.Texture2D, textureId); GL.PushMatrix(); double width = ComputeWidth(text); GL.Translate(-width / 2.0, -0.5, 0); GL.Begin(BeginMode.Quads); double xpos = 0; foreach (var ch in text) { WriteCharacter(ch, xpos); xpos += AdvanceWidth; } GL.End(); GL.PopMatrix(); } /// <summary> /// Determines the distance from character center to adjacent character center, horizontally, in /// one written text string. Model space coordinates. /// </summary> public double AdvanceWidth = 0.75; /// <summary> /// Determines the width of the cut-out to do for each character when rendering. This is necessary /// to avoid artefacts stemming from filtering (zooming/rotating). Make sure your font contains some /// "white space" around each character so they won't be clipped due to this! /// </summary> public double CharacterBoundingBoxWidth = 0.8; /// <summary> /// Determines the height of the cut-out to do for each character when rendering. This is necessary /// to avoid artefacts stemming from filtering (zooming/rotating). Make sure your font contains some /// "white space" around each character so they won't be clipped due to this! /// </summary> public double CharacterBoundingBoxHeight = 0.8;//{ get { return 1.0 - borderY * 2; } set { borderY = (1.0 - value) / 2.0; } } /// <summary> /// Computes the expected width of text string given. The height is always 1.0. /// Model space coordinates. /// </summary> public double ComputeWidth(string text) { return text.Length * AdvanceWidth; } /// <summary> /// This is a convenience function to write a text string using a simple coordinate system defined to be 0..100 in x and 0..100 in y. /// For example, writing the text at 50,50 means it will be centered onscreen. The height is given in percent of the height of the viewport. /// No GL state except the currently bound texture is modified. This method is not as flexible nor as fast /// as the WriteString() method, but it is easier to use. /// </summary> public void WriteStringAt( string text, double heightPercent, double xPercent, double yPercent, double degreesCounterClockwise) { GL.MatrixMode(MatrixMode.Projection); GL.PushMatrix(); GL.LoadIdentity(); GL.Ortho(0, 100, 0, 100, -1, 1); GL.MatrixMode(MatrixMode.Modelview); GL.PushMatrix(); GL.LoadIdentity(); GL.Translate(xPercent, yPercent, 0); double aspectRatio = ComputeAspectRatio(); GL.Scale(aspectRatio * heightPercent, heightPercent, heightPercent); GL.Rotate(degreesCounterClockwise, 0, 0, 1); WriteString(text); GL.PopMatrix(); GL.MatrixMode(MatrixMode.Projection); GL.PopMatrix(); GL.MatrixMode(MatrixMode.Modelview); } private static double ComputeAspectRatio() { int[] viewport = new int[4]; GL.GetInteger(GetPName.Viewport, viewport); int w = viewport[2]; int h = viewport[3]; double aspectRatio = (float)h / (float)w; return aspectRatio; } private void WriteCharacter(char ch, double xpos) { byte ascii; unchecked { ascii = (byte)ch; } int row = ascii >> 4; int col = ascii & 0x0F; double centerx = (col + 0.5) * Sixteenth; double centery = (row + 0.5) * Sixteenth; double halfHeight = CharacterBoundingBoxHeight * Sixteenth / 2.0; double halfWidth = CharacterBoundingBoxWidth * Sixteenth / 2.0; double left = centerx - halfWidth; double right = centerx + halfWidth; double top = centery - halfHeight; double bottom = centery + halfHeight; GL.TexCoord2(left, top); GL.Vertex2(xpos, 1); GL.TexCoord2(right, top); GL.Vertex2(xpos + 1, 1); GL.TexCoord2(right, bottom); GL.Vertex2(xpos + 1, 0); GL.TexCoord2(left, bottom); GL.Vertex2(xpos, 0); } private int textureId; private const double Sixteenth = 1.0 / 16.0; } } [/code] [editline]2nd June 2011[/editline] Every single line beginning with GL.something or anything that has to do with texture loading throws errors. The thing is, in my main program class, It doesn't throw any errors at all, and works perfectly.
  • [QUOTE=Angry Pineapple;30205214]How do you drill a hole in 1/8 thick glass without breaking it?[/QUOTE] You do realize this is the programming section right