Week10 [30/11] - [06/12]
Added active Variable to the Lights Classes Added updated MD2Loader Class Added Model Filename and Texture File Name to the Model Class Added Active Flag to the Model Class Added DrawMode to the Model Class Added Texture and UV Variables to the Model Class Added UV Coordinates to the Polygon3D Class Added DrawString method to the Rasterizer to write text to the screen space Added Interpolate and Lerp Methods to the Rasterizer Added Select statement for drawing a current models draw mode Added DrawTextured Method to the Rasterizer Class Added UVCoord Class Added Texture Class Added = operator to the Vector3D Class Added UVCoord to the Vertex Class Moved Models and Texture Files into a subfolder Fixed issue with textures not loading properly because of the vector address problem
This commit is contained in:
645
Rasteriser.cpp
645
Rasteriser.cpp
@ -2,23 +2,60 @@
|
||||
|
||||
Rasteriser app;
|
||||
|
||||
Rasteriser::~Rasteriser()
|
||||
{
|
||||
_lights.~vector();
|
||||
_sceneModels.~vector();
|
||||
}
|
||||
|
||||
void Rasteriser::DrawString(HDC hDc, int x, int y, LPCTSTR text, COLORREF textColor, COLORREF backgroundColor)
|
||||
{
|
||||
HFONT hFont, hOldFont;
|
||||
|
||||
// Retrieve a handle to the variable stock font.
|
||||
hFont = hFont = CreateFont(48, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
|
||||
CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Myfont"));
|
||||
|
||||
// Select the variable stock font into the specified device context.
|
||||
if (hOldFont = (HFONT)SelectObject(hDc, hFont))
|
||||
{
|
||||
SetTextColor(hDc, textColor);
|
||||
SetBkColor(hDc, backgroundColor);
|
||||
|
||||
// Display the text string.
|
||||
TextOut(hDc, x, y, text, lstrlen(text));
|
||||
|
||||
// Restore the original font.
|
||||
SelectObject(hDc, hOldFont);
|
||||
}
|
||||
DeleteObject(hFont);
|
||||
}
|
||||
|
||||
bool Rasteriser::Initialise()
|
||||
{
|
||||
Model modelA;
|
||||
if (MD2Loader::LoadModel(".\\marvin.MD2", modelA, &Model::AddPolygon, &Model::AddVertex))
|
||||
Model modelA = Model(_modelDataLocation + "cube.MD2", _modelDataLocation + "lines.pcx");
|
||||
// Changed to adding the model to the vector first because doing it once the model has been loaded
|
||||
// caused the texture pointers to be at incorrect addresses.............
|
||||
_sceneModels.push_back(modelA);
|
||||
|
||||
for (Model& currentModel : _sceneModels)
|
||||
{
|
||||
_sceneModels.push_back(modelA);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (MD2Loader::LoadModel(currentModel.CGetModelFilename(), currentModel.CGetTextureFilename(), currentModel, &Model::AddPolygon, &Model::AddVertex, &Model::AddTextureUV))
|
||||
{
|
||||
currentModel.SetDrawMethod(DrawMethod::Textured);
|
||||
currentModel.SetActive(true);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
_lights.push_back(new AmbientLight(150, 150, 150));
|
||||
//_lights.push_back(new AmbientLight(255, 255, 255));
|
||||
_lights.push_back(new DirectionalLight(Vector3D(-1, 0, -1), 150, 150, 150));
|
||||
//_lights.push_back(new PointLight(Vertex(-10, 0, 10), 0, 1, 0, 100, 0, 0));
|
||||
//_lights.push_back(new AmbientLight(50, 50, 50));
|
||||
_lights.push_back(new AmbientLight(255, 255, 255));
|
||||
//_lights.push_back(new DirectionalLight(Vector3D(-1, 0, 0), 150, 150, 150));
|
||||
_lights.push_back(new PointLight(Vertex(0, 0, -10), 0, 1, 0.01f, 150, 0, 0));
|
||||
_cameras.push_back(Camera(0.0f, 0.0f, 0.0f, Vertex(0.0f, 0.0f, -50.0f)));
|
||||
|
||||
_screenMinimized = false;
|
||||
@ -58,7 +95,10 @@ void Rasteriser::CalculateLighting(Model& currentModel, bool fullLightRender)
|
||||
COLORREF colorWorking = RGB(0, 0, 0);
|
||||
for (Light* currentLight : _lights)
|
||||
{
|
||||
colorWorking = currentLight->CalculateLight(currentModel, currentModel.GetVertex(pi, i), colorWorking);
|
||||
if (currentLight->GetLightActive())
|
||||
{
|
||||
colorWorking = currentLight->CalculateLight(currentModel, currentModel.GetVertex(pi, i), colorWorking);
|
||||
}
|
||||
}
|
||||
currentModel.SetVertexColor(pi, i, colorWorking);
|
||||
}
|
||||
@ -68,7 +108,10 @@ void Rasteriser::CalculateLighting(Model& currentModel, bool fullLightRender)
|
||||
COLORREF colorWorking = RGB(0, 0, 0);
|
||||
for (Light* currentLight : _lights)
|
||||
{
|
||||
colorWorking = currentLight->CalculateLight(currentModel, currentModel.GetPolygon(pi), colorWorking);
|
||||
if (currentLight->GetLightActive())
|
||||
{
|
||||
colorWorking = currentLight->CalculateLight(currentModel, currentModel.GetPolygon(pi), colorWorking);
|
||||
}
|
||||
}
|
||||
currentModel.SetPolygonColor(pi, colorWorking);
|
||||
}
|
||||
@ -77,6 +120,26 @@ void Rasteriser::CalculateLighting(Model& currentModel, bool fullLightRender)
|
||||
}
|
||||
}
|
||||
|
||||
float Rasteriser::Interpolate(float y, float x0, float x1, float y0, float y1)
|
||||
{
|
||||
return x0 + (y - y0) * ((x1 - x0) / (y1 - y0));
|
||||
}
|
||||
|
||||
float Rasteriser::Interpolate(int y, int x0, int x1, int y0, int y1)
|
||||
{
|
||||
return Interpolate((float)y, (float)x0, (float)x1, (float)y0, (float)y1);
|
||||
}
|
||||
|
||||
float Rasteriser::Lerp(float a, float b, float t)
|
||||
{
|
||||
return a + (b - a) * t;
|
||||
}
|
||||
|
||||
float Rasteriser::Lerp(int a, int b, float t)
|
||||
{
|
||||
return Lerp((float)a, (float)b, t);
|
||||
}
|
||||
|
||||
void Rasteriser::Update(const Bitmap& bitmap)
|
||||
{
|
||||
if (bitmap.GetWidth() == 0 || bitmap.GetHeight() == 0)
|
||||
@ -97,19 +160,22 @@ void Rasteriser::Update(const Bitmap& bitmap)
|
||||
|
||||
for (Model& currentModel : _sceneModels)
|
||||
{
|
||||
currentModel.EnqueueTransform(GetTranslateMatrix(startPos));
|
||||
currentModel.EnqueueTransform(GetRotationMatrix(Axis::Y, (float)currentRot));
|
||||
//startPos.SetX(startPos.GetX() + 100);
|
||||
if ((currentModelIndex % 2) == 1)
|
||||
if (currentModel.GetActive())
|
||||
{
|
||||
currentZOff = 0;
|
||||
currentModel.EnqueueTransform(GetTranslateMatrix(startPos));
|
||||
currentModel.EnqueueTransform(GetRotationMatrix(Axis::Y, (float)currentRot));
|
||||
/*startPos.SetX(startPos.GetX() + 100);
|
||||
if ((currentModelIndex % 2) == 1)
|
||||
{
|
||||
currentZOff = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentZOff = 100;
|
||||
}
|
||||
startPos.SetZ((float)currentZOff);*/
|
||||
currentModelIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentZOff = 100;
|
||||
}
|
||||
//startPos.SetZ((float)currentZOff);
|
||||
currentModelIndex++;
|
||||
}
|
||||
|
||||
_currentAspectRatio = (float)(bitmap.GetWidth() / (float)bitmap.GetHeight());
|
||||
@ -137,31 +203,70 @@ void Rasteriser::Render(const Bitmap& bitmap)
|
||||
|
||||
for (Model& currentModel : _sceneModels)
|
||||
{
|
||||
currentModel.SetReflectionCoefficient(0.5f, 0.5f, 0.5f);
|
||||
Matrix workingMatrix = workingMatrix.IdentityMatrix();
|
||||
for (Matrix currentTransform : currentModel.GetPendingTransforms())
|
||||
if (currentModel.GetActive())
|
||||
{
|
||||
workingMatrix *= currentTransform;
|
||||
currentModel.SetReflectionCoefficient(0.5f, 0.5f, 0.5f);
|
||||
Matrix workingMatrix = workingMatrix.IdentityMatrix();
|
||||
for (Matrix currentTransform : currentModel.GetPendingTransforms())
|
||||
{
|
||||
workingMatrix *= currentTransform;
|
||||
}
|
||||
currentModel.ApplyTransformToLocalVertices(workingMatrix);
|
||||
currentModel.ApplyTransformToTransformedVertices(GetCurrentCamera().GetCurrentCameraTransformMatrix());
|
||||
|
||||
currentModel.CalculateBackfaces(GetCurrentCamera());
|
||||
currentModel.Sort();
|
||||
|
||||
switch (currentModel.GetDrawMethod())
|
||||
{
|
||||
case (DrawMethod::Wireframe):
|
||||
currentModel.ApplyTransformToTransformedVertices(_currentPerspectiveMatrix);
|
||||
currentModel.DehomogenizeAllVertices();
|
||||
currentModel.ApplyTransformToTransformedVertices(_currentViewMatrix);
|
||||
DrawWireFrame(bitmap.GetDC(), currentModel);
|
||||
break;
|
||||
case (DrawMethod::Flat):
|
||||
currentModel.CalculateVertexNormals();
|
||||
CalculateLighting(currentModel, false);
|
||||
|
||||
currentModel.ApplyTransformToTransformedVertices(_currentPerspectiveMatrix);
|
||||
currentModel.DehomogenizeAllVertices();
|
||||
currentModel.ApplyTransformToTransformedVertices(_currentViewMatrix);
|
||||
DrawSolidFlat(bitmap.GetDC(), currentModel);
|
||||
break;
|
||||
case (DrawMethod::FlatRaster):
|
||||
currentModel.CalculateVertexNormals();
|
||||
CalculateLighting(currentModel, false);
|
||||
|
||||
currentModel.ApplyTransformToTransformedVertices(_currentPerspectiveMatrix);
|
||||
currentModel.DehomogenizeAllVertices();
|
||||
currentModel.ApplyTransformToTransformedVertices(_currentViewMatrix);
|
||||
DrawRasterisedSolidFlat(bitmap.GetDC(), currentModel);
|
||||
break;
|
||||
case (DrawMethod::Smooth):
|
||||
currentModel.CalculateVertexNormals();
|
||||
CalculateLighting(currentModel, true);
|
||||
|
||||
currentModel.ApplyTransformToTransformedVertices(_currentPerspectiveMatrix);
|
||||
currentModel.DehomogenizeAllVertices();
|
||||
currentModel.ApplyTransformToTransformedVertices(_currentViewMatrix);
|
||||
DrawGouraud(bitmap.GetDC(), currentModel);
|
||||
break;
|
||||
case (DrawMethod::Textured):
|
||||
currentModel.CalculateVertexNormals();
|
||||
CalculateLighting(currentModel, true);
|
||||
|
||||
currentModel.ApplyTransformToTransformedVertices(_currentPerspectiveMatrix);
|
||||
currentModel.DehomogenizeAllVertices();
|
||||
currentModel.ApplyTransformToTransformedVertices(_currentViewMatrix);
|
||||
DrawSolidTextured(bitmap.GetDC(), currentModel);
|
||||
break;
|
||||
}
|
||||
currentModel.ClearPendingTransforms();
|
||||
}
|
||||
currentModel.ApplyTransformToLocalVertices(workingMatrix);
|
||||
currentModel.ApplyTransformToTransformedVertices(GetCurrentCamera().GetCurrentCameraTransformMatrix());
|
||||
|
||||
currentModel.CalculateBackfaces(GetCurrentCamera());
|
||||
currentModel.Sort();
|
||||
|
||||
currentModel.CalculateVertexNormals();
|
||||
CalculateLighting(currentModel, true);
|
||||
|
||||
currentModel.ApplyTransformToTransformedVertices(_currentPerspectiveMatrix);
|
||||
currentModel.DehomogenizeAllVertices();
|
||||
currentModel.ApplyTransformToTransformedVertices(_currentViewMatrix);
|
||||
|
||||
//DrawWireFrame(bitmap.GetDC(), currentModel);
|
||||
//DrawSolidFlat(bitmap.GetDC(), currentModel);
|
||||
//DrawRasterisedSolidFlat(bitmap.GetDC(), currentModel);
|
||||
DrawGouraud(bitmap.GetDC(), currentModel);
|
||||
currentModel.ClearPendingTransforms();
|
||||
}
|
||||
|
||||
DrawString(bitmap.GetDC(), 10, 10, _T("Hello World"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,8 +284,8 @@ void Rasteriser::DrawSquare(HDC hDc, const vector<Vertex> verticies)
|
||||
pointArray[i].y = (long) verticies[i].GetY();
|
||||
}
|
||||
|
||||
SetDCBrushColor(hDc, RGB(255, 0, 255));
|
||||
SetDCPenColor(hDc, RGB(0, 0, 255));
|
||||
SetDCBrushColor(hDc, RGB(rand() % 256, rand() % 256, rand() % 256));
|
||||
SetDCPenColor(hDc, RGB(rand() % 256, rand() % 256, rand() % 256));
|
||||
Polygon(hDc, pointArray, 4);
|
||||
}
|
||||
|
||||
@ -225,6 +330,8 @@ void Rasteriser::DrawWireFrame(HDC hDc, Model& model)
|
||||
}
|
||||
}
|
||||
|
||||
SetDCBrushColor(hDc, RGB(1,1,1));
|
||||
SetDCPenColor(hDc, RGB(255,255,255));
|
||||
PolyPolygon(hDc, pointArray.data(), sizeArray.data(), unculledPolyCount);
|
||||
}
|
||||
|
||||
@ -280,6 +387,20 @@ void Rasteriser::DrawGouraud(HDC hDc, Model& model)
|
||||
}
|
||||
}
|
||||
|
||||
void Rasteriser::DrawSolidTextured(HDC hDc, Model& model)
|
||||
{
|
||||
int modelPolygonCount = (int)model.GetPolygonCount();
|
||||
for (int i = 0; i < modelPolygonCount; i++)
|
||||
{
|
||||
|
||||
if (!model.GetPolygon(i).GetCulled())
|
||||
{
|
||||
vector<Vertex> vertexArray = model.GetPolygonVertexArray(i);
|
||||
FillPolygonTextured(hDc, model, vertexArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool VerticiesYCompareAsc(Vertex& v1, Vertex& v2)
|
||||
{
|
||||
return v1.GetY() < v2.GetY();
|
||||
@ -326,11 +447,11 @@ void Rasteriser::FillFlatSideTriangle(HDC hDc, const Vertex& v1, const Vertex& v
|
||||
int dx2 = (int)ceil(abs(v3.GetX() - v1.GetX()));
|
||||
int dy2 = (int)ceil(abs(v3.GetY() - v1.GetY()));
|
||||
|
||||
int signx1 = (int)sgn(v2.GetX() - v1.GetX());
|
||||
int signx2 = (int)sgn(v3.GetX() - v1.GetX());
|
||||
int signx1 = (int)ceil(sgn(v2.GetX() - v1.GetX()));
|
||||
int signx2 = (int)ceil(sgn(v3.GetX() - v1.GetX()));
|
||||
|
||||
int signy1 = (int)sgn(v2.GetY() - v1.GetY());
|
||||
int signy2 = (int)sgn(v3.GetY() - v1.GetY());
|
||||
int signy1 = (int)ceil(sgn(v2.GetY() - v1.GetY()));
|
||||
int signy2 = (int)ceil(sgn(v3.GetY() - v1.GetY()));
|
||||
|
||||
if (dy1 > dx1)
|
||||
{
|
||||
@ -353,72 +474,73 @@ void Rasteriser::FillFlatSideTriangle(HDC hDc, const Vertex& v1, const Vertex& v
|
||||
|
||||
for (int i = 0; i <= dx1; i++)
|
||||
{
|
||||
int startPoint;
|
||||
int endPoint;
|
||||
float leftEndPoint;
|
||||
float rightEndPoint;
|
||||
|
||||
if (tempA.GetXInt() < tempB.GetXInt())
|
||||
if (tempA.GetX() < tempB.GetX())
|
||||
{
|
||||
startPoint = tempA.GetXInt();
|
||||
endPoint = tempB.GetXInt();
|
||||
leftEndPoint = tempA.GetX() - 1.0f;
|
||||
rightEndPoint = tempB.GetX() + 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
startPoint = tempB.GetXInt();
|
||||
endPoint = tempA.GetXInt();
|
||||
leftEndPoint = tempB.GetX() - 1.0f;
|
||||
rightEndPoint = tempA.GetX() + 1.0f;
|
||||
}
|
||||
|
||||
for (int xi = (int)ceil(startPoint); xi <= endPoint; xi++)
|
||||
for (int xi = (int)ceil(leftEndPoint); xi <= (int)ceil(rightEndPoint); xi++)
|
||||
{
|
||||
SetPixel(hDc, xi, tempA.GetYInt(), colorIn);
|
||||
}
|
||||
|
||||
|
||||
|
||||
while (e1 >= 0)
|
||||
{
|
||||
if (changed1)
|
||||
{
|
||||
tempA.SetX(tempA.GetX() + signx1);
|
||||
tempA.SetX((float)tempA.GetX() + (float)signx1);
|
||||
}
|
||||
else
|
||||
{
|
||||
tempA.SetY(tempA.GetY() + signy1);
|
||||
tempA.SetY((float)tempA.GetY() + (float)signy1);
|
||||
}
|
||||
e1 = e1 - 2 * dx1;
|
||||
}
|
||||
|
||||
if (changed1)
|
||||
{
|
||||
tempA.SetY(tempA.GetY() + signy1);
|
||||
tempA.SetY((float)tempA.GetY() + (float)signy1);
|
||||
}
|
||||
else
|
||||
{
|
||||
tempA.SetX(tempA.GetX() + signx1);
|
||||
tempA.SetX((float)tempA.GetX() + (float)signx1);
|
||||
}
|
||||
|
||||
e1 = e1 + 2 * dy1;
|
||||
|
||||
while (tempB.GetY() != tempA.GetY())
|
||||
while (tempB.GetYInt() != tempA.GetYInt())
|
||||
{
|
||||
while (e2 >= 0)
|
||||
{
|
||||
if (changed2)
|
||||
{
|
||||
tempB.SetX(tempB.GetX() + signx2);
|
||||
tempB.SetX((float)tempB.GetXInt() + (float)signx2);
|
||||
}
|
||||
else
|
||||
{
|
||||
tempB.SetY(tempB.GetY() + signy2);
|
||||
tempB.SetY((float)tempB.GetYInt() + (float)signy2);
|
||||
}
|
||||
e2 = e2 - 2 * dx2;
|
||||
}
|
||||
|
||||
if (changed2)
|
||||
{
|
||||
tempB.SetY(tempB.GetY() + signy2);
|
||||
tempB.SetY((float)tempB.GetYInt() + (float)signy2);
|
||||
}
|
||||
else
|
||||
{
|
||||
tempB.SetX(tempB.GetX() + signx2);
|
||||
tempB.SetX((float)tempB.GetXInt() + (float)signx2);
|
||||
}
|
||||
e2 = e2 + 2 * dy2;
|
||||
}
|
||||
@ -426,112 +548,6 @@ void Rasteriser::FillFlatSideTriangle(HDC hDc, const Vertex& v1, const Vertex& v
|
||||
}
|
||||
|
||||
void Rasteriser::FillPolygonGouraud(HDC hDc, vector<Vertex>& verts)
|
||||
{
|
||||
sort(verts.begin(), verts.end(), VerticiesYCompareAsc);
|
||||
if (verts[1].GetY() == verts[2].GetY())
|
||||
{
|
||||
FillGouraudBottomFlatTriangle(hDc, verts[0], verts[1], verts[2]);
|
||||
}
|
||||
else if (verts[0].GetY() == verts[1].GetY())
|
||||
{
|
||||
FillGouraudTopFlatTriangle(hDc, verts[0], verts[1], verts[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vertex temp = Vertex(verts[0].GetX() + ((verts[1].GetY() - verts[0].GetY()) / (verts[2].GetY() - verts[0].GetY())) * (verts[2].GetX() - verts[0].GetX()), verts[1].GetY(), verts[1].GetZ());
|
||||
temp.SetNormal(verts[1].GetNormal());
|
||||
|
||||
float cRed = GetRValue(verts[0].GetColor()) + ((verts[1].GetY() - verts[0].GetY()) / (verts[2].GetY() - verts[0].GetY())) * (GetRValue(verts[2].GetColor()) - GetRValue(verts[0].GetColor()));
|
||||
float cGreen = GetGValue(verts[0].GetColor()) + ((verts[1].GetY() - verts[0].GetY()) / (verts[2].GetY() - verts[0].GetY())) * (GetGValue(verts[2].GetColor()) - GetGValue(verts[0].GetColor()));
|
||||
float cBlue = GetBValue(verts[0].GetColor()) + ((verts[1].GetY() - verts[0].GetY()) / (verts[2].GetY() - verts[0].GetY())) * (GetBValue(verts[2].GetColor()) - GetBValue(verts[0].GetColor()));
|
||||
temp.SetColor(RGB((int)cRed, (int)cGreen, (int)cBlue));
|
||||
|
||||
temp.SetColor(verts[1].GetColor());
|
||||
|
||||
FillGouraudBottomFlatTriangle(hDc, verts[0], verts[1], temp);
|
||||
FillGouraudTopFlatTriangle(hDc, verts[1], temp, verts[2]);
|
||||
}
|
||||
}
|
||||
|
||||
void Rasteriser::FillGouraudBottomFlatTriangle(HDC hDc, const Vertex& v1, const Vertex& v2, const Vertex& v3)
|
||||
{
|
||||
float slope1 = (float)(v2.GetX() - v1.GetX()) / (float)(v2.GetY() - v1.GetY());
|
||||
float slope2 = (float)(v3.GetX() - v1.GetX()) / (float)(v3.GetY() - v1.GetY());
|
||||
|
||||
float x1 = (float)v1.GetX();
|
||||
float x2 = (float)v1.GetX() + 0.5f;
|
||||
|
||||
if (slope2 < slope1)
|
||||
{
|
||||
float slopeTmp = slope1;
|
||||
slope1 = slope2;
|
||||
slope2 = slopeTmp;
|
||||
}
|
||||
|
||||
for (int scanlineY = (int)v1.GetY(); scanlineY <= (int)v2.GetY(); scanlineY++)
|
||||
{
|
||||
float iRedA = (scanlineY - v2.GetY()) / (v1.GetY() - v2.GetY()) * v1.GetR() + (v1.GetY() - scanlineY) / (v1.GetY() - v2.GetY()) * v2.GetR();
|
||||
float iRedB = (scanlineY - v3.GetY()) / (v1.GetY() - v3.GetY()) * v1.GetR() + (v1.GetY() - scanlineY) / (v1.GetY() - v3.GetY()) * v3.GetR();
|
||||
float iGreenA = (scanlineY - v2.GetY()) / (v1.GetY() - v2.GetY()) * v1.GetG() + (v1.GetY() - scanlineY) / (v1.GetY() - v2.GetY()) * v2.GetG();
|
||||
float iGreenB = (scanlineY - v3.GetY()) / (v1.GetY() - v3.GetY()) * v1.GetG() + (v1.GetY() - scanlineY) / (v1.GetY() - v3.GetY()) * v3.GetG();
|
||||
float iBlueA = (scanlineY - v2.GetY()) / (v1.GetY() - v2.GetY()) * v1.GetB() + (v1.GetY() - scanlineY) / (v1.GetY() - v2.GetY()) * v2.GetB();
|
||||
float iBlueB = (scanlineY - v3.GetY()) / (v1.GetY() - v3.GetY()) * v1.GetB() + (v1.GetY() - scanlineY) / (v1.GetY() - v3.GetY()) * v3.GetB();
|
||||
|
||||
for (int xi = (int)ceil(x1); xi < (int)x2; xi++)
|
||||
{
|
||||
float redTmp = (x2 - xi) / (x2 - x1) * iRedA + (xi - x1) / (x2 - x1) * iRedB;
|
||||
float greenTmp = (x2 - xi) / (x2 - x1) * iGreenA + (xi - x1) / (x2 - x1) * iGreenB;
|
||||
float blueTmp = (x2 - xi) / (x2 - x1) * iBlueA + (xi - x1) / (x2 - x1) * iBlueB;
|
||||
|
||||
COLORREF currentColor = RGB(BoundsCheck(0, 255, (int)redTmp), BoundsCheck(0, 255, (int)greenTmp), BoundsCheck(0, 255, (int)blueTmp));
|
||||
SetPixel(hDc, xi, scanlineY, currentColor);
|
||||
}
|
||||
|
||||
x1 += slope1;
|
||||
x2 += slope2;
|
||||
}
|
||||
}
|
||||
|
||||
void Rasteriser::FillGouraudTopFlatTriangle(HDC hDc, const Vertex& v1, const Vertex& v2, const Vertex& v3)
|
||||
{
|
||||
float slope1 = (float)(v3.GetX() - v1.GetX()) / (float)(v3.GetY() - v1.GetY());
|
||||
float slope2 = (float)(v3.GetX() - v2.GetX()) / (float)(v3.GetY() - v2.GetY());
|
||||
|
||||
float x1 = (float)v3.GetX();
|
||||
float x2 = (float)v3.GetX() + 0.5f;
|
||||
|
||||
if (slope1 < slope2)
|
||||
{
|
||||
float slopeTmp = slope1;
|
||||
slope1 = slope2;
|
||||
slope2 = slopeTmp;
|
||||
}
|
||||
|
||||
for (int scanlineY = (int)v3.GetY(); scanlineY > (int)v1.GetY(); scanlineY--)
|
||||
{
|
||||
float iRedA = (scanlineY - v2.GetY()) / (v1.GetY() - v2.GetY()) * v1.GetR() + (v1.GetY() - scanlineY) / (v1.GetY() - v2.GetY()) * v2.GetR();
|
||||
float iRedB = (scanlineY - v3.GetY()) / (v1.GetY() - v3.GetY()) * v1.GetR() + (v1.GetY() - scanlineY) / (v1.GetY() - v3.GetY()) * v3.GetR();
|
||||
float iGreenA = (scanlineY - v2.GetY()) / (v1.GetY() - v2.GetY()) * v1.GetG() + (v1.GetY() - scanlineY) / (v1.GetY() - v2.GetY()) * v2.GetG();
|
||||
float iGreenB = (scanlineY - v3.GetY()) / (v1.GetY() - v3.GetY()) * v1.GetG() + (v1.GetY() - scanlineY) / (v1.GetY() - v3.GetY()) * v3.GetG();
|
||||
float iBlueA = (scanlineY - v2.GetY()) / (v1.GetY() - v2.GetY()) * v1.GetB() + (v1.GetY() - scanlineY) / (v1.GetY() - v2.GetY()) * v2.GetB();
|
||||
float iBlueB = (scanlineY - v3.GetY()) / (v1.GetY() - v3.GetY()) * v1.GetB() + (v1.GetY() - scanlineY) / (v1.GetY() - v3.GetY()) * v3.GetB();
|
||||
|
||||
for (int xi = (int)ceil(x1); xi < (int)x2; xi++)
|
||||
{
|
||||
float redTmp = (x2 - xi) / (x2 - x1) * iRedA - (xi - x1) / (x2 - x1) * iRedB;
|
||||
float greenTmp = (x2 - xi) / (x2 - x1) * iGreenA - (xi - x1) / (x2 - x1) * iGreenB;
|
||||
float blueTmp = (x2 - xi) / (x2 - x1) * iBlueA - (xi - x1) / (x2 - x1) * iBlueB;
|
||||
|
||||
COLORREF currentColor = RGB(BoundsCheck(0, 255, (int)redTmp), BoundsCheck(0, 255, (int)greenTmp), BoundsCheck(0, 255, (int)blueTmp));
|
||||
SetPixel(hDc, xi, scanlineY, currentColor);
|
||||
}
|
||||
|
||||
x1 -= slope1;
|
||||
x2 -= slope2;
|
||||
}
|
||||
}
|
||||
|
||||
void Rasteriser::FillPolygonGouraudInt(HDC hDc, vector<Vertex>& verts)
|
||||
{
|
||||
sort(verts.begin(), verts.end(), VerticiesYCompareAsc);
|
||||
if (verts[1].GetY() == verts[2].GetY())
|
||||
@ -547,12 +563,13 @@ void Rasteriser::FillPolygonGouraudInt(HDC hDc, vector<Vertex>& verts)
|
||||
Vertex temp = Vertex(verts[0].GetX() + ((verts[1].GetY() - verts[0].GetY()) / (verts[2].GetY() - verts[0].GetY())) * (verts[2].GetX() - verts[0].GetX()), verts[1].GetY(), verts[1].GetZ());
|
||||
temp.SetNormal(verts[1].GetNormal());
|
||||
|
||||
float cRed = verts[0].GetR() + ((verts[1].GetY() - verts[0].GetY()) / (verts[2].GetY() - verts[0].GetY())) * (verts[2].GetR() - verts[0].GetR());
|
||||
float cGreen = verts[0].GetG() + ((verts[1].GetY() - verts[0].GetY()) / (verts[2].GetY() - verts[0].GetY())) * (verts[2].GetG() - verts[0].GetG());
|
||||
float cBlue = verts[0].GetB() + ((verts[1].GetY() - verts[0].GetY()) / (verts[2].GetY() - verts[0].GetY())) * (verts[2].GetB() - verts[0].GetB());
|
||||
float vDiff = ((verts[1].GetY() - verts[0].GetY()) / (verts[2].GetY() - verts[0].GetY()));
|
||||
float cRed = Lerp(verts[0].GetR(), verts[2].GetR(), vDiff);
|
||||
float cGreen = Lerp(verts[0].GetG(), verts[2].GetG(), vDiff);
|
||||
float cBlue = Lerp(verts[0].GetB(), verts[2].GetB(), vDiff);
|
||||
temp.SetColor(BoundsCheck(0, 255, (int)cRed), BoundsCheck(0, 255, (int)cGreen), BoundsCheck(0, 255, (int)cBlue));
|
||||
|
||||
if (verts[1].GetX() < temp.GetX())
|
||||
if (verts[1].GetX() <= temp.GetX())
|
||||
{
|
||||
FillGouraudSideTriangle(hDc, verts[0], verts[1], temp);
|
||||
FillGouraudSideTriangle(hDc, verts[2], verts[1], temp);
|
||||
@ -611,30 +628,35 @@ void Rasteriser::FillGouraudSideTriangle(HDC hDc, const Vertex& v1, const Vertex
|
||||
|
||||
if (tempA.GetX() < tempB.GetX())
|
||||
{
|
||||
leftEndPoint = tempA.GetX();
|
||||
rightEndPoint = tempB.GetX();
|
||||
leftEndPoint = tempA.GetX() - 1.0f;
|
||||
rightEndPoint = tempB.GetX() + 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
leftEndPoint = tempB.GetX();
|
||||
rightEndPoint = tempA.GetX();
|
||||
leftEndPoint = tempB.GetX() - 1.0f;
|
||||
rightEndPoint = tempA.GetX() + 1.0f;
|
||||
}
|
||||
|
||||
float iRedA = (tempA.GetY() - v2.GetY()) / (v1.GetY() - v2.GetY()) * v1.GetR() + (v1.GetY() - tempA.GetY()) / (v1.GetY() - v2.GetY()) * v2.GetR();
|
||||
float iRedB = (tempA.GetY() - v3.GetY()) / (v1.GetY() - v3.GetY()) * v1.GetR() + (v1.GetY() - tempA.GetY()) / (v1.GetY() - v3.GetY()) * v3.GetR();
|
||||
float iGreenA = (tempA.GetY() - v2.GetY()) / (v1.GetY() - v2.GetY()) * v1.GetG() + (v1.GetY() - tempA.GetY()) / (v1.GetY() - v2.GetY()) * v2.GetG();
|
||||
float iGreenB = (tempA.GetY() - v3.GetY()) / (v1.GetY() - v3.GetY()) * v1.GetG() + (v1.GetY() - tempA.GetY()) / (v1.GetY() - v3.GetY()) * v3.GetG();
|
||||
float iBlueA = (tempA.GetY() - v2.GetY()) / (v1.GetY() - v2.GetY()) * v1.GetB() + (v1.GetY() - tempA.GetY()) / (v1.GetY() - v2.GetY()) * v2.GetB();
|
||||
float iBlueB = (tempA.GetY() - v3.GetY()) / (v1.GetY() - v3.GetY()) * v1.GetB() + (v1.GetY() - tempA.GetY()) / (v1.GetY() - v3.GetY()) * v3.GetB();
|
||||
float iRedA = Lerp(v1.GetR(), v2.GetR(), (float)i / (float)dx1);
|
||||
float iRedB = Lerp(v1.GetR(), v3.GetR(), (float)i / (float)dx1);
|
||||
float iGreenA = Lerp(v1.GetG(), v2.GetG(), (float)i / (float)dx1);
|
||||
float iGreenB = Lerp(v1.GetG(), v3.GetG(), (float)i / (float)dx1);
|
||||
float iBlueA = Lerp(v1.GetB(), v2.GetB(), (float)i / (float)dx1);
|
||||
float iBlueB = Lerp(v1.GetB(), v3.GetB(), (float)i / (float)dx1);
|
||||
|
||||
for (int xi = (int)ceil(leftEndPoint); xi <= (int)rightEndPoint; xi++)
|
||||
{
|
||||
float redTmp = (rightEndPoint - xi) / (rightEndPoint - leftEndPoint) * iRedA + (xi - leftEndPoint) / (rightEndPoint - leftEndPoint) * iRedB;
|
||||
float greenTmp = (rightEndPoint - xi) / (rightEndPoint - leftEndPoint) * iGreenA + (xi - leftEndPoint) / (rightEndPoint - leftEndPoint) * iGreenB;
|
||||
float blueTmp = (rightEndPoint - xi) / (rightEndPoint - leftEndPoint) * iBlueA + (xi - leftEndPoint) / (rightEndPoint - leftEndPoint) * iBlueB;
|
||||
int xLength = (int)ceil(rightEndPoint) - (int)ceil(leftEndPoint);
|
||||
int ci = 0;
|
||||
|
||||
for (int xi = (int)ceil(leftEndPoint); xi <= (int)ceil(rightEndPoint); xi++)
|
||||
{
|
||||
float ti = (float)ci / (float)xLength;
|
||||
float redTmp = Lerp(iRedA, iRedB, ti);
|
||||
float greenTmp = Lerp(iGreenA, iGreenB, ti);
|
||||
float blueTmp = Lerp(iBlueA, iBlueB, ti);
|
||||
|
||||
COLORREF currentColor = RGB(BoundsCheck(0, 255, (int)redTmp), BoundsCheck(0, 255, (int)greenTmp), BoundsCheck(0, 255, (int)blueTmp));
|
||||
SetPixel(hDc, xi, tempA.GetYInt(), currentColor);
|
||||
ci++;
|
||||
}
|
||||
|
||||
|
||||
@ -642,27 +664,27 @@ void Rasteriser::FillGouraudSideTriangle(HDC hDc, const Vertex& v1, const Vertex
|
||||
{
|
||||
if (changed1)
|
||||
{
|
||||
tempA.SetX((float)tempA.GetXInt() + (float)signx1);
|
||||
tempA.SetX((float)tempA.GetX() + (float)signx1);
|
||||
}
|
||||
else
|
||||
{
|
||||
tempA.SetY((float)tempA.GetYInt() + (float)signy1);
|
||||
tempA.SetY((float)tempA.GetY() + (float)signy1);
|
||||
}
|
||||
e1 = e1 - 2 * dx1;
|
||||
}
|
||||
|
||||
if (changed1)
|
||||
{
|
||||
tempA.SetY((float)tempA.GetYInt() + (float)signy1);
|
||||
tempA.SetY((float)tempA.GetY() + (float)signy1);
|
||||
}
|
||||
else
|
||||
{
|
||||
tempA.SetX((float)tempA.GetXInt() + (float)signx1);
|
||||
tempA.SetX((float)tempA.GetX() + (float)signx1);
|
||||
}
|
||||
|
||||
e1 = e1 + 2 * dy1;
|
||||
|
||||
while (tempB.GetY() < tempA.GetY() && tempB.GetY() > tempA.GetY())
|
||||
while (tempB.GetYInt() != tempA.GetYInt())
|
||||
{
|
||||
while (e2 >= 0)
|
||||
{
|
||||
@ -689,3 +711,224 @@ void Rasteriser::FillGouraudSideTriangle(HDC hDc, const Vertex& v1, const Vertex
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Rasteriser::FillPolygonTextured(HDC hDc, Model& model, vector<Vertex>& verts)
|
||||
{
|
||||
sort(verts.begin(), verts.end(), VerticiesYCompareAsc);
|
||||
if (verts[1].GetY() == verts[2].GetY())
|
||||
{
|
||||
FillTexturedSideTriangle(hDc, model, verts[0], verts[1], verts[2], model.GetUVCoord(verts[0].GetUVIndex()), model.GetUVCoord(verts[1].GetUVIndex()), model.GetUVCoord(verts[2].GetUVIndex()));
|
||||
}
|
||||
else if (verts[0].GetY() == verts[1].GetY())
|
||||
{
|
||||
FillTexturedSideTriangle(hDc, model, verts[2], verts[0], verts[1], model.GetUVCoord(verts[2].GetUVIndex()), model.GetUVCoord(verts[0].GetUVIndex()), model.GetUVCoord(verts[1].GetUVIndex()));
|
||||
}
|
||||
else
|
||||
{
|
||||
Vertex temp = Vertex(verts[0].GetX() + ((verts[1].GetY() - verts[0].GetY()) / (verts[2].GetY() - verts[0].GetY())) * (verts[2].GetX() - verts[0].GetX()), verts[1].GetY(), verts[1].GetZ());
|
||||
temp.SetNormal(verts[1].GetNormal());
|
||||
|
||||
float tempU = model.GetUVCoord(verts[0].GetUVIndex()).GetU() + ((verts[1].GetY() - verts[0].GetY()) / (verts[2].GetY() - verts[0].GetY())) * (model.GetUVCoord(verts[2].GetUVIndex()).GetU() - model.GetUVCoord(verts[0].GetUVIndex()).GetU());
|
||||
float tempV = model.GetUVCoord(verts[0].GetUVIndex()).GetV() + ((verts[1].GetY() - verts[0].GetY()) / (verts[2].GetY() - verts[0].GetY())) * (model.GetUVCoord(verts[2].GetUVIndex()).GetV() - model.GetUVCoord(verts[0].GetUVIndex()).GetV());
|
||||
|
||||
UVCoord tempCoords = UVCoord(tempU, tempV);
|
||||
|
||||
float cRed = verts[0].GetR() + ((verts[1].GetY() - verts[0].GetY()) / (verts[2].GetY() - verts[0].GetY())) * (verts[2].GetR() - verts[0].GetR());
|
||||
float cGreen = verts[0].GetG() + ((verts[1].GetY() - verts[0].GetY()) / (verts[2].GetY() - verts[0].GetY())) * (verts[2].GetG() - verts[0].GetG());
|
||||
float cBlue = verts[0].GetB() + ((verts[1].GetY() - verts[0].GetY()) / (verts[2].GetY() - verts[0].GetY())) * (verts[2].GetB() - verts[0].GetB());
|
||||
temp.SetColor(BoundsCheck(0, 255, (int)cRed), BoundsCheck(0, 255, (int)cGreen), BoundsCheck(0, 255, (int)cBlue));
|
||||
|
||||
if (verts[1].GetX() <= temp.GetX())
|
||||
{
|
||||
temp.SetUVIndex(verts[2].GetUVIndex());
|
||||
FillTexturedSideTriangle(hDc, model, verts[0], verts[1], temp, model.GetUVCoord(verts[0].GetUVIndex()), model.GetUVCoord(verts[1].GetUVIndex()), tempCoords);
|
||||
temp.SetUVIndex(verts[0].GetUVIndex());
|
||||
FillTexturedSideTriangle(hDc, model, verts[2], verts[1], temp, model.GetUVCoord(verts[2].GetUVIndex()), model.GetUVCoord(verts[1].GetUVIndex()), tempCoords);
|
||||
}
|
||||
else
|
||||
{
|
||||
temp.SetUVIndex(verts[2].GetUVIndex());
|
||||
FillTexturedSideTriangle(hDc, model, verts[0], temp, verts[1], model.GetUVCoord(verts[0].GetUVIndex()), tempCoords, model.GetUVCoord(verts[1].GetUVIndex()));
|
||||
temp.SetUVIndex(verts[0].GetUVIndex());
|
||||
FillTexturedSideTriangle(hDc, model, verts[2], temp, verts[1], model.GetUVCoord(verts[2].GetUVIndex()), tempCoords, model.GetUVCoord(verts[1].GetUVIndex()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Rasteriser::FillTexturedSideTriangle(HDC hDc, Model& model, const Vertex& v1, const Vertex& v2, const Vertex& v3, const UVCoord& uv1, const UVCoord& uv2, const UVCoord& uv3)
|
||||
{
|
||||
Vertex tempA = Vertex(v1);
|
||||
Vertex tempB = Vertex(v1);
|
||||
UVCoord tempUVA = UVCoord(uv1);
|
||||
UVCoord tempUVB = UVCoord(uv1);
|
||||
|
||||
bool changed1 = false;
|
||||
bool changed2 = false;
|
||||
|
||||
float uc0 = uv1.GetU();
|
||||
float vc0 = uv1.GetV();
|
||||
float uc1 = uv2.GetU();
|
||||
float vc1 = uv2.GetV();
|
||||
float uc2 = uv3.GetU();
|
||||
float vc2 = uv3.GetV();
|
||||
|
||||
int dx1 = (int)ceil(abs(v2.GetX() - v1.GetX()));
|
||||
int dy1 = (int)ceil(abs(v2.GetY() - v1.GetY()));
|
||||
int du1 = (int)ceil(abs(uc1 - uc0));
|
||||
int dv1 = (int)ceil(abs(vc1 - vc0));
|
||||
|
||||
int dx2 = (int)ceil(abs(v3.GetX() - v1.GetX()));
|
||||
int dy2 = (int)ceil(abs(v3.GetY() - v1.GetY()));
|
||||
int du2 = (int)ceil(abs(uc2 - uc0));
|
||||
int dv2 = (int)ceil(abs(vc2 - vc0));
|
||||
|
||||
int signx1 = (int)ceil(sgn(v2.GetX() - v1.GetX()));
|
||||
int signx2 = (int)ceil(sgn(v3.GetX() - v1.GetX()));
|
||||
int signu1 = (int)ceil(sgn(uc1 - uc0));
|
||||
int signu2 = (int)ceil(sgn(uc2 - uc0));
|
||||
|
||||
int signy1 = (int)ceil(sgn(v2.GetY() - v1.GetY()));
|
||||
int signy2 = (int)ceil(sgn(v3.GetY() - v1.GetY()));
|
||||
int signv1 = (int)ceil(sgn(vc1 - vc0));
|
||||
int signv2 = (int)ceil(sgn(vc2 - vc0));
|
||||
|
||||
if (dy1 > dx1)
|
||||
{
|
||||
int tempDx = dx1;
|
||||
dx1 = dy1;
|
||||
dy1 = tempDx;
|
||||
|
||||
int tempDu = du1;
|
||||
du1 = dv1;
|
||||
dv1 = tempDu;
|
||||
|
||||
changed1 = true;
|
||||
}
|
||||
|
||||
if (dy2 > dx2)
|
||||
{
|
||||
int tempDx = dx2;
|
||||
dx2 = dy2;
|
||||
dy2 = tempDx;
|
||||
|
||||
int tempDu = du2;
|
||||
du2 = dv2;
|
||||
dv2 = tempDu;
|
||||
|
||||
changed2 = true;
|
||||
}
|
||||
|
||||
int e1 = 2 * (int)dy1 - (int)dx1;
|
||||
int e2 = 2 * (int)dy2 - (int)dx2;
|
||||
|
||||
for (int i = 0; i <= (int)dx1; i++)
|
||||
{
|
||||
float leftEndPoint;
|
||||
float rightEndPoint;
|
||||
float leftUV;
|
||||
float rightUV;
|
||||
|
||||
if (tempA.GetX() < tempB.GetX())
|
||||
{
|
||||
leftEndPoint = tempA.GetX() - 1.0f;
|
||||
rightEndPoint = tempB.GetX() + 1.0f;
|
||||
leftUV = tempUVA.GetU();
|
||||
rightUV = tempUVB.GetU();
|
||||
}
|
||||
else
|
||||
{
|
||||
leftEndPoint = tempB.GetX() - 1.0f;
|
||||
rightEndPoint = tempA.GetX() + 1.0f;
|
||||
leftUV = tempUVB.GetU();
|
||||
rightUV = tempUVA.GetU();
|
||||
}
|
||||
|
||||
|
||||
float UCoordA = Interpolate(uv1.GetV() + i, uv1.GetU(), uv2.GetU(), uv1.GetV(), uv2.GetV());
|
||||
float UCoordB = Interpolate(uv1.GetV() + i, uv1.GetU(), uv3.GetU(), uv1.GetV(), uv3.GetV());
|
||||
|
||||
float iRedA = Lerp(v1.GetR(), v2.GetR(), (float)i / (float)dx1);
|
||||
float iRedB = Lerp(v1.GetR(), v3.GetR(), (float)i / (float)dx1);
|
||||
float iGreenA = Lerp(v1.GetG(), v2.GetG(), (float)i / (float)dx1);
|
||||
float iGreenB = Lerp(v1.GetG(), v3.GetG(), (float)i / (float)dx1);
|
||||
float iBlueA = Lerp(v1.GetB(), v2.GetB(), (float)i / (float)dx1);
|
||||
float iBlueB = Lerp(v1.GetB(), v3.GetB(), (float)i / (float)dx1);
|
||||
|
||||
int xLength = (int)ceil(rightEndPoint) - (int)ceil(leftEndPoint);
|
||||
int ci = 0;
|
||||
|
||||
for (int xi = (int)ceil(leftEndPoint); xi <= (int)ceil(rightEndPoint); xi++)
|
||||
{
|
||||
float ti = (float)ci / (float)xLength;
|
||||
float UCoordTmp = Lerp(leftUV, rightUV, ti);
|
||||
float redTmp = Lerp(iRedA, iRedB, ti) / 100;
|
||||
float greenTmp = Lerp(iGreenA, iGreenB, ti) / 100;
|
||||
float blueTmp = Lerp(iBlueA, iBlueB, ti) / 100;
|
||||
|
||||
COLORREF textureColor = model.GetTexture().GetTextureValue((int)UCoordTmp, (int)tempUVA.GetV());
|
||||
COLORREF currentColor = RGB(BoundsCheck(0, 255, (int)(GetRValue(textureColor) * redTmp)), BoundsCheck(0, 255, (int)(GetGValue(textureColor) * greenTmp)), BoundsCheck(0, 255, (int)(GetBValue(textureColor) * blueTmp)));
|
||||
|
||||
SetPixel(hDc, xi, tempA.GetYInt(), currentColor);
|
||||
ci++;
|
||||
}
|
||||
|
||||
|
||||
while (e1 >= 0)
|
||||
{
|
||||
if (changed1)
|
||||
{
|
||||
tempA.SetX((float)tempA.GetXInt() + (float)signx1);
|
||||
tempUVA.SetU((float)tempUVA.GetU() + (float)signu1);
|
||||
}
|
||||
else
|
||||
{
|
||||
tempA.SetY((float)tempA.GetYInt() + (float)signy1);
|
||||
tempUVA.SetV((float)tempUVA.GetV() + (float)signv1);
|
||||
}
|
||||
e1 = e1 - 2 * dx1;
|
||||
}
|
||||
|
||||
if (changed1)
|
||||
{
|
||||
tempA.SetY((float)tempA.GetYInt() + (float)signy1);
|
||||
tempUVA.SetV((float)tempUVA.GetV() + (float)signv1);
|
||||
}
|
||||
else
|
||||
{
|
||||
tempA.SetX((float)tempA.GetXInt() + (float)signx1);
|
||||
tempUVA.SetU((float)tempUVA.GetU() + (float)signu1);
|
||||
}
|
||||
|
||||
e1 = e1 + 2 * dy1;
|
||||
|
||||
while (tempB.GetYInt(true) != tempA.GetYInt(true))
|
||||
{
|
||||
while (e2 >= 0)
|
||||
{
|
||||
if (changed2)
|
||||
{
|
||||
tempB.SetX((float)tempB.GetXInt() + (float)signx2);
|
||||
tempUVB.SetU((float)tempUVB.GetU() + (float)signu2);
|
||||
}
|
||||
else
|
||||
{
|
||||
tempB.SetY((float)tempB.GetYInt() + (float)signy2);
|
||||
tempUVB.SetV((float)tempUVB.GetV() + (float)signv2);
|
||||
}
|
||||
e2 = e2 - 2 * dx2;
|
||||
}
|
||||
|
||||
if (changed2)
|
||||
{
|
||||
tempB.SetY((float)tempB.GetYInt() + (float)signy2);
|
||||
tempUVB.SetV((float)tempUVB.GetV() + (float)signv2);
|
||||
}
|
||||
else
|
||||
{
|
||||
tempB.SetX((float)tempB.GetXInt() + (float)signx2);
|
||||
tempUVB.SetU((float)tempUVB.GetU() + (float)signu2);
|
||||
}
|
||||
e2 = e2 + 2 * dy2;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user