Files
Work/engine/DEVICE3D.CPP
2024-08-07 09:16:27 -04:00

114 lines
4.1 KiB
C++

#include <common/math.hpp>
#include <engine/rect3d.hpp>
#include <engine/device3d.hpp>
Device3D::Device3D(GUIWindow &displayWindow,PureDevice &displayDevice)
: PureDevice((HDC)displayDevice), mDisplayWindow(displayWindow)
{
}
void Device3D::line(Point3D &firstPoint3D,Point3D &secondPoint3D,const Pen &somePen)
{
Point firstPoint;
Point secondPoint;
mapCoordinates(firstPoint3D,firstPoint);
mapCoordinates(secondPoint3D,secondPoint);
if(firstPoint.x()>=viewPortWidth())firstPoint.x(viewPortWidth()-1);
if(secondPoint.x()>=viewPortWidth())secondPoint.x(viewPortWidth()-1);
if(firstPoint.x()<0)firstPoint.x(0);
if(secondPoint.x()<0)secondPoint.x(0);
if(firstPoint.y()>=viewPortHeight())firstPoint.y(viewPortHeight()-1);
if(secondPoint.y()>=viewPortHeight())secondPoint.y(viewPortHeight()-1);
if(firstPoint.y()<0)firstPoint.y(0);
if(firstPoint.y()<0)firstPoint.y(0);
// if(!isInView(firstPoint))return;
// if(!isInView(secondPoint))return;
PureDevice::line(firstPoint,secondPoint,somePen);
}
void Device3D::point(Point3D &somePoint3D,RGBColor &someRGBColor)
{
Point somePoint;
mapCoordinates(somePoint3D,somePoint);
setPixel(somePoint,someRGBColor);
}
void Device3D::rect3D(const Rect3D &someRect3D,const Pen &somePen)
{
line(((Vector3D&)(someRect3D.firstPlane()))[0],((Vector3D&)(someRect3D.firstPlane()))[1],somePen);
line(((Vector3D&)(someRect3D.firstPlane()))[1],((Vector3D&)(someRect3D.firstPlane()))[2],somePen);
line(((Vector3D&)(someRect3D.firstPlane()))[2],((Vector3D&)(someRect3D.firstPlane()))[3],somePen);
line(((Vector3D&)(someRect3D.firstPlane()))[3],((Vector3D&)(someRect3D.firstPlane()))[0],somePen);
line(((Vector3D&)(someRect3D.nextPlane()))[0],((Vector3D&)(someRect3D.nextPlane()))[1],somePen);
line(((Vector3D&)(someRect3D.nextPlane()))[1],((Vector3D&)(someRect3D.nextPlane()))[2],somePen);
line(((Vector3D&)(someRect3D.nextPlane()))[2],((Vector3D&)(someRect3D.nextPlane()))[3],somePen);
line(((Vector3D&)(someRect3D.nextPlane()))[3],((Vector3D&)(someRect3D.nextPlane()))[0],somePen);
line(((Vector3D&)(someRect3D.firstPlane()))[0],((Vector3D&)(someRect3D.nextPlane()))[0],somePen);
line(((Vector3D&)(someRect3D.firstPlane()))[1],((Vector3D&)(someRect3D.nextPlane()))[1],somePen);
line(((Vector3D&)(someRect3D.firstPlane()))[2],((Vector3D&)(someRect3D.nextPlane()))[2],somePen);
line(((Vector3D&)(someRect3D.firstPlane()))[3],((Vector3D&)(someRect3D.nextPlane()))[3],somePen);
}
void Device3D::drawAxis(WORD drawFlag)
{
Pen blackPen(RGBColor(0,0,0),2);
Pen whitePen(RGBColor(255,255,255),2);
int maxValue(100);
int minValue(-100);
if(!drawFlag)
{
line(Point3D(minValue,0,0),Point3D(maxValue,0,0),blackPen);
line(Point3D(0,minValue,0),Point3D(0,maxValue,0),blackPen);
line(Point3D(0,0,minValue),Point3D(0,0,maxValue),blackPen);
}
else
{
line(Point3D(minValue,0,0),Point3D(maxValue,0,0),whitePen);
line(Point3D(0,minValue,0),Point3D(0,maxValue,0),whitePen);
line(Point3D(0,0,minValue),Point3D(0,0,maxValue),whitePen);
}
}
void Device3D::drawAxis(const RGBColor &textColor,const RGBColor &bkColor)
{
Pen blackPen(RGBColor(0,0,0),2);
Pen whitePen(RGBColor(255,255,255),2);
int maxValue(100);
int minValue(-100);
setTextColor(textColor);
setBkColor(bkColor);
line(Point3D(minValue,0,0),Point3D(maxValue,0,0),whitePen);
drawText("x",Point3D(maxValue/2,0,0));
drawText(String().fromInt(maxValue),Point3D(maxValue,0,0));
drawText(String().fromInt(minValue),Point3D(minValue,0,0));
line(Point3D(0,minValue,0),Point3D(0,maxValue,0),whitePen);
drawText("y",Point3D(0,maxValue/2,0));
drawText(String().fromInt(maxValue),Point3D(0,maxValue,0));
drawText(String().fromInt(minValue),Point3D(0,minValue,0));
line(Point3D(0,0,minValue),Point3D(0,0,maxValue),whitePen);
drawText("z",Point3D(0,0,maxValue/2));
drawText(String().fromInt(maxValue),Point3D(0,0,maxValue));
drawText(String().fromInt(minValue),Point3D(0,0,minValue));
}
void Device3D::drawText(const String &text,Point3D &point3D,bool useCartesian)
{
Point screenPoint;
mapCoordinates(point3D,screenPoint,useCartesian);
PureDevice::drawText(screenPoint,text);
}