• What do you need help with? Version 5
    5,752 replies, posted
I'm trying to compare table values in lua using [lua] for i, v in pairs(blockList) do -- end [/lua] so within that I'm making the blocks move and stuff using blockList[i].y etc., but how do I compare it to everything else in the table? I can't put another loop like I could with; [lua] for i = 1, #blockList do for k = 1, #blockList do -- end end [/lua]
[QUOTE=Jimmylaw;35024977]Is it possible to give a shader to multiple objects to all use it but draw the object in a different position? Right now its drawing the object at the last position given to the shader and i don't really see a way of stopping it.[/QUOTE] Are you modifying the world-space matrix of the objects?
Wanting a good IDE for Python that is available on Windows and Fedora / Arch and is low spec and consistent between the two. I'm getting into Python since it's the "official" raspberry pi language and I'd like to toy with it, so I'd like it to be able to run on it well.
Is there really no way to add mp3 support to SFML? No point in making a mp3 player if it can't play mp3 files edit: SDL it is then
How I make a thread in a class? test.cpp [cpp] void test::ThreadCreate() { CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)test.Func, 0, 0, NULL); } byte test::Func() { return 1; } [/cpp] test.h [cpp] class test { public: void ThreadCreate(); byte Func(); }; [/cpp] Says: "Error, invalid type conversion" at CreateThread (LPTHREAD_START_ROUTINE).
The function you pass to CreateThread has to look like this: [cpp] DWORD WINAPI ThreadStartRoutine(LPVOID lpThreadParameter); [/cpp] So you would do this: [cpp] class Test { public: static DWORD WINAPI ThreadFn(LPVOID param) { Test *instance = (Test *)param; // instance is the "this" pointer. } }; Test instance; CreateThread(NULL, 0, Test::ThreadFn, &instance, 0, NULL); [/cpp]
"Consider the following declarations, in which the variable c stores the radius and coordinates in xOy of a circle's center. Write a C++ expression that outputs 1 only if the circle's center is inside the second quadrant and not on its axis." [quote]struct point{ int x, y; }; struct circle { struct point center; float radius; } c;[/quote] What I came up with but not sure if it's right: if(c.center.x < 0 && c.center.y > 0) cout << 1; What bothers me is the "struct point center;" does it create a new structure or an instance of the previous structure?
I doubt anyone here will be able to help me but here's my problem: I've got a simple Verlet particle physics engine in 2d (C#). I place each particle into a 12.5x12.5 grid and use that grid to get the neighbors of the particle to check for calculations. Now, my problem is that I want to have ~20,000 particles @ 60fps. Does anyone have any advice of how I can improve the speed of my neighbor finding? Right now all I do is find the particle in bordering cells of that particle and do a distance check to see if it's colliding. Then, after each frame I place all the particles in the grid again (because they are moving) and repeat. For anyone curious, I'm trying to implement a crude model of fluids like PixelJunk Shooter. I've already read the presentation and it looks like it's so fast because of the PS3's SPUs.
[QUOTE=Foda;35039088]I doubt anyone here will be able to help me but here's my problem: I've got a simple Verlet particle physics engine in 2d (C#). I place each particle into a 12.5x12.5 grid and use that grid to get the neighbors of the particle to check for calculations. Now, my problem is that I want to have ~20,000 particles @ 60fps. Does anyone have any advice of how I can improve the speed of my neighbor finding? Right now all I do is find the particle in bordering cells of that particle and do a distance check to see if it's colliding. Then, after each frame I place all the particles in the grid again (because they are moving) and repeat. For anyone curious, I'm trying to implement a crude model of fluids like PixelJunk Shooter. I've already read the presentation and it looks like it's so fast because of the PS3's SPUs.[/QUOTE] A quadtree may or may not improve performance. If each cell of the 12.5x12.5 grid holds from zero to just a few particles, it's extremely optimal for what you're doing and there isn't much you can do anymore. It makes comparing each particle to its neighbors an approximately O(n) operation, instead of the naive O(n^2). The benefit of quadtrees is that they do not require a grid of such an optimal size - they improve the performance to O(n log n) regardless.
Hello! Whenver I try to [URL="http://pastebin.com/MFiCZQPC"]compile this C code[/URL], I get the following error: evolution.c:6 [It's line 7 on the pastebin]: identifier expected I'm fairly new to such a relatively low-level language, and the code is by no means complete. I'm using the [URL="http://bellard.org/tcc/"]tcc compiler[/URL], if that has anything to do with it. Any help would be greatly appreciated! :3
That's not how you initialize a struct.
[QUOTE=Tinker Toy;35041292]Hello! Whenver I try to [URL="http://pastebin.com/MFiCZQPC"]compile this C code[/URL], I get the following error: evolution.c:6 [It's line 7 on the pastebin]: identifier expected I'm fairly new to such a relatively low-level language, and the code is by no means complete. I'm using the [URL="http://bellard.org/tcc/"]tcc compiler[/URL], if that has anything to do with it. Any help would be greatly appreciated! :3[/QUOTE] You initialize a struct like you would an array.
[QUOTE=esalaka;35041436]That's not how you initialize a struct.[/QUOTE] [QUOTE=Octave;35041471]You initialize a struct like you would an array.[/QUOTE] Unfortunately, I've tried it every way I could figure out. The only way that works is to fill in every single field, one line at a time. If you could provide some sample code, that'd be great. Sorry for being so hard to please, but I don't know what to do and I want to get my little project back on track.
[code] typedef struct { int a; int b; int c; } foo; foo thing1 = { 1, 6, 3 }; // thing1.a = 1, thing1.b = 6, thing1.c = 3[/code] Have you tried like this?
[QUOTE=Tinker Toy;35041673]Unfortunately, I've tried it every way I could figure out. The only way that works is to fill in every single field, one line at a time. If you could provide some sample code, that'd be great. Sorry for being so hard to please, but I don't know what to do and I want to get my little project back on track.[/QUOTE] Do it like you're doing, just drop the field names. Like Octave does in his example. You can only initialize them like arrays ( {a, b, c...} ) or one field at a time.
[QUOTE=Octave;35041701][code]bleep bloop[/code] Have you tried like this?[/QUOTE] Creating a single object at a time isn't going to suit my purposes, if that's what you're implying I should do. I'm planning on dealing with the entire population of 20 at a time, which is why I used an array, and calling each and every one individually is going to be hell to code. I'm fairly sure that in libevo.h the typedef is correct, and I've also tried it in the way you gave in the example.
It was just an example, and maybe you should get a new compiler if that way isn't working, because I'm pretty sure it's part of the C standard.
[QUOTE=ThePuska;35039550]A quadtree may or may not improve performance. If each cell of the 12.5x12.5 grid holds from zero to just a few particles, it's extremely optimal for what you're doing and there isn't much you can do anymore. It makes comparing each particle to its neighbors an approximately O(n) operation, instead of the naive O(n^2). The benefit of quadtrees is that they do not require a grid of such an optimal size - they improve the performance to O(n log n) regardless.[/QUOTE] I thought about using quadtrees, but I've heard that they are not good with moving objects.
What's the point of a quadtree if there aren't going to be moving objects? No, quadtrees are good when there's a lot of collisions.
[QUOTE=esalaka;35041436]That's not how you initialize a struct.[/QUOTE] It is in C99. [editline]8th March 2012[/editline] [url=gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html]Helpful Link[/url] [editline]8th March 2012[/editline] [code]population[1] = {.resistance = SICKRES, .ability = SWIMS .specialty = SPEED .strength = 15 .speed = 15}; [/code] This, however, isn't how you initialize a struct. You're missing some commas.
[QUOTE=WTF Nuke;35043177]What's the point of a quadtree if there aren't going to be moving objects? No, quadtrees are good when there's a lot of collisions.[/QUOTE] As far as I'm aware, you have to remake the entire tree every update as objects are constantly moving (fluids).
Well yes, you have to move objects through nodes, but what would the point of a quad tree be if nothing is moving (and thus there are no collisions).
I have a c# console app problem. I need to input 4 rows of 4 ints each, i.e [code] 1 4 7 2 2 0 1 8 0 1 7 2 1 9 2 3 [/code] and assign them to an array. I don't need to error check for non int types. C++ had easy ways to input values skipping whitespace. What's the equivalent?
[QUOTE=Foda;35043425]As far as I'm aware, you have to remake the entire tree every update as objects are constantly moving (fluids).[/QUOTE] Yes, but that's fine because it's still an O(n log n) operation. Here's how it works: Naive approach: O(n^2) Quadtree: O(n log n), even if you have to rebuild the whole tree from scratch every frame. Uniform grid (best case, if [i]all[/i] objects are ~gridsize): O(n) [i]But if objects are not roughly the same size as cells in a uniform grid (larger or smaller), then it quickly degenerates back into O(n^2).[/i] So, uniform grids give the best results in the optimal case and the worst results in the sub-optimal case. Because you're doing a simple particle simulation (with uniform size particles?) you can probably tweak it and make the uniform grid work out. However, quadtrees work well for the general case, where you can't make assumptions about the objects in your simulation. You might also use them if the particles are very small and the simulation area is very large, in which case you would probably need way too many cells to make a uniform grid work.
[QUOTE=DoctorSalt;35043785]I have a c# console app problem. I need to input 4 rows of 4 ints each, i.e [code] 1 4 7 2 2 0 1 8 0 1 7 2 1 9 2 3 [/code] and assign them to an array. I don't need to error check for non int types. C++ had easy ways to input values skipping whitespace. What's the equivalent?[/QUOTE] Try [URL="http://stackoverflow.com/questions/3881826/reading-two-integers-in-one-line-using-c-sharp"]t[/URL][URL="http://stackoverflow.com/questions/3881826/reading-two-integers-in-one-line-using-c-sharp"]his[/URL].
Dofile?
So is everyone in the programming world. Don't say stuff like that, it ends up discouraging yourself and you eventually will just give up thinking "Ugh I am dumb, I am the only one that makes these stupid mistakes", which anyone here can tell you is -certainly- not true Edit: Of course except Dajoh. He doesn't make mistakes. Ever.
[QUOTE=dajoh;35036672] So you would do this: [cpp] class Test { public: static DWORD WINAPI ThreadFn(LPVOID param) { Test *instance = (Test *)param; // instance is the "this" pointer. } }; Test instance; CreateThread(NULL, 0, Test::ThreadFn, &instance, 0, NULL); [/cpp][/QUOTE] How I deal with variables now? [cpp] class Test { public: int num; static DWORD WINAPI ThreadFn(LPVOID param) { Test *instance = (Test *)param; while(true) { Test.num++; } return 1; } }; [/cpp] Says: "a nonstatic member reference must be relative to a specific object" at num.
[QUOTE=rute;35050895]How I deal with variables now? [cpp] class Test { public: int num; static DWORD WINAPI ThreadFn(LPVOID param) { Test *instance = (Test *)param; while(true) { Test.num++; } return 1; } }; [/cpp] Says: "a nonstatic member reference must be relative to a specific object" at num.[/QUOTE] You can't use nonstatic members in a static method, you'll need to put it inside your method, or make it static if you need it outside.
[QUOTE=evil-tedoz;35045248]Try [URL="http://stackoverflow.com/questions/3881826/reading-two-integers-in-one-line-using-c-sharp"]t[/URL][URL="http://stackoverflow.com/questions/3881826/reading-two-integers-in-one-line-using-c-sharp"]his[/URL].[/QUOTE] Thanks much kind sir. Split is exactly what I'm looking for! Also, I already posted this in the WAYWO thread, but for you guys: [url]http://web.cs.wpi.edu/Resources/Contest/2012/[/url] It's a programming competition (already happened), which outlines the problems and gives an answer. I think it's a great way to get your act together. The guideline is to do them all in 4 hours.
Sorry, you need to Log In to post a reply to this thread.