Do you mean interpolation?
Linear interpolation between two vectors, v₀ and v₁:
v(x) = x*v₁ + (1-x)v₀, 0<=x<=1
Do you mean interpolation?
Linear interpolation between two vectors, v₀ and v₁:
v(x) = x*v₁ + (1-x)v₀, 0<=x<=1
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.
You could use HGE. It's easy to start with.
If you know pointers you know how to use HGE.
Link: http://hge.relishgames.com/
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).
Thanks, this is really useful. By the way is there a generally recommended site for DirectX tutorials if I decide to use that?
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
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
Here's my issue:player_x = player_x + 10 -- to player_x = player_x + 250 * dt
There's a value that's multiplied by 0.8 each frame. Like this:
How would I convert that to delta-based code?velocity_x = velocity_x * 0.8
velocity_x = velocity_x - (velocity_x * (1 - 0.8) * dt)
Thanks.
I was using http://www.opentk.com/project/TexLib 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?
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:
Where I declare the list:Code:list<struct Node*>::iterator itNode = this->renderList.begin(); while(itNode != this->renderList.end()) { (*itNode)->object->Render(); itNode++; }
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.Code:list<struct Node*> renderList;
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().
Any help would be appreciated. I've tried everything and I just can't get it to work, it's driving me insane.Code:if (this->renderList.empty()) return;
Pretty sure that's not correct.
It should be velocity_x = velocity_x * 0.8 ^ dt
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...
Square-square collision is coming next, watch this space!
Edited:
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.
![]()
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 http://www.metamodsource.net/mmsdrop/1.8/ and http://www.sourcemod.net/smdrop/1.3/ and save them in a folder somewhere? I'm essentially wanting to create an out of game autoupdate.
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.
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.
Isn't it a joke towards the Linux versioning?
Oops, I didn't initialize the class doing the iteration. Wow, I feel silly. Thanks for pointing me in the right direction.![]()
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?
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;
Edited: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; } }
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.
EDIT: Nevermind
You do realize this is the programming section right
Shit, leaving now
Yes, thank you.
How do I generate a number between 3 and 4? It's something like generator.nextInt(3) + 4, but I have forgotten.
You multiply with The DeltaFrameTime.
I think you where using love so for example
function love.update( dt ) -- dt = DeltaFrameTime myobject.x = myobject.x + 3 * dt -- 3 is the speed of the object we multiply this with deltaframetime. here we go from moving 3 pixels a frame to moving 3 pixels a second. end
DeltaFrameTime is the time it took the frame to render/run completely.
For example if we run at 10 frames a second delta frame time will be 1/10 = 0.1
if we for example say we move the pad down when the 'down' key is down we move the object 3 pixels down.
When you are not multiplying with delta frame time you will move the object 3 pixels every frame on a slow pc this might be with 10 frames a second, on a fast pc this might be with a 100 frames a second.
So if we multiply with dt instead of moving 3 pixels that frame it will move 3 * 0.1 = 0.3 pixels. and that way make sure we always move at the same speed a second
FPS goes up, DT goes down.
On initialization-time, yes, a negligible cost. On run-time - nothing, a little bit when debugging perhaps; again negligible.
Edited:
generator.nextInt(1)+3, assuming that nextInt(1) outputs a number within [0..1].
Not really rocket science o.O
Yeah, sorry, i'm just really tired, and I can't think straight.
Edited:
Wait. This IS rocket science, your solution didn't work for me, it only generates 3 atm. Also, my way of generating them is:
Random generator = new Random(); int random1 = generator.nextInt(1) + 3;
This always gives me 3.
It probably outputs [0..1[. Or just bad luck .. you never know.
int random2 = generator.nextInt(2) + 3;
This worked, thanks.
By vector... do you mean coordinate? If you know how to move it in the direction (linear interpolation (lerp?)) then you must be able to just set the item's position to the destination vector, no?