public static bool Line2dWithOrientedRectangle2d(Line2d line, OrientedRectangle2d rectangle2d) { Vector3L forward = RotateHelper.GetForward(rectangle2d.m_rotation); Vector3L right = Vector3L.Cross(Vector3L.up, forward); Vector3L pos = new Vector3L(rectangle2d.m_pos.x, 0, rectangle2d.m_pos.y); Vector3L a = pos + forward * rectangle2d.m_length * 0.5f + -right * rectangle2d.m_width * 0.5f; Vector3L b = pos + forward * rectangle2d.m_length * 0.5f + right * rectangle2d.m_width * 0.5f; Vector3L c = pos + -forward * rectangle2d.m_length * 0.5f + right * rectangle2d.m_width * 0.5f; Vector3L d = pos + -forward * rectangle2d.m_length * 0.5f + -right * rectangle2d.m_width * 0.5f; List <Vector2L> lineList = new List <Vector2L>(); lineList.Add(new Vector2L(a.x, a.z)); lineList.Add(new Vector2L(b.x, b.z)); lineList.Add(new Vector2L(c.x, c.z)); lineList.Add(new Vector2L(d.x, d.z)); for (int i = 0; i < lineList.Count; ++i) { if (IsTwoSegmentIntersection(lineList[i], lineList[(i + 1) % lineList.Count], line.m_point1, line.m_point2)) { return(true); } } return(false); }
public static bool Circle2dWithOrientedRectangle2d(Circle2d circle, OrientedRectangle2d rectangle) { Vector3L forward = RotateHelper.GetForward(rectangle.m_rotation); Vector3L right = Vector3L.Cross(Vector3L.up, forward); Vector3L pos = new Vector3L(rectangle.m_pos.x, 0, rectangle.m_pos.y); Vector3L a = pos + forward * rectangle.m_length * 0.5f + -right * rectangle.m_width * 0.5f; Vector3L b = pos + forward * rectangle.m_length * 0.5f + right * rectangle.m_width * 0.5f; Vector3L c = pos + -forward * rectangle.m_length * 0.5f + right * rectangle.m_width * 0.5f; Vector3L d = pos + -forward * rectangle.m_length * 0.5f + -right * rectangle.m_width * 0.5f; List <Vector2L> lineList = new List <Vector2L>(); lineList.Add(new Vector2L(a.x, a.z)); lineList.Add(new Vector2L(b.x, b.z)); lineList.Add(new Vector2L(c.x, c.z)); lineList.Add(new Vector2L(d.x, d.z)); for (int i = 0; i < lineList.Count; ++i) { Segment2d segment = new Segment2d(); segment.m_point1 = lineList[i]; segment.m_point2 = lineList[(i + 1) % lineList.Count]; if (Segment2dWithCircle2d(segment, circle)) { return(true); } } return(false); }
public void Rotate(int x, int y) { x0 = RotateHelper.RotateX(x0, y0, x, y); y0 = RotateHelper.RotateY(x0, y0, x, y); x1 = RotateHelper.RotateX(x1, y1, x, y); y1 = RotateHelper.RotateY(x1, y1, x, y); }
public void RotateCorrect1() { int x = 0; int y = 0; int x0 = 30; int y0 = 30; Assert.AreEqual(60, RotateHelper.RotateX(x, y, x0, y0)); Assert.AreEqual(0, RotateHelper.RotateY(x, y, x0, y0)); }
public void Rotate(int x, int y) { var newx0 = RotateHelper.RotateX(x0, y0, x, y); var newy0 = RotateHelper.RotateY(x0, y0, x, y); x0 = newx0; y0 = newy0; afterClick = true; list = null; afterMove = true; }
public void Rotate(int x, int y) { var newx0 = RotateHelper.RotateX(x0, y0, x, y); var newy0 = RotateHelper.RotateY(x0, y0, x, y); var newx1 = RotateHelper.RotateX(x1, y1, x, y); var newy1 = RotateHelper.RotateY(x1, y1, x, y); x0 = newx0; x1 = newx1; y0 = newy0; y1 = newy1; }
public static bool Point2dWithRectangle2d(Vector2L point2d, OrientedRectangle2d rectangle2d) { Vector3L forward = RotateHelper.GetForward(rectangle2d.m_rotation); Vector3L right = Vector3L.Cross(Vector3L.up, forward); Vector3L pos = new Vector3L(rectangle2d.m_pos.x, 0, rectangle2d.m_pos.y); Vector3L a = pos + forward * rectangle2d.m_length * 0.5f + -right * rectangle2d.m_width * 0.5f; Vector3L b = pos + forward * rectangle2d.m_length * 0.5f + right * rectangle2d.m_width * 0.5f; Vector3L c = pos + -forward * rectangle2d.m_length * 0.5f + right * rectangle2d.m_width * 0.5f; Vector3L d = pos + -forward * rectangle2d.m_length * 0.5f + -right * rectangle2d.m_width * 0.5f; return(IsInRectangle2d(a, b, c, d, new Vector3L(point2d.x, 0, point2d.y))); }
void Start() { target = GameObject.FindWithTag("Player").transform; //target the player treeRotate = new RotateHelper(gameObject,new Vector3(90,0,0),speed); gateRotators = new System.Collections.Generic.List<RotateHelper>(); gateRotators.Add(new RotateHelper(gateLeft, new Vector3(-90, 0, 0),speed/2)); gateRotators.Add(new RotateHelper(gateRight, new Vector3(-90, 0, 0), speed/2)); meshCollider = GetComponent<Collider>(); //Rather than copy pasting the same line, should really put some of these in a utility class. //But that'd take time. }
public static bool Point2dWithSector2d(Vector2L pos, Sector2d sector2d) { Vector2L distance = pos - sector2d.m_pos; if (distance.magnitude > sector2d.m_radius) { return(false); } Vector3L sectorForward = RotateHelper.GetForward(sector2d.m_rotation); FloatL cosTarget = Vector3L.Dot(sectorForward, distance) / sectorForward.magnitude / distance.magnitude; FloatL cosHalfDegree = FixPointMath.Cos((FixPointMath.Deg2Rad * sector2d.m_theraDegree / 2)); return(cosTarget > cosHalfDegree); }
public void Rotate(int x, int y) { this.x = RotateHelper.RotateX(this.x, this.y, x, y); this.y = RotateHelper.RotateY(this.x, this.y, x, y); }
// Use this for initialization void Start() { rotator = new RotateHelper(gameObject, rotation, speed); }