private Vector3 TransformPointInEllipseCircleLocalSpace(Vector3 vector) { TransformMatrix transformMatrix = TransformMatrix; vector = transformMatrix.MultiplyPointInverse(vector); vector.x /= _radiusX; vector.z /= _radiusZ; return(vector); }
public void CalculateCellIndicesFromPoint(Vector3 point, out int cellIndexX, out int cellIndexZ) { Vector3 gridSpacePoint = TransformMatrix.MultiplyPointInverse(point); float offsetX = _alignCellEdgeWithOrigin ? 0.0f : CellSizeSettings.CellSizeX; float offsetZ = _alignCellEdgeWithOrigin ? 0.0f : CellSizeSettings.CellSizeZ; cellIndexX = Mathf.FloorToInt((gridSpacePoint.x + offsetX) / CellSizeSettings.CellSizeX); cellIndexZ = Mathf.FloorToInt((gridSpacePoint.z + offsetZ) / CellSizeSettings.CellSizeZ); }
private void CalculateInitialMinMaxPoints(out Vector3 minPoint, out Vector3 maxPoint) { // We will sort the points along the X axis, but we have to take the polygon's coordinate // system into account because if we use the global X axis, we will run into trouble when // all points of the polygon reside on the YZ plane (i.e. same X coordinate). Vector3 polyLocalRight, polyLocalLook; if (_polygonNormal.IsAlignedWith(Vector3.up)) { polyLocalRight = Vector3.right; polyLocalLook = Vector3.Cross(polyLocalRight, Vector3.up); polyLocalLook.Normalize(); } else { polyLocalRight = Vector3.Cross(_polygonNormal, Vector3.up); polyLocalRight.Normalize(); polyLocalLook = Vector3.Cross(polyLocalRight, _polygonNormal); polyLocalLook.Normalize(); } Quaternion polyRotation = Quaternion.LookRotation(polyLocalLook, _polygonNormal); TransformMatrix transformMatrix = new TransformMatrix(Vector3.zero, polyRotation, Vector3.one); // Note: We will work in polygon local space and transform the points to world space after we are done. minPoint = transformMatrix.MultiplyPointInverse(_polygonPointsOnSamePlane[0]); maxPoint = transformMatrix.MultiplyPointInverse(_polygonPointsOnSamePlane[0]); for (int ptIndex = 0; ptIndex < _polygonPointsOnSamePlane.Count; ++ptIndex) { Vector3 point = transformMatrix.MultiplyPointInverse(_polygonPointsOnSamePlane[ptIndex]); if (point.x < minPoint.x) { minPoint = point; } if (point.x > maxPoint.x) { maxPoint = point; } } minPoint = transformMatrix.MultiplyPoint(minPoint); maxPoint = transformMatrix.MultiplyPoint(maxPoint); }
public Vector3 GetPointInModelSpace(Vector3 point) { return(TransformMatrix.MultiplyPointInverse(point)); }