what wrong is with these comparation?

Mar 27, 2022 at 6:25pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
do
    {
        for(int y=0; y<ConsoleHeight; y++)
        {
            for(int x=0, i=0; x<ConsoleWidth; x++)
            {

                if(i<GetLineDots.size() && GetLineDots[i].PosX == x &&  GetLineDots[i].PosY==y )
                {
                    PixelColors[y*ConsoleWidth + x] = RGB(0,255,0);
                    //MessageBox(NULL, "error", "error", MB_OK);
                    i++;
                }
                else
                {
                    PixelColors[y*ConsoleWidth + x] = RGB(0,0,255);
                }

            }
        }
        StretchDIBits(HDCConsoleWindow,0,0,ConsoleWidth, ConsoleHeight, 0,0, ConsoleWidth,ConsoleHeight, BufferMemory, &BitInfo,DIB_RGB_COLORS, SRCCOPY );
    }while(!GetAsyncKeyState(VK_ESCAPE));

the line 'PixelColors[y*ConsoleWidth + x] = RGB(0,0,255);' is done.
but see here:
' if(i<GetLineDots.size() && GetLineDots[i].PosX == x && GetLineDots[i].PosY==y )'
what is wrong with these comparation?
if i add a messagebox(), the message is showed... but the pixel isn't changed :(
so what i did wrong?
'GetLineDots' is a line pixels vetor... and the line was drawed and i get the line pixel count correctly.
Last edited on Mar 27, 2022 at 6:26pm
Mar 27, 2022 at 6:36pm
I don't see PixelColors used on line 21.
Mar 27, 2022 at 6:58pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
int main()
{
    void *BufferMemory;
    BITMAPINFO BitInfo;
    HWND HWNDConsoleWindow = GetConsoleWindow();
    HDC HDCConsoleWindow = GetDC(HWNDConsoleWindow);
    std::vector<Position3D> GetLineDots;
    Position3D Origin ={0,0,0};
    Position3D Destination ={100,100,0};

    Position3D RotOrigin ={0,0,0};
    Position3D RotDestination ={100,100,0};

    GetLineDots = GetLinePoints(Origin,Destination);
    Position3D Angle={0,0,0};
    Position3D RotatePoint={50,50,0};
    Position3D GetLineDotsRot;

    RECT rect;
    GetClientRect(HWNDConsoleWindow, &rect);
    int ConsoleWidth = rect.right - rect.left;
    int ConsoleHeight = rect.bottom - rect.top;


    BitInfo.bmiHeader.biSize = sizeof(BitInfo.bmiHeader);
    BitInfo.bmiHeader.biWidth = ConsoleWidth;
    BitInfo.bmiHeader.biHeight = -ConsoleHeight;
    BitInfo.bmiHeader.biPlanes = 1;
    BitInfo.bmiHeader.biBitCount = 32;
    BitInfo.bmiHeader.biCompression = BI_RGB;

    int BufferSize = ConsoleWidth * ConsoleHeight * sizeof(unsigned int);

    if(BufferMemory) VirtualFree(BufferMemory, 0,MEM_RELEASE);
    BufferMemory = VirtualAlloc(0, BufferSize,MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
    unsigned int *PixelColors = (unsigned int) BufferMemory;
    do
    {//.............. 
Mar 27, 2022 at 7:15pm
ok so buffer memory is pixel colors.
line 8 original post. what modifies i when it is false the first time? Maybe its not important, but its weird, esp with the if doing the same thing for both true and false (to debug it?)
Last edited on Mar 27, 2022 at 7:19pm
Mar 27, 2022 at 7:19pm
yes... for resolve the problem is did more 1 loop:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
do
    {
        //draw a background color:
        for(int y=0; y<ConsoleHeight; y++)
        {
            for(int x=0, i=0; x<ConsoleWidth; x++)
            {
                PixelColors[y*ConsoleWidth + x] = RGB(0,0,255);
            }
        }

        Angle.PosZ += 0.2;

        RotOrigin = RotationPoints(Origin,RotatePoint,Angle);
        RotDestination = RotationPoints(Destination,RotatePoint,Angle);
        GetLineDots = GetLinePoints(RotOrigin,RotDestination);
        
        // draw a line:
        for(int x=0; x<GetLineDots.size()-1; x++)
        {
            int Index=GetLineDots[x].PosY*ConsoleWidth + GetLineDots[x].PosX;
            if (Index<0 || (GetLineDots[x].PosY>=ConsoleHeight && GetLineDots[x].PosY<0 && GetLineDots[x].PosX>=ConsoleWidth && GetLineDots[x].PosY<0) ) continue;
            PixelColors[Index] = RGB(0,255,0);

        }
        // draw the pixels on console window:
        StretchDIBits(HDCConsoleWindow,0,0,ConsoleWidth, ConsoleHeight, 0,0, ConsoleWidth,ConsoleHeight, BufferMemory, &BitInfo,DIB_RGB_COLORS, SRCCOPY );
        Sleep(50);
    }while(!GetAsyncKeyState(VK_ESCAPE));

but i need ask: why that comparation' if(i<GetLineDots.size() && GetLineDots[i].PosX == x && GetLineDots[i].PosY==y ) PixelColors[y*ConsoleWidth + x] = RGB(0,255,0);' was not used or ignored?
Mar 27, 2022 at 7:24pm
I don't see it. check the results of line 21 and 22. if they zero out, nothing happens.
Mar 27, 2022 at 8:22pm
how can i test if 'x == GetLineDots[i].PosX && y ==GetLineDots[i].PosY'?
of course the i must be minus than GetLineDots.size().
i found 1 error: variable 'i' life was wrong:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
do
    {
        int i=0;
        for(int y=0; y<ConsoleHeight; y++)
        {
            for(int x=0; x<ConsoleWidth; x++)
            {

                if(i<GetLineDots.size() && x == GetLineDots[i].PosX &&  y ==GetLineDots[i].PosY )
                {
                    PixelColors[y*ConsoleWidth + x] = RGB(0,255,0);
                    //MessageBox(NULL, "error", "error", MB_OK);
                    i++;
                }
                else
                {
                    PixelColors[y*ConsoleWidth + x] = RGB(0,0,255);
                }

            }
        }
Mar 27, 2022 at 8:26pm
at least i win 3 pixels :P
https://imgur.com/B5JO5ff
the 'i' go to 3 and not 100 :(
Last edited on Mar 27, 2022 at 8:30pm
Mar 29, 2022 at 12:10am
> unsigned int *PixelColors = (unsigned int) BufferMemory;
I don't understand how you see that and are completely fine with it


you'll only render the line if it goes "down", i. e., if y1<y2
consider instead
1
2
3
4
5
6
clear()
//draw all you want
for i in [0, LineDots.size}
  x = lineDots.PosX
  y = lineDots.PosY
   screen.at(x, y) = green
Topic archived. No new replies allowed.