public void translate(point3 translation) { for (int i = 0; i < verts.Length; i++) { verts[i] = Matrix.add(verts[i], translation); } }
public point3 translatePoint(point3 point, int side) { switch (side) { case 0: return(new point3(point.x, point.y + 1, point.z)); case 1: return(new point3(point.x, point.y - 1, point.z)); case 2: return(new point3(point.x, point.y, point.z + 1)); case 3: return(new point3(point.x + 1, point.y, point.z)); case 4: return(new point3(point.x, point.y, point.z - 1)); case 5: return(new point3(point.x - 1, point.y, point.z)); default: return(null); } }
public void rotate(double angle, byte dir) { //Rotate about centerpoint of the shape: translate the center of our shape to the origin, rotate, translate back. float cosAngle = (float)Math.Cos(angle); float sinAngle = (float)Math.Sin(angle); Matrix rotMtrx = null; point3 startCoords = verts[0]; translate(new Mesh.point3(-startCoords.x, -startCoords.y, -startCoords.z)); #region rotations /* Rotate about X Axis {{1,0, 0}, * {0, cosAngle,sinAngle*100}, * {0, -sinAngle/100, cosAngle}}, 3, 3); * * * Rotate about Y Axis {{cosAngle,0,-sinAngle*100}, * {0, 1, 0}, * {sinAngle, 0, cosAngle}}, 3, 3); * Rotate about Z axis * {{cosAngle,-sinAngle,0}, * {sinAngle, cosAngle,0}, * {0, 0, 1}},3,3); */ #endregion int x = Environment.TickCount; if (dir == 0) { rotMtrx = new Matrix(new float[, ] { { 1, 0, 0 }, { 0, cosAngle, sinAngle * 100 }, { 0, -sinAngle / 100, cosAngle } }, 3, 3); } else if (dir == 1) { rotMtrx = new Matrix(new float[, ] { { cosAngle, 0, -sinAngle * 100 }, { 0, 1, 0 }, { sinAngle / 100, 0, cosAngle } }, 3, 3); } else { rotMtrx = new Matrix(new float[, ] { { cosAngle, -sinAngle, 0 }, { sinAngle, cosAngle, 0 }, { 0, 0, 1 } }, 3, 3); } x = Environment.TickCount - x; for (int i = 0; i < vertCount; i++) { verts[i] = rotMtrx.multiply(verts[i]); } translate(new Mesh.point3(startCoords.x, startCoords.y, startCoords.z)); }
public Mesh(point3[] meshVerts, triangle[] meshFaces, point2[] meshUvs, Material[] mtls = null) { verts = meshVerts; vertCount = verts.Length; faces = meshFaces; faceCount = faces.Length; uvVerts = meshUvs; matIDs = mtls; }
public point3 Vector2Point(Vector3 _v3) { point3 p = new point3(); p.x = _v3.x; p.y = _v3.y; p.z = _v3.z; return(p); }
void generateInitialPopulation() { // int initialStrutID = 1000; // Use this for initialization // int identityStrut = initialStrutID; // int currentStrut; for (int i = 0; i < populationSize; i++) { bluePrint robot; string[] chromosomes = new string[numberOfUnits - 1]; string ID = "B" + i; //sr.WriteLine (ID); // string[] IDList = new string[numberOfUnits]; // int originID = 5000; robot = new bluePrint(ID); int originUnitType = UnityEngine.Random.Range(0, maxValueOfUnit + 1); functionalUnit origin = new functionalUnit("5000", new point3(0, 0, 0)); robot.unitArray.Add(origin); for (int j = 0; j < numberOfUnits - 1; j++) { int id = 5001 + j; int side = UnityEngine.Random.Range(0, 6); int connectObject = 5000 + UnityEngine.Random.Range(0, j + 1); functionalUnit con = robot.getUnit("" + connectObject); point3 newPoint = translatePoint(con.location, side); while (robot.unitAreaOccupied(newPoint)) { side = UnityEngine.Random.Range(0, 6); connectObject = 5000 + UnityEngine.Random.Range(0, j + 1); con = robot.getUnit("" + connectObject); newPoint = translatePoint(con.location, side); } robot.unitArray.Add(new functionalUnit("" + id, newPoint)); int unitType = UnityEngine.Random.Range(0, maxValueOfUnit + 1); string chromosome = connectObject + "," + id + "," + originUnitType + "," + unitType + "," + side; chromosomes [j] = chromosome; } robot.chromosomes = chromosomes; currentPopulation [i] = robot; } }
public void CameraRender(PointF borderx, PointF bordexy) { int h = pictureBox2.Image.Height; int w = pictureBox2.Image.Width; double xstep = double.Parse(textBox5.Text); double ystep = xstep; var YMax = new int[w]; var YMin = new int[w]; for (int i = 0; i < w; i++) { YMax[i] = -1; YMin[i] = pictureBox2.Height; } for (double x = borderx.X; x <= borderx.Y; x += xstep) { var hor = new List <PointPol>(); for (double y = bordexy.X; y <= bordexy.Y; y += ystep) { hor.Add(PointToView(new PointPol(x, y, f(x, y)))); } var cur_hor = new List <Point>(); foreach (PointPol p in hor) { point3 vp = ViewPortTranform(p); cur_hor.Add(new Point((int)p.X, (int)p.Y)); } cur_hor = cur_hor.OrderBy(p => p.X).ToList(); for (int i = 0; i < cur_hor.Count - 1; i++) { var line = Interpolate(cur_hor[i].X, cur_hor[i].Y, cur_hor[i + 1].X, cur_hor[i + 1].Y); int index = -1; for (int linex = cur_hor[i].X; linex < cur_hor[i + 1].X; ++linex) { index++; if (linex >= 0 && linex < w && line[index] > YMax[linex]) { YMax[linex] = line[index]; } if (linex >= 0 && linex < w && line[index] < YMin[linex]) { YMin[linex] = line[index]; } } } for (int i = 0; i < w - 1; i++) { if (YMax[i] >= 0 && YMax[i] < h && YMax[i + 1] >= 0 && YMax[i + 1] < h) { g2.DrawLine(new Pen(Color.Green), new Point(i, YMax[i]), new Point(i + 1, YMax[i + 1])); } if (YMin[i] <= h && YMax[i] < pictureBox2.Width && YMin[i + 1] < h && YMin[i + 1] < pictureBox2.Width) { g2.DrawLine(new Pen(Color.GreenYellow), new Point(i, YMin[i]), new Point(i + 1, YMin[i + 1])); } } } pictureBox2.Image = pictureBox2.Image; }