} // public bool IsCrossEdge(EDGE__) public bool DoesCrossEdge2D(Vector3 v3Pnt0_, Vector3 v3Pnt1_) { Vector2 v2Pnt0_ = new Vector2(v3Pnt0_.x, v3Pnt0_.z); Vector2 v2Pnt1_ = new Vector2(v3Pnt1_.x, v3Pnt1_.z); return(CMATH.lineCross2D(_v2Pnt0, _v2Pnt1, v2Pnt0_, v2Pnt1_)); }
//@ Intersect ray to tries iteration. public CBASE__ GetIntersectedRay(Vector3 lineOrigin, Vector3 lineDir) { if (true == m_listTris.IsNullOrEmpty()) { return(null); } List <CTRI> triesForIteration = m_listTris.Where(t => { return(null != t.GetBaseLinked); }).ToListOrDefault(); if (true == triesForIteration.IsNullOrEmpty()) { return(null); } CTRI intersectedTri = triesForIteration.FirstOrDefault(t => { return(CMATH.IntersectRayTriSimple(lineOrigin, lineDir, t._arrv3PT[0], t._arrv3PT[1], t._arrv3PT[2])); }); if (null == intersectedTri) { return(null); } CBASE__ intersectedBase = intersectedTri.GetBaseLinked; return(intersectedBase); }
} // protected void collectWayToGoalLinear() //protected float differChangeRateBetweenVec3(Vector3 v3Way0, Vector3 v3Way1, Vector3 v3Way2) protected float differChangeRateBetweenVec3(Vector3 v3Edge01, Vector3 v3Edge02) { Vector2 v2Edge01 = CMATH.ConvertToV2_Y(v3Edge01); Vector2 v2Edge02 = CMATH.ConvertToV2_Y(v3Edge02); Vector2 v2Change01 = new Vector2(v2Edge01.sqrMagnitude, v3Edge01.y * v3Edge01.y); Vector2 v2Change02 = new Vector2(v2Edge02.sqrMagnitude, v3Edge02.y * v3Edge02.y); float fChangeRate01 = v2Change01.x / v2Change01.y; float fChangeRate02 = v2Change02.x / v2Change02.y; return(Mathf.Abs(fChangeRate02 - fChangeRate01)); } // protected float differChangeRateBetweenVec3(Vector3 v3Way0, Vector3 v3Way1, Vector3 v3Way2)
public void DrawMesh_user(int iIDX_, Vector3[] arrVertex_in, int[] arriIB, Color colorUser_, float fScale_, float fEpsilonForZFight) { m_iIDX = iIDX_; int iCntVertices = arrVertex_in.Length; Vector3[] arrVertex_to = new Vector3[arrVertex_in.Length]; if (fEpsilonForZFight > CMATH.FEPSILON_F4) { for (int iVB = 0; iVB < iCntVertices; ++iVB) { Vector3 v3Src_ = arrVertex_in[iVB]; arrVertex_to[iVB] = new Vector3(v3Src_.x, v3Src_.y + fEpsilonForZFight, v3Src_.z); } } else { Array.Copy(arrVertex_in, arrVertex_to, arrVertex_in.Length); } if (fScale_ > 0) { CMATH.rescaleVertices(ref arrVertex_to, fScale_); } Mesh meshUser = gameObject.AddComponent <MeshFilter>().mesh; Renderer rendererNew = gameObject.AddComponent <MeshRenderer>().GetComponent <Renderer>(); Vector2[] arrv2UV = new Vector2[iCntVertices]; for (int iVB = 0; iVB < iCntVertices; ++iVB) { arrv2UV[iVB] = new Vector2(arrVertex_to[iVB].x, arrVertex_to[iVB].z); } meshUser.vertices = arrVertex_to; meshUser.triangles = arriIB; meshUser.uv = arrv2UV; meshUser.RecalculateNormals(); // Option rendererNew.material = m_materialUser; // material Mesh rendererNew.material.color = colorUser_; // Color Mesh } // public void DrawMesh_user()
public bool IntersectedPosToEdge(Vector3 posTestStart, Vector3 posTestEnd, ref Vector3 posIntersected) { Vector3 posP0 = posTestStart; Vector3 posP1 = posTestEnd; Vector3 posP2 = new Vector3(posTestStart.x, posTestStart.y + 0.2f, posTestStart.z); Vector3[] arrPosLine = new Vector3[2]; arrPosLine[0] = new Vector3(_posEdgeTo0.x, _posEdgeTo0.y, _posEdgeTo0.z); arrPosLine[1] = new Vector3(_posEdgeTo1.x, _posEdgeTo1.y, _posEdgeTo1.z); //CMATH.rescaleVertices(ref arrPosLine, 1.0f); bool bIntersected = CMATH.findposIntersected(arrPosLine[0], arrPosLine[1], posP0, posP1, posP2, false, ref posIntersected); _ratioPerpen = (posIntersected - _posEdgeTo0).magnitude / (_posEdgeTo1 - _posEdgeTo0).magnitude; return(bIntersected); }
public void InitializeFlyPathUnit() { if (null != m_Text3D_src) { m_Text3D_Numbering = (C3DText_)Instantiate(m_Text3D_src); m_Text3D_Numbering.SetFont("", size_font3d, color_font3d, billboard_font3d); m_Text3D_Position = (C3DText_)Instantiate(m_Text3D_src); m_Text3D_Position.SetFont("", size_font3d_info, color_font3d_info, billboard_font3d); m_Text3D_Position.SetVisible(true); } m_v3ScaleSel = CMATH.V3Multiply(transform.localScale, m_v3ScaleSel); m_v3ScaleNonSel = CMATH.V3Multiply(transform.localScale, m_v3ScaleNonSel); m_rendererCurvePath = gameObject.GetComponent <Renderer>(); SetUnselectMaterial(); }
} // protected float differChangeRateBetweenVec3(Vector3 v3Way0, Vector3 v3Way1, Vector3 v3Way2) //@ search intersected point // faster then 3.x~4.x times average, prepare RayIntersect. public int intersectRay_inAdjs(int iSeqCell, Vector3 v3RayOrigin, Vector3 v3RayDir, ref Vector3 posIntersected_out) { if (CNAVICELL.NULL_CELL == iSeqCell) { return(CNAVICELL.NULL_CELL); } CNAVICELL navicell = m_arrNavicells[iSeqCell]; int iIdxIntersectedCell = CNAVICELL.NULL_CELL; bool bIntersectedCell = false; bIntersectedCell = CMATH.IntersectRayTri_GetPos( v3RayOrigin, v3RayDir, navicell.m_arrv3PT, ref posIntersected_out); if (true == bIntersectedCell) { iIdxIntersectedCell = iSeqCell; } else { foreach (int iIterCell in navicell.m_arriAdjCells) { if (CNAVICELL.NULL_CELL != iIterCell) { bIntersectedCell = m_arrNavicells[iIterCell].trilinkcell.IntersectRayTri(v3RayOrigin, v3RayDir, ref posIntersected_out); if (true == bIntersectedCell) { iIdxIntersectedCell = iIterCell; break; } } // if (CNAVICELL.NULL_CELL != iSeqCell) } // foreach(int iSeqCellNavi in navicell.m_arriAdjCells) } // if (true == bIntersectedCell) return(iIdxIntersectedCell); } // public bool intersectRay_inAdjs(int iSeqCell, Vector3 v3RayOrigin, Vector3 v3RayDir, ref Vector3 posIntersected_out)
//@ Construct Triangle public bool InsertNewTri(int iSeqTri, CTRI tri_in, bool bConfirm) { bool bAlreadyExisted = false; if (_listIdxTris.Count > 0) { bAlreadyExisted = (-1 < _listIdxTris.BinarySearch(iSeqTri)); } if (true == bAlreadyExisted) { return(false); } for (int iPnt = 0; iPnt < tri_in._arrv3PT.Length; ++iPnt) { _listv3PntsSrc.Add(tri_in._arrv3PT[iPnt]); } if (_listv3Pnts.Count < 1) { SetNewTri(iSeqTri, tri_in); } else { List <Vector3> listInsertPnt = new List <Vector3>(); bool bAlreadyPutin = false; for (int iPntTri = 0; iPntTri < 3; ++iPntTri) { Vector3 v3PntTri = tri_in._arrv3PT[iPntTri]; bAlreadyPutin = false; for (int iSeqPnt = 0; iSeqPnt < _listv3Pnts.Count; ++iSeqPnt) { Vector3 v3Pnt_ = _listv3Pnts[iSeqPnt]; if (CMATH.similarVector3_f2(v3PntTri, v3Pnt_)) { bAlreadyPutin = true; break; } } if (false == bAlreadyPutin) { listInsertPnt.Add(v3PntTri); } } // for(int iPntTri = 0; iPntTri < 3; ++iPntTri) if (listInsertPnt.Count > 0) { if (listInsertPnt.Count == tri_in._arrv3PT.Length) { Debug.Log("(Wrong value.//listInsertPnt.Count > 0)//(listInsertPnt.Count == tri_in._arrv3PT.Length)//"); } for (int iSeq = 0; iSeq < listInsertPnt.Count; ++iSeq) { Vector3 v3Pnt = listInsertPnt[iSeq]; _listv3Pnts.Add(v3Pnt); } listInsertPnt.Clear(); } // if(listInsertPnt.Count>0) _listIdxTris.Add(iSeqTri); _listIdxTris.Sort(); } // if(_listv3Pnts.Count<1) tri_in.SetBaseLinked(this); return(true); } // public void InsertNewTri(int iSeqTri, CTRI tri_in)
public bool crossoverTest(Vector3 posTestStart, Vector3 posTestEnd) { bool bcrossOver = CMATH.crossOverDest(_posCenterCell, _postoDest, posTestEnd); return(bcrossOver); }
} // public bool intersectRay_inAdjs(int iSeqCell, Vector3 v3RayOrigin, Vector3 v3RayDir, ref Vector3 posIntersected_out) //@ Organize shortest way block edges only Current cell public bool setNaviPortal_forShortestWay(Vector2[] arrv2PntObjBoundary, ref CNAVICELL cellWayStart) { if (true == cellWayStart.useWaytoPortal) { return(true); } List <CNAVICELL> listSequenceCell = new List <CNAVICELL>(); collectWayToGoalLinear(m_arrNavicells, cellWayStart, ref listSequenceCell, ref m_computeEdgeBlock); if (listSequenceCell.Count < 2) { return(true); } Vector3 v3PntPrev = new Vector3(); Vector3 v3PntCurr = new Vector3(); Vector3 v3PntNext = new Vector3(); int iLenSeq = listSequenceCell.Count; int iSeqIteration = 0; CNAVICELL cellGOAL = listSequenceCell[iLenSeq - 1]; CNAVICELL cellNext, cellPrev; bool bCrosswithBlock = false; bool bSetNewPortalPosition = false; Vector3[] arrv3Pnt_Cell_start = new Vector3[cellWayStart.m_arrv3PT.Length]; Array.Copy(cellWayStart.m_arrv3PT, arrv3Pnt_Cell_start, cellWayStart.m_arrv3PT.Length); CMATH.rescaleVertices(ref arrv3Pnt_Cell_start, DFLT_ADJUST_SCALE_FOR_VISIBLECHECK); foreach (CNAVICELL cellCurr in listSequenceCell) { int iSeqCurr = iSeqIteration++; if (0 == iSeqCurr) { continue; } if (cellGOAL == cellCurr) { cellWayStart.SetPortalPosition(cellGOAL.seqCell, cellGOAL.getPos_cellCenter()); bSetNewPortalPosition = true; break; } cellPrev = listSequenceCell[iSeqCurr - 1]; cellNext = listSequenceCell[iSeqCurr + 1]; cellCurr.getPos_BestWay_onEdge(ref v3PntCurr); cellNext.getPos_BestWay_onEdge(ref v3PntNext); cellPrev.getPos_BestWay_onEdge(ref v3PntPrev); bCrosswithBlock = false; foreach (Vector3 v3PntCell in arrv3Pnt_Cell_start) { if (m_computeEdgeBlock.crossBlockIteration(v3PntCell, v3PntNext)) { bCrosswithBlock = true; break; } } //@ Set Portal if (true == bCrosswithBlock) { cellWayStart.SetPortalPosition(cellCurr.seqCell, v3PntCurr); bSetNewPortalPosition = true; break; } Vector2 v2PntNext = CMATH.ConvertToV2_Y(v3PntNext); foreach (Vector2 v2PntObj in arrv2PntObjBoundary) { //@ Cross At least 1 mo if (true == m_computeEdgeBlock.crossBlockIteration(v2PntObj, v2PntNext)) { bCrosswithBlock = true; break; } } //@ Set Portal -2 if (true == bCrosswithBlock) { cellWayStart.SetPortalPosition(cellCurr.seqCell, v3PntCurr); bSetNewPortalPosition = true; break; } } // foreach (CNAVICELL cellCurr in listSequenceCell) listSequenceCell.Clear(); listSequenceCell = null; return(bSetNewPortalPosition); } // public bool setNaviPortal_forShortestWay(int iSeqCell)
public bool DoesCrossEdge2D(Vector2 v2Pnt0_, Vector2 v2Pnt1_) { return(CMATH.lineCross2D(_v2Pnt0, _v2Pnt1, v2Pnt0_, v2Pnt1_)); }
} // public void SetEdge(Vector2 v2Pnt0_, Vector2 v2Pnt1_) //@ Check cross edge public bool DoesCrossEdge2D(EDGE__ edgeRight) { return(CMATH.lineCross2D(_v2Pnt0, _v2Pnt1, edgeRight._v2Pnt0, edgeRight._v2Pnt1)); } // public bool IsCrossEdge(EDGE__)