• Content count

  • Joined

  • Last visited

Community Reputation

106 Neutral

About BytePtr

  • Rank
  1. Saving data, according to list

    Seems that i solved this problem, thanks to "boost.any" [url=""][/url] [url=""][/url] [quote]But sometimes, very rarely, you actually want to store a whole bunch of messy, unrelated types in a container without trying to ram them into some sort of class hierarchy. [b]Parsers are a good example of this[/b].[/quote] Exactly my case! Parser & compiler. At parsing stage i just "push_back" my structs into custom vector: [CODE] using boost::any_cast; typedef std::vector< boost::any > AnyVector; AnyVector values; [/CODE] Later when saving, i just cast them back, get my values and save. [CODE] for ( std::vector< boost::any >::const_iterator p = parser->tab->values.begin(); p != parser->tab->values.end(); ++p ) { if ( p->type() == typeid(int) ) { cout << "ID: " << any_cast<int>(*p) << endl; } if ( p->type() == typeid(MY_STRUCT) ) { // .... fwrite(mystruct, ...); } } etc etc... [/CODE] Each struct is saved correctly with correct nr of them. Just tested and it works.
  2. Saving data, according to list

    I just loop through them, they are saved in specific order, same order as i use the "fwrite" in my CPP source. But how i would know in advance in what order the commands will be in the script source? Impossible. For ex: script [CODE] cls print "test 1" print "test 2" [/CODE] I have to write "cls" struct once, and then "print" twice. In same order. The order could be anything. Because its compiler. And user can write this in any order.
  3. Hi. Im working on my script compiler. All works fine, but at the saving part i got some problems. I need some ideas from other people. What i have is a list of ID's (identifications) of commands used in script. The list is built as the commands are parsed from script (i mean, the commands ID's are put in same order into list, as they are found in script). This is important. Almost each command has it's own struct which must be saved to compiled script in same order as they are found in source of script. ID's are just int's, for ex: "cls" = 5 "begin" = 20, "end" = 25, "print" = 30 etc. So for example i have script like: [CODE] begin cls print "hello" print "good bye" end [/CODE] As you see from example, print is used twice: so command id's list for this script will be like this: [CODE] 20 5 30 30 25 [/CODE] 5 commands. Each of these commands structs must be saved to file, in same order. The filling of structs is done earlier in parsing stage. What i have now is just a for_loop, that goes thru ID's, for ex: 0 to 4, in this loop i check what ID i have currently, with "switch" statement. In each "case" in "switch" i also loop through nr_of_current_command_id's", for example above, i need to loop 2 times, because i have 2 "print" commands. It kinda works but because of first loop, it writes data too many times. If i have 1 "print" command, it writes actually 2 of them. If i have 2 "print" commands, it writes 4 of them, etc. Not good. Any ideas how i could get rid of the main loop? Im heavily using std::vector and std::map and iterators, because they are so good and neat. I thought about something with std::map and go through it and if i find specific ID, i will save it. But what about order of saving? Im completely lost here. I hope somebody understands my problem. TIA for any help.
  4. Need help with rewriting loop

    Thanks, that was it. Works fine now. I don't know how i missed that little thing. EDIT: i probably shouldn't code at 4 AM, without sleeping.
  5. Hi. I got a bit strange problem. Im using OpenGL and raypicking. But this problem has more coding problem than OpenGL problem. I have a loop (3D): [source lang="cpp"] int c = 0; for (int x = 0; x < maxx; x++) { for (int y = 0; y < maxy; y++) { for (int z = 0; z < maxz; z++) { obj[c].Shift(new Vec3(x, y, z)); c++; } } }[/source] In this loop vertices of objects are shifted according to their positions on the map. maxx, maxy, maxz are int values. For example: maxx=3; maxy=3; maxz=3; If they all are equal, like above, then i get fine results and picking works. As soon as at least one of them is different (bigger or smaller), the picking fails to return correct coords (X,Y,Z). In my case, maxx, maxy, maxz, never can be equal. MaxX is maximum 255 MaxY is maximum 255 MaxZ is maximum 7 But in that case, code fails to do picking. If im correct, the problem is in this 3D for loop. Because if i manually assign coords to objects, the it always works. Even with different maxx, maxy and maxz. The output of looping is like this: [code]X: 0 Y: 0 Z: 0 X: 0 Y: 0 Z: 1 X: 0 Y: 0 Z: 2 X: 0 Y: 1 Z: 0 X: 0 Y: 1 Z: 1 X: 0 Y: 1 Z: 2 X: 0 Y: 2 Z: 0 X: 0 Y: 2 Z: 1 X: 0 Y: 2 Z: 2 X: 1 Y: 0 Z: 0 X: 1 Y: 0 Z: 1 X: 1 Y: 0 Z: 2 X: 1 Y: 1 Z: 0 X: 1 Y: 1 Z: 1 X: 1 Y: 1 Z: 2 X: 1 Y: 2 Z: 0 X: 1 Y: 2 Z: 1 X: 1 Y: 2 Z: 2 X: 2 Y: 0 Z: 0 X: 2 Y: 0 Z: 1 X: 2 Y: 0 Z: 2 X: 2 Y: 1 Z: 0 X: 2 Y: 1 Z: 1 X: 2 Y: 1 Z: 2 X: 2 Y: 2 Z: 0 X: 2 Y: 2 Z: 1 X: 2 Y: 2 Z: 2[/code] Im not even sure, if somebody understands this and can help me, but it's pretty strange problem here. Manually it works, but with this loop, it doesn't. I will try once more manually, and will try to post differences, but in meanthime i would be thankful to get any help on this. EDIT: ok my manual values: [code]0, 0, 0 0, 1, 0 0, 2, 0 0, 0, 1 0, 0, 2[/code]
  6. OK as usually after posting topic, i got this to work but not fully. Because for each cube the X,Y,Z coords change, i need to somehow calculate the bounds using also the X,Y,Z coords. Relative to to block coords or something, but i don't know the math behind it. If for example: X=4, Y=3, Z=6, how i should calculate bounds for it? Block size is 1x1x1 (100x100x100) pixels always. For X0,Y0,Z0 i got really bounds like: 0-1 (float values from gluUnproject, without casting them to int's). But for coords like X1, Y1, Z1 it will no longer work. Should i multiply X,Y,Z with 1 or something? Or subtract something? I just don't know.
  7. Hello. I found interesting method about detecting on which side of cube user clicked: [url=""][/url] But i don't understand it fully. Also i don't get it, to which corner (?) for example (100,0,0) or (0,0,100) belongs. If somebody understands it, what he said or how are the bounds calculated, then please explain. I have same cube size 1x1x1. But im in OpenGL, not XNA, if that matters. I would like to try out this but i don't understand it. A pic would help also. Thanks in advance.
  8. OK, another idea i was thinking about is as follows: Z can only holds values from 0 to 7. So if i do simple logic like: [code]if(R<=255 & G<=255 & B >7) { // Ignore All Three Color Values Read // Because They Are Background Color Values. }[/code] So basically do not allow user to choose color, which B (blue) is less than or equal to 7. I think it will work and still it is possible to use a lot more colors than some very limited amount of colors for background. But somebody's other thoughts on this will also help me.
  9. I actually looked for another SwapBuffers(), and haven't found it. Something is really wrong in my code. Well it works but anyway, i also think that it shouldn't flicker. I will take a look what's up with my pixelformat. EDIT: yes, pixelfmt has the PFD_DOUBLEBUFFER included. Dunno what is wrong with it. I will make some small test app. Something is very wrong there. I will use your last pseudo code.
  10. Servant: Yes structure is same: My snippet in rendering loop: [code] DrawStuff(mode); if (mode == SELECT) { ProcessPick(); mode = RENDER; } else SwapBuffers(ghDC);[/code] So it's a bad way if i want to allow custom background colors? And i should use really 2 buffers? I used two glClearColors, once in place where i disabled some gl stuff (texturing etc) with white color. And second in place where i enabled gl stuff (texturing etc) with my fav. bgcolor. And result was like very ugly flickering of white and my fav. bg color. Picking worked, but there was that very ugly flickering. Exactly when i clicked, the flickering occurred.
  11. Simon. Could you post some pseudo code. Will this slow things down? Servant of the Lord Yes, im using "background" buffer for colored objects, im not flipping it. User doesn't see it. But why is my code picking the background color then? I specified background color with glClearColor(0.0f, 155.0/255.0, 102.0/255.0, 1.0f); for example and my picking code also picks it up. My bug somewhere? Should i use 2 different glClearColor()'s each time? For first and second buffer?
  12. Im using glColor3ub's and all my object colors are derived from X,Y,Z, It can be maximum 255,255,7. So i could set bgcolor to 255, 255, 8, but it's white, it will kill eyes. And it's very limited this way. Of course not all of my objects are drawn at once, but it's just the way my picking works. I already killed almost 3 months on finding good and fast picking for my app and only that worked was glColor3ub and glReadPixels. I don't want to kill this again. Im tired of messing and searching with/for picking code. Is it really impossible to ignore bgcolor? I tried once glDepthMask for specific thing, and it ignored what i didn't need to detect. But im not sure, if it will work on color.
  13. Hi. To make it short. Im using opengl color picking. Im drawing my 3D objects using unique colors and picking them using glreadpixels. My app also can have custom background color. Atm it has conflicts with object colors. When user clicks on background color which is black for example: glClearColor(0,0,0, 1.0) then code "thinks" that user clicked on object at the same coordinate (X0,Y0,Z0). But actually he clicked on background. Which has same color with object. So my question is: is it possible to make OpenGL to ignore background color? I mean color what is used for glClearColor()? Will the glDepthMask(true/false) help me on this one?
  14. I have a DidgiBen programming Lessons source of simple line -> polygon collision code: The source contains lines like this: [list=1] [*] // This is our line that we will be checking against the polygon's plane for collision. [*] // We position the line going directly through the polygon at first. [*] CVector3 vLine[2] = { {0, 0.5f, -0.5f}, {0, 0.5f, 0.5f} }; [/list] vLine is used like ray, to shoot through polygon / triangle / quad. It works fine. Now, my question is: is it possible and how to make this code to use ray from gluUnproject? Instead of hardcoded vLine? Will this be very hard? What modifications i must make?
  15. Need some help making The Snake Game

    You need to watch this: [url=""][/url] And other videos in the series. His tutorials are awesome and the code actually compiles, unlike the other peoples tutorials. It's for Linux but it's easily convertible to WIN32, it shows how to do the snake game. And actually it doesn't matter: Linux or Win or Console or not. It shows the core, that makes snake to move and eat food.Gfx is yours to do.