• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=Richy19;35433089]I want to have a mini console in my game, where I can output stuff or input stuff, but I want to also display all the cout stuff in it, now I managed to find out how to cnage the cout to be a different fstream to for example write it to a file, but I was wondering how can I access what is stored in the cout's stream? my idea was to say during the init stages or update stages have stuff output to cout, then have the console class read all the stream of the cout in the update stage and just print it to screen Is this possible?[/QUOTE] I have no experience doing specifically what you're trying to do, and this is C rather than C++, but one could use a (temporary) log file and print/read from it. Or an obstack or some equivalent, or a custom stream which primarily writes into memory and periodically and upon termination into a log file. If you were using glibc all this would be easy with cookies: fopencookie().
Okay I'm going to ask this here, because it seems appropriate. I'm working on a project, and I need to modify someone else's code slightly. A little, minor change. The only problem is that he used Boost, and Boost refuses to properly install or something. I tried installing it from scratch, and I tried using BoostPro. I don't see what I can be doing wrong as I followed a guide, and BoostPro has like three checkboxes that you fill in appropriate to your IDE. I'm using VS9/2008. When I try to compile, Boost explodes with all sorts of errors, here's an excerpt: [URL]http://pastebin.com/qJdQ8w2X[/URL] I really want to continue working on my project. Does anybody have any idea what is going on? I've asked in Boost's IRC channel, but it's surprisingly idle and the only answers I've gotten are "You did it wrong. Do it again." I've done it four times now, tried compiling from scratch following a guide, and BoostPro has like three checkboxes - there's no way to screw it up. EDIT: I updated Visual Studio and downgraded Boost to 1.42. Seems to work now.
Uhh.. Why are you building Boost with Visual Studio? You're supposed to be using the Boost.Build system, by running 'bootstrap.bat' and following the readme. Did you even read it??
I'm trying to code a nuclear strike simulator in Visual Basic. I got the required info for simulating a strike on the city of oulu (148500 people, density 102.11/km2) but I don't know how to move on from there (we started coding this year). [code]Dim Oulu As Single = 148500 Dim Y As Double = 2.5[/code] The Y is the multiplier for thermal, blast, and radiation per 2,5 kiloton warhead. [code]r_thermal = Y^0.41*constant_th r_blast = Y^0.33*constant_bl r_radiation = Y^0.19*constant_rad[/code] I am starting with the effects of the strike during the strike and immediately after, only calculating the casualty rate.
[QUOTE=ROBO_DONUT;35435313]That's not going to work well for you at all. You might be able to get [i]something[/i] out of it if you map logarithmically. Like: int y = sign(x) * (float)INT_MAX * (128.0 + log2(abs(x))) / 256.0 ...and whatever the reverse process of that is. Edit: The reverse process is: float x = sign(x) * exp2(256.0 * (float)abs(x) / (float)INT_MAX - 128.0) Don't try to map the entire range of values. That's a bad idea. Choose a 'near plane' and a 'far plane' and scale that range to the range of integers. Look at how OpenGL handles projection. It uses integer depth buffers for most things. [url]http://www.songho.ca/opengl/gl_projectionmatrix.html[/url] And after you've got depth in the [-1, 1] range, it's trivial to remap to the range of integers.[/QUOTE] I see I ended up using a logarithmic depth buffer to scale between -1 and 1 and *sing by int_max, thanks
Has anyone else ever experienced blue screens after compiling SFML in Visual Studio? I can use it just fine in XCode but when I tried to set it up for windows it gives a blue screen after it's done compiling.
[QUOTE=T3hGamerDK;35438256]Uhh.. Why are you building Boost with Visual Studio? You're supposed to be using the Boost.Build system, by running 'bootstrap.bat' and following the readme. Did you even read it??[/QUOTE] I did build it with the Boost build system. I meant when I try to compile something that uses Boost.
[QUOTE=Sickle;35433058]Ooohhh, thanks, man! Oh wow, no matter what I do, the thing outputs, 'x is not in the array!' target = (int)((Math.random() * 100) + 1); System.out.println("The target is " + target); boolean inArray = false; for (int m = 0; m < array.length; m++) { if (array[m] == target) { int index = m; inArray = true; System.out.println(target + " is at index " + index + " in the array."); } else { inArray = false; } } if (inArray == false) { System.out.println(target + " is not in the array!"); } Anyone know what I'm doing wrong with my if statements?[/QUOTE] It looks to me like the else [php] else { inArray = false; }[/php] is not needed. When it's there, if there are any elements after the target that is not equal to the target, inArray is set to false. If it is unessecery to look through the whole array when the target is found just once, you can also break; the loop in the if (array[m] == target).
I have to make a design document for 3 games I am making as a college project. The games are Connect Four, Snakes and Ladders and Checkers. I have Connect Four and Snakes and ladders so far, could you guys tell me if it looks okay or if I should change anything? [url]http://pastebin.com/iEgxyi9r[/url]
[QUOTE=Doritos_Man;35418082]Yeah and I prefer to learn from a book if it's related to programming, I don't know why but I just find it easier.[/QUOTE] I always love learning from books, but all the programming books I've picked up were sort of eehhh. I always end up reading function references and source code :(
So for my current project in C Programming class we need to make the fastest and most memory efficient program we can for following buy and sell orders of stocks. This project is a continuation of the past two projects that we've been working on and I already have a working program using a hash map for data storage up and running. The question is now that we can use any data structure to hold the data and the purpose of the project is to try and run the fastest, which data structure should I use? In the project there is many add, delete, and edit commands, so the data structure should be set up so that I can easily find whichever order I need by id #. I also need to be able to access the highest buy and lowest sell priced order every n commands (could either keep a sorted structure at all times or keep an unordered structure and only sort it after n commands). Currently I have a hash map that contains several linked lists of order nodes sorted by id. Each node contains the order id, if the order is to buy or sell, quantity of the order, and price. I also have two linked lists that keep track of the orders in terms of buy/sell prices (the head of the linked list being the current lowest and the tail being the current highest). I was considering using two heaps (one for buy and one for sell) where the root for the buy heap was the highest price and the root for the sell heap was the lowest price, but then that means that whenever I want to delete an order (when a delete command is given, only the id is supplied) then I would have to search both trees to find it. Any ideas, Facepunch?
How many stocks will you need to keep track of? Hash might be the fastest, and not sorting the buckets might help (you take a bit of a hit when finding the highest / lowest / searching by id, but sorting takes time. Question is which takes more?). If the buckets aren't huge then a linear search through the bucket won't hurt much. You could always just have pointers to the min / max and when adding new / editing stocks see if they are the new min / max, that way you don't even have to search for them. But then if you delete one you have to search for the new min / max. You could do some sort of a priority queue where stocks that are queried most often get higher priority (and lose priority after a certain amount of time) and just do linear searches on that. Also you mention you have a hash table and linked lists, how many structures can you use (I don't mean you used linked lists to make a hash map but that you said you had the stocks stored in several structures)? Also if you know the max id # then you can make a perfect hash and get rid of buckets. It could waste a little bit of memory if you aren't filling it all up but accessing would be faster. Pros and cons to everything I guess.
[QUOTE=thrawn2787;35448932]How many stocks will you need to keep track of? Hash might be the fastest, and not sorting the buckets might help (you take a bit of a hit when finding the highest / lowest / searching by id, but sorting takes time. Question is which takes more?). If the buckets aren't huge then a linear search through the bucket won't hurt much. You could always just have pointers to the min / max and when adding new / editing stocks see if they are the new min / max, that way you don't even have to search for them. But then if you delete one you have to search for the new min / max. You could do some sort of a priority queue where stocks that are queried most often get higher priority (and lose priority after a certain amount of time) and just do linear searches on that. Also you mention you have a hash table and linked lists, how many structures can you use (I don't mean you used linked lists to make a hash map but that you said you had the stocks stored in several structures)? Also if you know the max id # then you can make a perfect hash and get rid of buckets. It could waste a little bit of memory if you aren't filling it all up but accessing would be faster. Pros and cons to everything I guess.[/QUOTE] The input file has orders for many different stocks but a symbol is given in the command line arguments and I only have to keep track of the one stock and ignore the orders about all the others. It's not really likely that one order will be queried more often so that'd be a waste of processing time. Also, the max id is unknown. They can be any number that can fit in an unsigned int. Here's a pdf showing how I have my data sorted: [url]http://piazza-uploads.s3-website-us-east-1.amazonaws.com/attach/gwxlo090d1u367/h00cbz8us5d518/h05okyvc93w5pa/sorted_list.pdf[/url] The solid lines are how the orders are stored in the hash map and the dotted lines show the buy/sell list and how they are connecting the nodes contained within the hash map. The image only shows one buy/sell list, but I actually have 2, buy and sell. No order is in both the buy and sell list because orders are either being bought or sold. Therefore, every order is in the hash map sorted by id and also in either the buy or sell list.
Oh that's really neat, never thought to have a list inside a hash like that. That looks pretty fast as is.
is it necessary to be good at math to program? I can do the basics, addition, Subtraction, multiplication, division, and basic geometry and algebra, but after that I lose it. [editline]6th April 2012[/editline] specifically Python for blender animations and stuff.
[QUOTE=nemmises5;35451550]is it necessary to be good at math to program? I can do the basics, addition, Subtraction, multiplication, division, and basic geometry and algebra, but after that I lose it. [editline]6th April 2012[/editline] specifically Python for blender animations and stuff.[/QUOTE] For games, you might want to learn some trigonometry too, but no, you don't actually need to know more than this.
I have to make a design document for 3 games I am making as a college project. The games are Connect Four, Snakes and Ladders and Checkers. I have Connect Four and Snakes and ladders so far, could you guys tell me if it looks okay or if I should change anything? [url]http://pastebin.com/iEgxyi9r[/url]
Im trying to get my head around movement in a fps style movement system. basically in my shitty point skills [imghttp://i.imgur.com/XbO26.png[/img] so in code: [cpp]//View = glm::mat4(1.0); View = glm::lookAt( glm::vec3(0, 5, 3), // the position of your camera, in world space glm::vec3(0, 0, 0), // where you want to look at, in world space glm::vec3(0, 1, 0) // probably glm::vec3(0,1,0), but (0,-1,0) would make you looking upside-down, which can be great too ); [/cpp] im guessing when you look straight its simple, say you move left, you just subtract say 10*delta to the x of the position and of the lookingAtPosition but what if your not looking straight? and when you move the mouse the position your looking at changes, but it would have to change in a circular motion, i think I get how it would be done with trig. I just have to first do the X value and then the Y right?
[QUOTE=Richy19;35456102]Im trying to get my head around movement in a fps style movement system. basically in my shitty point skills [imghttp://i.imgur.com/XbO26.png[/img] so in code: [cpp]//View = glm::mat4(1.0); View = glm::lookAt( glm::vec3(0, 5, 3), // the position of your camera, in world space glm::vec3(0, 0, 0), // where you want to look at, in world space glm::vec3(0, 1, 0) // probably glm::vec3(0,1,0), but (0,-1,0) would make you looking upside-down, which can be great too ); [/cpp] im guessing when you look straight its simple, say you move left, you just subtract say 10*delta to the x of the position and of the lookingAtPosition but what if your not looking straight? and when you move the mouse the position your looking at changes, but it would have to change in a circular motion, i think I get how it would be done with trig. I just have to first do the X value and then the Y right?[/QUOTE] Get the angles you're looking in and use trig to move him in that direction (X += sin(yaw); Y += cos(yaw)). I've noticed you're in Linux and not online in steam. Get steam working in Linux and I'll answer your questions more directly, if you have gmail I can chat with you at [email]naelstrof@gmail.com[/email] to help you get steam working.
[QUOTE=nemmises5;35451550]is it necessary to be good at math to program? I can do the basics, addition, Subtraction, multiplication, division, and basic geometry and algebra, but after that I lose it. [editline]6th April 2012[/editline] specifically Python for blender animations and stuff.[/QUOTE] As with anything it depends on the complexity. For 2D stuff basic Algebra, Geometry, and Trigonometry will be fine. For 3D you'll need to understand more complex trigonometry and matrix Algebra.
What is a fast way to figure out if a sprite is on screen or not? I want a fast way of culling non-visible entities from the draw queue, was going to just do AABB checks for each sprite but that sounds really inefficient.
if( !screenRect.contains( sprite.rect ) )
There's something about derived classes in C++ that I'm not understanding. [cpp] #include <iostream> using namespace std; class Base { public: Base() { cerr << "Created base " << this << endl; } virtual ~Base() { cerr << "Destroyed base " << this << endl; } }; class Derived : public Base { public: Derived() { cerr << "Created derived " << this << endl; } Derived(const Base & b) { cerr << "Copied derived " << this << endl; } ~Derived() { cerr << "Destroyed derived " << this << endl; } }; int main() { Derived x; Derived y (x); return EXIT_SUCCESS; }[/cpp] Displays [code] Created base 0x1234 Created derived 0x1234 Destroyed derived 0x5678 Destroyed base 0x5678 Destroyed derived 0x1234 Destroyed base 0x1234 [/code] That is to say, Derived y (x) calls only the implicit Base copy constructor, skipping the one I defined entirely. Why is that? I figured it would interpret x as a Base, and find the matching constructor declaration, but instead it seems to interpret both x and y as Base. The reason I'm trying to do this is because I want several classes all deriving from the same abstract base class, but all able to be constructed using any of the others - without needing to code a specific constructor for each class. Using the clone pattern works, but that's almost as tedious because then I need to define a clone method for every derived class.
[QUOTE=Larikang;35459244]That is to say, Derived y (x) calls only the implicit Base copy constructor, skipping the one I defined entirely. Why is that? I figured it would interpret x as a Base, and find the matching constructor declaration, but instead it seems to interpret both x and y as Base.[/QUOTE] No, it's interpreting both x and y as Derived, which means it's not going to call your custom constructor that takes a Base instead of a Derived. But I think if you cast what you're passing to Base, it'll work. Try this: [cpp] Derived y ((Base)x); [/cpp] (Or maybe I have no idea what I'm talking about; I haven't dealt with the complexities of the C++ type system in a while)
Im trying to create a flat 256*256 verticie field, so I have the following: [cpp] #define pointCount 768 GLfloat g_vertex_buffer_data[pointCount * pointCount]; int x = 0; for(int y = 0; y < (pointCount)/3.0f;y++) { g_vertex_buffer_data[(int)(y*(pointCount/3.0f) + x )] = (float)x; g_vertex_buffer_data[(int)(y*(pointCount/3.0f) + x + 1 )] = 0.0f; g_vertex_buffer_data[(int)(y*(pointCount/3.0f) + x + 2 )] = (float)y; x+=3; if(x > (pointCount/3.0f)) x = 0; } // Generate 1 buffer, put the resulting identifier in vertexbuffer glGenBuffers(1, &vertexbuffer); // The following commands will talk about our 'vertexbuffer' buffer glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); // Give our vertices to OpenGL. glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); //...//////////////////////////////////// // 1rst attribute buffer : vertices glEnableVertexAttribArray(positionID); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glVertexAttribPointer( positionID, // attribute 0. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 130050); // Starting from vertex 0; 3 vertices total -> 1 triangle [/cpp] Can anyone see if there is anything wrong with this? Im guessing its with the actuall filling of the array as when drawing it, it isnt flat it looks more like a corner, as in it bends in half
[QUOTE=shill le 2nd;35459975]No, it's interpreting both x and y as Derived, which means it's not going to call your custom constructor that takes a Base instead of a Derived. But I think if you cast what you're passing to Base, it'll work. Try this: [cpp] Derived y ((Base)x); [/cpp] (Or maybe I have no idea what I'm talking about; I haven't dealt with the complexities of the C++ type system in a while)[/QUOTE] Ugh, that worked! I can't believe I didn't try that after being stuck for hours...
[QUOTE=conman420;35457645]What is a fast way to figure out if a sprite is on screen or not? I want a fast way of culling non-visible entities from the draw queue, was going to just do AABB checks for each sprite but that sounds really inefficient.[/QUOTE] Are you counting completely transparent pixels?
[QUOTE=Richy19;35460541]Im trying to create a flat 256*256 verticie field, so I have the following: [cpp] #define pointCount 768 GLfloat g_vertex_buffer_data[pointCount * pointCount]; int x = 0; for(int y = 0; y < (pointCount)/3.0f;y++) { g_vertex_buffer_data[(int)(y*(pointCount/3.0f) + x )] = (float)x; g_vertex_buffer_data[(int)(y*(pointCount/3.0f) + x + 1 )] = 0.0f; g_vertex_buffer_data[(int)(y*(pointCount/3.0f) + x + 2 )] = (float)y; x+=3; if(x > (pointCount/3.0f)) x = 0; } // Generate 1 buffer, put the resulting identifier in vertexbuffer glGenBuffers(1, &vertexbuffer); // The following commands will talk about our 'vertexbuffer' buffer glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); // Give our vertices to OpenGL. glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); //...//////////////////////////////////// // 1rst attribute buffer : vertices glEnableVertexAttribArray(positionID); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glVertexAttribPointer( positionID, // attribute 0. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 130050); // Starting from vertex 0; 3 vertices total -> 1 triangle [/cpp] Can anyone see if there is anything wrong with this? Im guessing its with the actuall filling of the array as when drawing it, it isnt flat it looks more like a corner, as in it bends in half[/QUOTE] 1. You appear to have an obsession with using floating-point numbers as divisors in inappropriate places. 2. Your buffer dimensions are off, and you're iterating over the values incorrectly. It's 256 * 256 * 3, not 768 * 768. You should be doing either: [cpp] for (int y = 0; y < 256; y++) { for (int x = 0; x < 256; x++) { i = y * 256 + x; point[i*3 + 0] = (float)x; point[i*3 + 1] = (float)y; point[i*3 + 2] = 0.0f; } } [/cpp] or [cpp] for (int i = 0; i < 256*256; i++) { x = i % 256; y = i / 256; point[i*3 + 0] = (float)x; point[i*3 + 1] = (float)y; point[i*3 + 2] = 0.0f; } [/cpp]
-snip- thanks
[QUOTE=Hypershadsy;35461117]Are you counting completely transparent pixels?[/QUOTE] Yes, it is just a rough estimate whether or not the sprite should draw.
Sorry, you need to Log In to post a reply to this thread.