-
April 4th, 2020, 09:55 AM
#1
how draw 3D just using the math?
from what i have learned from others forums and tutorials, i know convert from 3D(X, Y, Z) to 2D(X, Y):
Code:
x2D = (x * L) / (z + L)
y2D = (y * L) / (z + L)
the 'L' is the distance between the position object\dot and the player\camera.
Code:
class Console{
public:
HWND myconsole;
HDC mydc;
Console()
{
myconsole = GetConsoleWindow();
//Get a handle to device context
mydc = GetDC(myconsole);
}
~Console()
{
ReleaseDC(myconsole, mydc);
}
operator HDC()
{
return mydc;
}
operator HWND()
{
return myconsole;
}
RECT GetWindowSize()
{
RECT RectWindow;
GetWindowRect(myconsole,&RectWindow);
return RectWindow;
}
void Clear(COLORREF Color=RGB(0,0,0))
{
//Clear:
RECT RectWindow;
GetWindowRect(myconsole,&RectWindow);
RectWindow.top=0;
RectWindow.left=0;
FillRect(mydc,&RectWindow,CreateSolidBrush(Color));
}
}Console;
after knowing these i drawed a rectangle that scales when i move back and front:
Code:
//draw a rectangle HPEN hWhitePen = (HPEN)GetStockObject(WHITE_PEN);
HPEN hOldPen = (HPEN)SelectObject(Console, hWhitePen);
POINT points[5] =
{
{ (X * MeDistance) / (Z + MeDistance), (Y * MeDistance) / (Z + MeDistance) },
{ Width+X, (Y * MeDistance) / (Z + MeDistance) },
{ Width+X, Height+Y },
{ (X * MeDistance) / (Z + MeDistance), Height+Y },
{ (X * MeDistance) / (Z + MeDistance), (Y * MeDistance) / (Z + MeDistance) },
};
if(MeDistance-Z>=-1 && MeDistance-Z<=100)
{
HBRUSH hBrush1 = CreateSolidBrush(RGB(121, 90, 0));
HBRUSH holdBrush = (HBRUSH)SelectObject(Console, hBrush1);
Polygon(Console, points, 5);
SelectObject(Console, hOldPen);
SelectObject(Console, holdBrush );
DeleteObject(hBrush1);
DeleteObject(hWhitePen);
}
doing the same way, i tried draw the floor without success
Code:
//Position and Size Floor: int FloorX=0, FloorY=1000, FloorZ=0,FloorWidth=1000, FloorHeight=100, FloorZWidth=1000;
//floor vectors:
POINT FloorPoints[5] =
{
{ (FloorX * MeDistance) / (FloorZ + MeDistance), (FloorY * MeDistance) / (FloorZ + MeDistance) },
{ FloorWidth+FloorX, (FloorY * MeDistance) / (FloorZ + MeDistance) },
{ FloorWidth+FloorX, FloorHeight+FloorY },
{ (FloorX * MeDistance) / (FloorZ + MeDistance), FloorHeight+FloorY },
{ (FloorX * MeDistance) / (FloorZ + MeDistance), (FloorY * MeDistance) / (FloorZ + MeDistance) },
};
//floor color:
HBRUSH hBrush12 = CreateSolidBrush(RGB(0, 0, 255));
HBRUSH holdBrush2 = (HBRUSH)SelectObject(Console, hBrush12);
//draw the floor:
Polygon(Console, FloorPoints, 5);
SelectObject(Console, holdBrush2 );
DeleteObject(hBrush12);
i need to understand what i'm doing wrong for draw the floor... can anyone explain to me?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|