public void MoveDrop(MonoDrop movingDrop , Vector3 direction , ushort amountOfMovement) { if (null == movingDrop) { return; } //길이를 1로 만든다 (정규화) direction.Normalize (); Index2 placedIndex = movingDrop.index2D; Index2 nextIndex = movingDrop.index2D;; MonoDrop nextDrop = null; for (ushort aOm = 1; aOm <= amountOfMovement; aOm++) { nextIndex.ix += ((int)direction.x); nextIndex.iy += ((int)direction.y); nextDrop = this.mapDrop.GetMonoDropByIndex2 (nextIndex); //CDefine.DebugLog ("----------MoveDrop : "+ aOm +" :"+ nextIndex.ToString() + " drop:"+nextDrop ); //chamto test //if (null == nextDrop && this.boardInfo.BelongToViewArea (nextIndex)) if (null == nextDrop && this.boardInfo.BelongToArea (new Index2(0,0), new Index2(5,9), nextIndex)) { placedIndex = nextIndex; //CDefine.DebugLog ("----------MoveDrop : " + movingDrop.index2D + " placedIndex :" + placedIndex.ToString() + " v3:"+direction ); //chamto test continue; } break; } if (movingDrop.index2D != placedIndex) { //CDefine.DebugLog ("----------MoveToIndex : " + placedIndex.ToString() ); //chamto test //chamto test , temp code if(this.boardInfo.BelongToArea(new Index2(0,5),new Index2(5,9) ,movingDrop.index2D) && this.boardInfo.BelongToViewArea(placedIndex)) { movingDrop.SetColor(Color.white); movingDrop.GetBoxCollider2D().enabled = true; //20150212 chamto - 터치입력을 못받게 충돌체를 비활성 시켜 놓는다. } movingDrop.MoveToIndex (placedIndex); } }
public void AddMovedPath(MonoDrop drop) { if(null == drop) return; int prevAddedDropIdx = m_dtnrMovedPath.Count-1; if(0 <= prevAddedDropIdx) { //same object required if(drop == m_dtnrMovedPath.ElementAt(prevAddedDropIdx).Value) return; } CDefine.DebugLog("AddMovedPath : " + Time.fixedTime + " " + Time.time); m_dtnrMovedPath.Add(Time.time , drop); }
//------------------------------------------------------------------------ // currection method //------------------------------------------------------------------------ public ML.LineSegment3 CorrectionLineSegment(MonoDrop srcDrop , ML.LineSegment3 lineSeg3) { if (null == srcDrop) return lineSeg3; //Correction value //PairInt parameter is array index(0 start , 1 is not ). //Index2 startPos = PairInt.Start_C5_R0; Vector3 putPos_left_up = m_boardInfo.GetPositionAt_ViewLeftUp () + Single.UIRoot.transform.position; Vector3 putPos_right_up = m_boardInfo.GetPositionAt_ViewRightUp () + Single.UIRoot.transform.position; Vector3 putPos_left_bottom = m_boardInfo.GetPositionAt_ViewLeftBottom () + Single.UIRoot.transform.position; Vector3 putPos_right_bottom = m_boardInfo.GetPositionAt_ViewRightBottom () + Single.UIRoot.transform.position; //Vector3 putPos_left_up = GetPositionOfPutDrop (new PairInt (0, 0)); //Vector3 putPos_right_up = GetPositionOfPutDrop (new PairInt (0, (int)ConstBoard.Max_Row-1)); //Vector3 putPos_left_bottom = GetPositionOfPutDrop (new PairInt ((int)ConstBoard.Max_Column-1, 0)); //Vector3 putPos_right_bottom = GetPositionOfPutDrop (new PairInt ((int)ConstBoard.Max_Column-1, (int)ConstBoard.Max_Row-1)); #if UNITY_EDITOR //------------------------------------------------------------------------- //20140906 chamto test //------------------------------------------------------------------------- Single.MonoDebug.cube_LeftUp.transform.position = putPos_left_up; Single.MonoDebug.cube_RightUp.transform.position = putPos_right_up; Single.MonoDebug.cube_LeftBottom.transform.position = putPos_left_bottom; Single.MonoDebug.cube_RightBottom.transform.position = putPos_right_bottom; //------------------------------------------------------------------------- #endif Bounds bob = m_boardInfo.GetBoundaryOfView (Single.UIRoot.transform.position); ML.LineSegment3 result = new ML.LineSegment3(); result.origin = srcDrop.gotoWorldPosition; result.last = lineSeg3.last; //CDefine.DebugLog ("Bounds " + bob + bob.min + bob.max); if (lineSeg3.last.y >= bob.max.y) { //------------- correction up ------------- //CDefine.DebugLog("----correction up"); result.last_y = putPos_left_up.y; if(lineSeg3.last.x <= bob.min.x) { //correction left-up result.last = putPos_left_up; //CDefine.DebugLog("----correction left up" + putPos_left_up); } if(lineSeg3.last.x >= bob.max.x) { //correction right-up result.last = putPos_right_up; //CDefine.DebugLog("----correction right up"); } }else if (lineSeg3.last.y <= bob.min.y) { ////------------- correction bottom ------------- //CDefine.DebugLog("----correction bottom"); result.last_y = putPos_left_bottom.y; if(lineSeg3.last.x <= bob.min.x) { //correction left-bottom result.last = putPos_left_bottom; //CDefine.DebugLog("----correction left bottom"+putPos_left_bottom); } if(lineSeg3.last.x >= bob.max.x) { //correction right-bottom result.last = putPos_right_bottom; //CDefine.DebugLog("----correction right bottom"); } }else if(lineSeg3.last.x <= bob.min.x) { ////------------- correction left ------------- result.last_x = putPos_left_up.x; //CDefine.DebugLog("----correction left"); }else if(lineSeg3.last.x >= bob.max.x) { ////------------- correction right ------------- result.last_x = putPos_right_up.x; //CDefine.DebugLog("----correction right"); }else { ////------------- correction is not required //CDefine.DebugLog("----correction is not required"); return lineSeg3; } //CDefine.DebugLog ("Correction LineSegement : " + result); return result; }
public bool ValidSwapMonoDrop (MonoDrop drop1, MonoDrop drop2) { if (null == drop1 || null == drop2) return false; //피타고라스 정리 [가로*가로 + 세로*세로 = 빗변*빗변] 를 이용하여 직각삼각형의 빗변을 구함 //구할려는 삼각형의 가로,세로길이가 같기 때문에 식을 다음과 같이 정리 //빗변*빗변 = 가로*가로*2 //실수값을 비교, 오차가 발생할것이기 떄문에 가중치값을 더함 //빗변*빗변 = 가로*가로*2 + 가중치 //float dist = m_board.squareWidth * m_board.squareWidth * 2 + 0.15f; float dist = (m_boardInfo.squareWidth * m_boardInfo.squareWidth + m_boardInfo.squareHeight * m_boardInfo.squareHeight) + 0.15f; return (dist > GetSqrDistance (drop1.gotoWorldPosition, drop2.gotoWorldPosition)); }
public bool SetValue(Index2 keyIndex , MonoDrop valueDrop) { if (null != valueDrop && valueDrop.index2D != keyIndex) { CDefine.DebugLog("Warring !!! : valueDrop.index2D != keyIndex : " + valueDrop.index2D + " " + keyIndex); return false; } MonoDrop getValue = null; if (false == _mapIndex2.TryGetValue (keyIndex, out getValue)) { _mapIndex2.Add(keyIndex, valueDrop); } _mapIndex2[keyIndex] = valueDrop; return true; }
//==============: override method:======================================================================================== public bool Add(int key, MonoDrop value) { if (null == value) { Debug.LogError("Add : null == value"); return false; } //----------------------- //add this if (_mapId.ContainsKey (key)) { _mapId [key] = value; } else { _mapId.Add (key, value); } //----------------------- //add mapIndex2 if (_mapIndex2.ContainsKey (value.index2D)) { _mapIndex2[value.index2D] = value; }else { //CDefine.DebugLog("value.index2D : " + value.index2D); //chamto test _mapIndex2.Add (value.index2D, value); } return true; }
//chamto noUsed function !! //chamto need Optimization !! public MonoDrop CalcCollision(MonoDrop srcDrop) { const float BOX_WIDTH = 0.57f; const float BOX_HEIGHT = 0.57f; if(null == srcDrop) return null; Rect srcBox = new Rect(); Rect dstBox = new Rect(); srcBox.width = BOX_WIDTH; srcBox.height = BOX_HEIGHT; srcBox.center = new Vector2(srcDrop.transform.position.x,srcDrop.transform.position.y); dstBox = srcBox; foreach(MonoDrop dstDrop in m_mapDrop.DtnrId.Values) { //self exclusion if(srcDrop == dstDrop) continue; //dstBox.center = new Vector2(dstDrop.transform.position.x,dstDrop.transform.position.y); dstBox.center = new Vector2(dstDrop.gotoWorldPosition.x , dstDrop.gotoWorldPosition.y); if(true == srcBox.Overlaps(dstBox,true)) //include allowInverse { return dstDrop; } } return null; }
//-------------------------------------------------- //idMap 자료구조와 indexMap 자료구조는 1대1 대응하지 않는다. //예) 특정 드롭이 등록되지 않은 위치로 갈때 indexMap에 추가되게 된다. // 이때 idMap은 드롭이 추가된것이 아니기 때문에 변동이 없다. private void notuse_UpdateValue(MonoDrop valueDrop , Index2 prevIndex) { if (null == valueDrop) { CDefine.DebugLog("Error !!: null == valueDrop"); return; } MonoDrop getValue = null; if (_mapId.TryGetValue (valueDrop.id, out getValue) && getValue == valueDrop) { //Add index2Coord in mapIndex2 if index2 is not register if (false == _mapIndex2.TryGetValue (valueDrop.index2D, out getValue)) { _mapIndex2.Add(valueDrop.index2D, valueDrop); } MonoDrop prevPlacedDrop = _mapIndex2[valueDrop.index2D]; _mapIndex2[valueDrop.index2D] = valueDrop; } }
//new multi CCD collision functuon - 20140619 chamto public List<MonoDrop> CalcCCDCollision(MonoDrop srcDrop, float nonCollision_minDistance) { if (null == srcDrop) return null; //1.터치드래그한 선분을 구한다. ML.LineSegment3 ls3 = new ML.LineSegment3 (); //ls3.origin = srcDrop.transform.position; ls3.origin = srcDrop.gotoWorldPosition; ls3.last = Input_Unity.GetTouchWorldPos (); //1.1.드롭판을 벗어난 터치선을 보정한다. ls3 = this.CorrectionLineSegment (srcDrop, ls3); //1.2.터치선이 2차원 상에 있게 한다. ls3.origin.z = 0; ls3.direction.z = 0; #if UNITY_EDITOR //------------------------------------------------------------------------- //20140906 chamto - test //------------------------------------------------------------------------- Single.MonoDebug.lineRender.SetWidth (0.1f, 0.4f); Single.MonoDebug.lineRender.SetPosition (0, ls3.origin); Single.MonoDebug.lineRender.SetPosition (1, ls3.direction + ls3.origin); Single.MonoDebug.lineRender.useWorldSpace = false; //------------------------------------------------------------------------- #endif //2. 3. 모든드롭에 대해 전수 조사한다. (선분 근처 드롭만 조사하게 최적화 필요) //SortedDictionary<float , MonoDrop> collisionDtnr = new Dictionary<float , MonoDrop> (); List<MonoDrop> collisionList = new List<MonoDrop> (); float t_c = 0.0f; foreach (MonoDrop dstDrop in m_mapDrop.DtnrId.Values) { //self exclusion if(srcDrop == dstDrop) continue; if((nonCollision_minDistance * nonCollision_minDistance) > ls3.MinimumDistanceSquared(dstDrop.gotoWorldPosition,out t_c)) { //20140907 chamto test // float dist = ls3.MinimumDistanceSquared(dstDrop.gotoWorldPosition,out t_c); // { // CDefine.DebugLog("object : "+dstDrop +" mSqrtDist : "+dist + " noncSqrtDist : " + nonCollision_minDistance * nonCollision_minDistance + " gotowp : "+dstDrop.gotoWorldPosition + " t_c : " + t_c); // } //Input collision list collisionList.Add(dstDrop); } } //4.선분과 충돌한 드롭목록을 “선분의 시작점에서 충돌드롭의 중점 까지의 거리”를 기준으로 오름차순 정렬한다. // collisionDtnr = (from pairObj in collisionDtnr // orderby pairObj.Key ascending // select pairObj).ToDictionary (v1 => v1.Key,v1 => v1.Value); List<MonoDrop> result = (from dstDrop in collisionList orderby GetSqrDistance(srcDrop.gotoWorldPosition,dstDrop.gotoWorldPosition) ascending select dstDrop).ToList(); // CDefine.DebugLog ("----- line ----- ori :" + ls3.origin + " last : " + ls3.last + " dict : " + ls3.direction); //chamto test //20150331 chamto test if (0 != result.Count) { string sss = ""; foreach(MonoDrop mm in result) { sss += mm.index2D.ToString() + " | "; } CDefine.DebugLog (sss); } return result; }
/// <summary> /// Gets the shortest distance. /// </summary> /// <returns>The shortest distance.</returns> /// <param name="standardDrop">Standard drop.</param> /// <param name="minDistance">최소거리의 최소값을 지정. 최소값이 5라면, 최소거리는 적어도 5보다 같거나 커야한다.</param> public MonoDrop GetShortestDistance(MonoDrop standardDrop, float minDistance) { if(null == standardDrop || 0 >= minDistance) return null; if(0 == m_mapDrop.DtnrId.Count) return null; List<MonoDrop> list = m_mapDrop.DtnrId.Values.ToList(); //list.Remove(standardDrop); //deduplicate //list.Sort(SortDistanceCompareTo); //기준점으로 부터 제곱길이가 가장 작은순으로 정렬한 드롭목록을 얻는다. list = (from dstDrop in list orderby GetSqrDistance(standardDrop.gotoWorldPosition,dstDrop.gotoWorldPosition) ascending select dstDrop).ToList(); //foreach(MonoDrop drop in list) // CDefine.DebugLog(drop + " " + Math.Sqrt(GetSqrDistance(standardDrop,drop))); //CDefine.DebugLog(GetSqrDistance(standardDrop,list[0]) + " " + (minDistance*minDistance)); //chamto test if(GetSqrDistance(standardDrop.gotoWorldPosition,list[0].gotoWorldPosition) <= (minDistance * minDistance)) return null; //if(standardDrop == list[0]) return null; return list[0]; }
//==============: factory method :======================================================================================== static public bool Remove(MonoDrop drop) { if (null == drop) return false; Single.DropMgr.mapDrop.Remove (drop.id); //drop.SetColor(new Color(1,1,1,0.2f)); //drop.GetBoxCollider2D().enabled = false; //drop.gameObject.SetActive(false); MonoBehaviour.Destroy(drop.gameObject); //20150403 chamto test Single.DropMgr.Update_DebugMap (); return true; }
void OnCollision() { //const float NONCOLLISION_MIN_DISTANCE = 0.55f; const float NONCOLLISION_MIN_DISTANCE = 0.55f; List<MonoDrop> colList = Single.DropMgr.CalcCCDCollision (this, NONCOLLISION_MIN_DISTANCE); MonoDrop lastDrop = null; if (0 < colList.Count) { lastDrop = colList[colList.Count-1]; //CDefine.DebugLog ("collisionList Count : "+ colList.Count + " " + lastDrop); //chamto test } foreach (MonoDrop dstDrop in colList) { if(_prevLastCollisionDrop == dstDrop) return; //one treatment , avoidance continuous collision if(null != dstDrop && this != dstDrop) { //Debug.Log("--------- onCollision ---------"); //chamto test //moving complete after process //1.stop move animation if(null != _prevLastCollisionDrop) _prevLastCollisionDrop.StopAni(); dstDrop.StopAni(); //2.setting target position //swap gotoPostion //Single.DropMgr.SwapgotoLocalPosition(this,dstDrop); Single.DropMgr.SwapMonoDropInBoard(this.id , dstDrop.id, false); //break; //3.animation target drop //rolling drop dstDrop.MovingAni(dstDrop.gotoLocalPosition); } } _prevLastCollisionDrop = lastDrop; }
public void SwapgotoLocalPosition (MonoDrop dstDrop) { if (null != dstDrop) { Vector3 dstLocalPos = dstDrop.gotoLocalPosition; dstDrop.gotoLocalPosition = this.gotoLocalPosition; this.gotoLocalPosition = dstLocalPos; } }