Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 09 Jun 2005
Offline Last Active Nov 03 2012 03:02 PM

Topics I've Started

Saving data, according to list

03 November 2012 - 03:03 AM


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:
print "hello"
print "good bye"

As you see from example, print is used twice: so command id's list for this script will be like this:

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.

Need help with rewriting loop

18 August 2012 - 03:25 PM


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:


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:
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

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:
0, 0, 0
0, 1, 0
0, 2, 0
0, 0, 1
0, 0, 2

Finding bounds of a square on the cube or something like that

01 August 2012 - 04:18 PM

I found interesting method about detecting on which side of cube user clicked:

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.

Ignore background color when using glReadPixels?

15 April 2012 - 03:01 PM


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?

Ray / Polygon Collision from DigiBen

14 January 2012 - 07:56 AM

I have a DidgiBen programming Lessons source of simple line -> polygon collision code:


The source contains lines like this:

  • // 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} };

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?