private void DefaultTransformVals() { objCentre = DefaultObjCentre; surfaceCentre = DefaultSurfaceCentre; OldScalVal = ScalVal = 1; ScaleBox.Value = 1; if (PyramidCheck.Checked) { oldTransVal.X = TransVal.X = objCentre.X; oldTransVal.Y = TransVal.Y = objCentre.Y; oldTransVal.Z = TransVal.Z = objCentre.Z; } else { oldTransVal.X = TransVal.X = surfaceCentre.X; oldTransVal.Y = TransVal.Y = surfaceCentre.Y; oldTransVal.Z = TransVal.Z = surfaceCentre.Z; } transX.Value = (decimal)oldTransVal.X; transY.Value = (decimal)oldTransVal.Y; transZ.Value = (decimal)oldTransVal.Z; XRotValue = YRotValue = ZRotValue = OldXRotValue = OldYRotValue = OldZRotValue = 0; rotateX.Value = rotateY.Value = rotateZ.Value = 0; pyramid = (Polygon3D[])DefaultPyramid.Clone(); surface.ControlPoints = (PointF3D[, ])DefaultControlPoints.Clone(); }
public Form1() { InitializeComponent(); Normalize.WinHeight = isometrixBox.ClientSize.Height; Normalize.WinWidth = isometrixBox.ClientSize.Width; //Base PointF3D base1 = new PointF3D(2, 0, 0); PointF3D base2 = new PointF3D(0, 0, 5); PointF3D base3 = new PointF3D(15f, 0, 8f); //Height PointF3D height = new PointF3D(2, 10, 0); DefaultPyramid = new Polygon3D[] { //base new Polygon3D(new PointF3D[] { base1, base2, base3 }), //connections lines to the height new Polygon3D(new PointF3D[] { base1, height }), new Polygon3D(new PointF3D[] { base2, height }), new Polygon3D(new PointF3D[] { base3, height }), //height new Polygon3D(new PointF3D[] { height, height }), }; pyramid = (Polygon3D[])DefaultPyramid.Clone(); DefaultObjCentre = new PointF3D(2, 0, 2); objCentre = DefaultObjCentre; surfaceCentre = DefaultSurfaceCentre; DefaultTransformVals(); PointF[] IzometricAxes = ProjectionAffinity.projectionIsometric(coordinateLines); PointF[] XYAxes = ProjectionAffinity.projectionXY(coordinateLines); PointF[] XZAxes = ProjectionAffinity.projectionXZ(coordinateLines); PointF[] YZAxes = ProjectionAffinity.projectionYZ(coordinateLines); normalizedIzometricAxes = new PointF[IzometricAxes.Length]; normalizedXYAxes = new PointF[XYAxes.Length]; normalizedXZAxes = new PointF[XZAxes.Length]; normalizedYZAxes = new PointF[YZAxes.Length]; for (int i = 0; i < coordinateLines.Length; i++) { normalizedIzometricAxes[i].X = Normalize.NormalizeX(IzometricAxes[i].X); normalizedIzometricAxes[i].Y = Normalize.NormalizeY(IzometricAxes[i].Y); normalizedXYAxes[i].X = Normalize.NormalizeX(XYAxes[i].X); normalizedXYAxes[i].Y = Normalize.NormalizeY(XYAxes[i].Y); normalizedXZAxes[i].X = Normalize.NormalizeX(XZAxes[i].X); normalizedXZAxes[i].Y = Normalize.NormalizeY(XZAxes[i].Y); normalizedYZAxes[i].X = Normalize.NormalizeX(YZAxes[i].X); normalizedYZAxes[i].Y = Normalize.NormalizeY(YZAxes[i].Y); } }
public static PointF3D[] Translate3D(PointF3D[] obj, double x, double y, double z) { PointF3D[] TranslatedtedObj = new PointF3D[obj.Length]; obj.CopyTo(TranslatedtedObj, 0); Matrix CurPoint; for (int i = 0; i < TranslatedtedObj.Length; i++) { CurPoint = Form3DCoordsMatrix(obj[i].X, obj[i].Y, obj[i].Z); CurPoint = Get3DTranslationMatrix(x, y, z).Multiply(CurPoint); TranslatedtedObj[i].X = (float)CurPoint.GetElementValue(0, 0); TranslatedtedObj[i].Y = (float)CurPoint.GetElementValue(1, 0); TranslatedtedObj[i].Z = (float)CurPoint.GetElementValue(2, 0); } return(TranslatedtedObj); }
public static PointF3D[] RotateZ3D(PointF3D[] obj, double angle, PointF3D RotationCentre) { PointF3D[] RotatedObj = new PointF3D[obj.Length]; obj.CopyTo(RotatedObj, 0); RotatedObj = Translate3D(RotatedObj, -RotationCentre.X, -RotationCentre.Y, -RotationCentre.Z); Matrix CurPoint; for (int i = 0; i < RotatedObj.Length; i++) { CurPoint = Form3DCoordsMatrix(RotatedObj[i].X, RotatedObj[i].Y, RotatedObj[i].Z); CurPoint = GetZRotation3DMatrix(angle).Multiply(CurPoint); RotatedObj[i].X = (float)CurPoint.GetElementValue(0, 0); RotatedObj[i].Y = (float)CurPoint.GetElementValue(1, 0); RotatedObj[i].Z = (float)CurPoint.GetElementValue(2, 0); } RotatedObj = Translate3D(RotatedObj, RotationCentre.X, RotationCentre.Y, RotationCentre.Z); return(RotatedObj); }
public static PointF3D[] Scale3D(PointF3D[] obj, double xScal, double yScal, double zScal, PointF3D ScalingCentre) { PointF3D[] ScaledtedObj = new PointF3D[obj.Length]; obj.CopyTo(ScaledtedObj, 0); ScaledtedObj = Translate3D(ScaledtedObj, -ScalingCentre.X, -ScalingCentre.Y, -ScalingCentre.Z); Matrix CurPoint; for (int i = 0; i < ScaledtedObj.Length; i++) { CurPoint = Form3DCoordsMatrix(ScaledtedObj[i].X, ScaledtedObj[i].Y, ScaledtedObj[i].Z); CurPoint = Get3DScalingMatrix(xScal, yScal, zScal).Multiply(CurPoint); ScaledtedObj[i].X = (float)CurPoint.GetElementValue(0, 0); ScaledtedObj[i].Y = (float)CurPoint.GetElementValue(1, 0); ScaledtedObj[i].Z = (float)CurPoint.GetElementValue(2, 0); } ScaledtedObj = Translate3D(ScaledtedObj, ScalingCentre.X, ScalingCentre.Y, ScalingCentre.Z); return(ScaledtedObj); }
public PointF3D[] Scale(PointF3D ScalVal, PointF3D ScalCentre) { return(ProjectionAffinity.Scale3D(polygons, ScalVal.X, ScalVal.Y, ScalVal.Z, ScalCentre)); }
public PointF3D[] RotateZ(float Angle, PointF3D RotCentre) { return(ProjectionAffinity.RotateZ3D(polygons, Angle, RotCentre)); }
public PointF3D[] Translate(PointF3D translation) { return(ProjectionAffinity.Translate3D(polygons, translation.X, translation.Y, translation.Z)); }
void TransformObject() { if (oldTransVal != TransVal) { if (PyramidCheck.Checked) { for (int i = 0; i < pyramid.Length; i++) { pyramid[i].polygons = pyramid[i].Translate(new PointF3D(TransVal.X - oldTransVal.X, TransVal.Y - oldTransVal.Y, TransVal.Z - oldTransVal.Z)); } objCentre.X += TransVal.X - oldTransVal.X; objCentre.Y += TransVal.Y - oldTransVal.Y; objCentre.Z += TransVal.Z - oldTransVal.Z; } else { surface.ControlPoints = surface.Translate(new PointF3D(TransVal.X - oldTransVal.X, TransVal.Y - oldTransVal.Y, TransVal.Z - oldTransVal.Z)); surfaceCentre.X += TransVal.X - oldTransVal.X; surfaceCentre.Y += TransVal.Y - oldTransVal.Y; surfaceCentre.Z += TransVal.Z - oldTransVal.Z; } oldTransVal = TransVal; } if (OldXRotValue != XRotValue) { if (PyramidCheck.Checked) { for (int i = 0; i < pyramid.Length; i++) { pyramid[i].polygons = pyramid[i].RotateX(XRotValue - OldXRotValue, objCentre); } } else { surface.ControlPoints = surface.RotateX(XRotValue - OldXRotValue, surfaceCentre); } OldXRotValue = XRotValue; } if (OldYRotValue != YRotValue) { if (PyramidCheck.Checked) { for (int i = 0; i < pyramid.Length; i++) { pyramid[i].polygons = pyramid[i].RotateY(YRotValue - OldYRotValue, objCentre); } } else { surface.ControlPoints = surface.RotateY(YRotValue - OldYRotValue, surfaceCentre); } OldYRotValue = YRotValue; } if (OldZRotValue != ZRotValue) { if (PyramidCheck.Checked) { for (int i = 0; i < pyramid.Length; i++) { pyramid[i].polygons = pyramid[i].RotateZ(ZRotValue - OldZRotValue, objCentre); } } else { surface.ControlPoints = surface.RotateZ(ZRotValue - OldZRotValue, surfaceCentre); } OldZRotValue = ZRotValue; } if (OldScalVal != ScalVal) { float curscalval = ScalVal / OldScalVal; if (PyramidCheck.Checked) { for (int i = 0; i < pyramid.Length; i++) { pyramid[i].polygons = pyramid[i].Scale(new PointF3D(curscalval, curscalval, curscalval), objCentre); } } else { surface.ControlPoints = surface.Scale(new PointF3D(curscalval, curscalval, curscalval), surfaceCentre); } OldScalVal = ScalVal; } }