News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Pack one bit into byte or something like that, how?

Started by BytePtr, April 11, 2012, 11:08:31 PM

Previous topic - Next topic

qWord

Quote from: BytePtr on April 15, 2012, 06:30:11 PM
But each object has that ID number, so when reading coordinates, i also need this ID. Without packing stuff together, it seems to get too complicated.
but this would mean, that the color also depends on the ID, because the ID is placed in the upper bits of Z - make not much sense.
FPU in a trice: SmplMath
It's that simple!

dedndave

i am not sure that you need to explicitly store an "ID number"
doesn't the position in the array imply the ID ?
for example - you have coordinate sets with ID's numbering 0 to 4
if we place those 5 coordinates into an array, then we know the ID of each, based on it's position in the array

that could work out rather nicely
you could store bytes like so

X0 Y0 X1 Y1 X2 Y2 X3 Y3 X4 Y4 P1 P2

P1 and P2 contain the packed Z values
5 x 3 = 15 bits
12 bytes stores 5 coordinates

dedndave

not to mention what qWord said   :red
QuoteIn my app each object has color derived from X,Y,Z. So for ex: X0,Y0,Z0 are all RGB 0,0,0, so,
this object has coordinates of 0,0,0. If X1, Y0, Z0, then color of this object is RGB 1,0,0
that makes no sense
i mean - ok - we can do that, but we don't have to store the values
we can simply generate them based on location   :P

EDIT:
ok - i can see where that makes sense
you have an object plotted with points
if there is nothing there, there will be no point

BytePtr

Well okay, i have to reveal more about my project.


All the 3D objects i have are the CUBES. Each cube has a FACE ID: LEFT, RIGHT, TOP, BOTTOM, LID.
Each cube is drawn using colors derived from X,Y,Z, OpenGL assigns for each block a color glColor3ub(X,Y,Z);
Im using colors for picking these cubes in my OpenGL app.
This works perfectly. I can click on any cube and it shows it's location perfectly, even at X:255, Y:255, Z:7.

When i added packed FACE_ID+X_COORD: i used it like this: glColor3ub(PackedData, Y, Z);

If im gonna add something (pack) to X, the picking is messed up. X is limited to 31 and that's all. I still know what side user clicked but X coord gets limited. So will Y and probably Z, dunno.

It (X) starts from 0 again and goes up to 31 and again from 0, etc and so on.
When user clicks on any cube at any location of X,Y,Z, i need to also detect, on which side of cube user clicked: (0=LEFT, 1=RIGHT, 2=TOP, 3=BOTTOM, 4=LID).


I used jj2007 code to pack and unpack the FACE ID and X coordinate, believe it or not, it worked perfectly. I mean detecting face and coordinate, but only thing was limited X coord. Because i packed stuff into it.

Quotebut this would mean, that the color also depends on the ID, because the ID is placed in the upper bits of Z

Yeah i know, but for some reason it worked fine for X. Only problem i have atm. is that everything is limited to 31, after packing / unpacking.
Without packing, everything works, but i don't know which side user clicked.

So if the additional FACE_ID will fit into Z coord, then it should work fine. If Z is limited to 31, it's okay. Z can never go beyond 8 anyway. I will try to pack FACE_ID into Z.

EDIT I packed face_id into Z and it works perfectly now. If inside dark places in exe, it limits the Z to 31, i don't care.
X,Y are now as they are, Z can never go over 8, so im satisfied.

Thank you guys for all the help so far.


EDIT2
I know it's not OpenGL forum, but just a question, you can ignore it if you want. But..

How to allow user to choose background color and at the same time avoid conflicts between block colors and background colors?

For example i like black background color, better for eyes. But my block also can have (has) color value (0,0,0).
If user clicks on background, code "thinks" that user clicked on the cube at X0,Y0,Z0 and it get's modified, but it shouldn't.

One way i was thinking about is just limit the list of colors for background, from which user can choose one, but im not very sure about this one.

jj2007

Quote from: BytePtr on April 15, 2012, 08:15:21 PM
Z can never go beyond 8 anyway.

That was the missing info! So you can use e.g. 3 bits for the ID, 0...15 and 5 bits for Z, 0...63. Don't forget to mask out the ID before passing Z to OpenGL, e.g. with
mov eax, PackedZ
and eax, 63
invoke glColor3ub(X, Y, eax)

BytePtr

Thank you. Sorry for the missing info.
I also found a pretty fine solution for color conflicts with objects and background color.
It's again thanks to the fact that Z can't go beyond 8. Actually: 0..7.

I found this solution in 3 AM in the morning. But they say, don't code anything at this time of night  :bg

If background color RGB blue component is below 8, then just change it back to 8.
This way, it's still allowed to choose a lot of colors, but at the same time, it will not conflict with my object colors.
Because B value is always equal to 8 or higher than 8.
And i don't have any objects with colors: R255, G255, B > 7

dedndave

that's one way
another would be to change 1 bit
colors used to draw objects could always have odd values
colors used for backgrounds, insets, descriptive text, etc, could have even values
especially true for BLUE, the human eye can't detect the difference

the data can be stored with all bits - only displayed with that bit set or cleared, as required