/** * InsidePolygon * * @param verts * @param num * @param pt * @param ray * @return boolean */ private bool InsidePolygon(Point[] verts, int num, Point pt, Ray ray) { int cross = 0; int xindex, yindex, index = 0; double xtest, ytest, x0, y0, x1, y1; if (MaxComp == 0) { xindex = 1; yindex = 2; xtest = pt.GetY(); ytest = pt.GetZ(); } else if (MaxComp == 1) { xindex = 0; yindex = 2; xtest = pt.GetX(); ytest = pt.GetZ(); } else { xindex = 0; yindex = 1; xtest = pt.GetX(); ytest = pt.GetY(); } x0 = GetCoord(verts[num - 1], xindex) - xtest; y0 = GetCoord(verts[num - 1], yindex) - ytest; while (num-- != 0) { x1 = GetCoord(verts[index], xindex) - xtest; y1 = GetCoord(verts[index], yindex) - ytest; if (y0 > 0.0f) { if (y1 <= 0.0f) { if (x1 * y0 > y1 * x0) { cross++; } } } else { if (y1 > 0.0f) { if (x0 * y1 > y0 * x1) { cross++; } } } x0 = x1; y0 = y1; index++; } return((cross & 1) == 1); }
/** * InsidePolygon * * @param verts * @param num * @param pt * @param ray * @return boolean */ private bool InsidePolygon(Point[] verts, int num, Point pt, Ray ray) { int cross = 0; int xindex, yindex, index = 0; double xtest, ytest, x0, y0, x1, y1; if(MaxComp == 0) { xindex = 1; yindex = 2; xtest = pt.GetY(); ytest = pt.GetZ(); } else if(MaxComp == 1) { xindex = 0; yindex = 2; xtest = pt.GetX(); ytest = pt.GetZ(); } else { xindex = 0; yindex = 1; xtest = pt.GetX(); ytest = pt.GetY(); } x0 = GetCoord(verts[num - 1], xindex) - xtest; y0 = GetCoord(verts[num - 1], yindex) - ytest; while(num-- != 0) { x1 = GetCoord(verts[index], xindex) - xtest; y1 = GetCoord(verts[index], yindex) - ytest; if(y0 > 0.0f) { if(y1 <= 0.0f) { if(x1 * y0 > y1 * x0) { cross++; } } } else { if(y1 > 0.0f) { if(x0 * y1 > y0 * x1) { cross++; } } } x0 = x1; y0 = y1; index++; } return ((cross & 1) == 1); }
public void MarkWall(Point Mappos) { if (wall == false && Map[Mappos.GetX()][Mappos.GetY()][Mappos.GetZ()].Passable == true) { Map[Mappos.GetX() + 1][Mappos.GetY()][Mappos.GetZ()].GetComponent <Renderer>().material = Map[Mappos.GetX() + 1][Mappos.GetY()][Mappos.GetZ()].mat_move; Map[Mappos.GetX() + 1][Mappos.GetY()][Mappos.GetZ()].At_Marked = true; Map[Mappos.GetX()][Mappos.GetY()][Mappos.GetZ() + 1].GetComponent <Renderer>().material = Map[Mappos.GetX() + 1][Mappos.GetY()][Mappos.GetZ()].mat_move; Map[Mappos.GetX()][Mappos.GetY()][Mappos.GetZ() + 1].At_Marked = true; wall = true; wallpos = Mappos; } }
static public void Test_A2(Point point) { double x = point.GetX(); double y = point.GetY(); double z = point.GetZ(); Debug.Assert(Program.IsApprox(x, 636784.74, 0.01)); Debug.Assert(Program.IsApprox(y, 849106.66, 0.01)); Debug.Assert(Program.IsApprox(z, 426.71, 0.01)); double time = point.GetTime(); Debug.Assert(Program.IsApprox(time, 245382.13595, 0.00001)); Debug.Assert(point.GetIntensity() == 118); Debug.Assert(point.GetReturnNumber() == 1); Debug.Assert(point.GetNumberOfReturns() == 1); Classification classif = point.GetClassification(); Debug.Assert(classif.GetClassName() == "Unclassified"); Debug.Assert(!classif.IsKeyPoint()); Debug.Assert(!classif.IsSynthetic()); Debug.Assert(!classif.IsWithheld()); Color color = point.GetColor(); Debug.Assert(color.GetRed() == 112); Debug.Assert(color.GetGreen() == 97); Debug.Assert(color.GetBlue() == 114); }
/** * Combine * * @param pt * @param vector * @param ptscale * @param vecscale * @return Point */ public Point Combine(Point pt, Vector vector, double ptscale, double vecscale) { x = ptscale * pt.GetX() + vecscale * vector.GetX(); y = ptscale * pt.GetY() + vecscale * vector.GetY(); z = ptscale * pt.GetZ() + vecscale * vector.GetZ(); return(this); }
public int GetDistance(Hex h1, Hex h2) { Point pos1 = h1.MapPos; Point pos2 = h2.MapPos; return((int)(Mathf.Sqrt(Mathf.Pow(pos1.GetX() - pos2.GetX(), 2) + Mathf.Pow((pos1.GetZ() - pos2.GetZ()), 2)))); // return((pos1.GetX() - pos2.GetX())+( pos1.GetZ() - pos2.GetZ())); }
/** * FindCorner * * @param view * @param up * @param plane * @param origin */ public void FindCorner(Vector view, Vector up, Vector plane, Point origin) { x = origin.GetX(); y = origin.GetY(); z = origin.GetZ(); Add(view); Add(up); Add(plane); }
public void MarkTile(Point pos, int range, Hex hex) { int highLighedCount = 0; Point start = pos; if (PlayerManager.GetInst().Players[PlayerManager.GetInst().CurTurnIdx].act == ACT.IDLE) { for (int x = 0; x <= MapSizeX; x++) { for (int y = 0; y <= MapSizeY; y++) { for (int z = 0; z <= MapSizeZ; z++) { //int distance = (GetDistance(hex, Map[x][y][z])); //헥사곤 상의 셀과 셀간의 공식 //if (distance <= range && distance != 0) //{ // Map[x][y][z].GetComponent<Renderer>().material.color = Color.green; // if (Map[x][y][z].GetComponent<Renderer>().material.color == Color.green) // highLighedCount++; // } } } } // for(int i=0;i<5;++i) // Map[s_x][s_y][s_z+i].GetComponent<Renderer>().material.color = Color.green; if (highLighedCount == 0) { Map[pos.GetX()][pos.GetY()][pos.GetZ()].GetComponent <Renderer>().material = Map[pos.GetX() + 1][pos.GetY()][pos.GetZ()].mat_move; } else { ResetMapColor(); Map[pos.GetX()][pos.GetY()][pos.GetZ()].GetComponent <Renderer>().material = Map[pos.GetX() + 1][pos.GetY()][pos.GetZ()].mat_move;; } } }
public void ResetMapColor(Point pos) { int x = pos.GetX(); int y = pos.GetY(); int z = pos.GetZ(); Map[x][y][z].GetComponent <Renderer>().material.color = Map[x][y][z].mat_color; Map[x][y][z].Marked = false; Map[x][y][z].At_Marked = false; wall = false; }
/** * SphereObj * * @param objmaterial * @param newobjID * @param neworigin * @param newradius * @param MaxX * @param MinX * @param MaxY * @param MinY * @param MaxZ * @param MinZ */ public SphereObj(Material objmaterial, int newobjID, Point neworigin, double newradius, Point max, Point min) : base(objmaterial, newobjID) { Origin = neworigin; Radius = newradius; RadiusSquare = Radius * Radius; GetMax().SetX(Origin.GetX() + Radius); GetMax().SetY(Origin.GetY() + Radius); GetMax().SetZ(Origin.GetZ() + Radius); GetMin().SetX(Origin.GetX() - Radius); GetMin().SetY(Origin.GetY() - Radius); GetMin().SetZ(Origin.GetZ() - Radius); if(GetMax().GetX() > max.GetX()) { max.SetX(GetMax().GetX()); } if(GetMax().GetY() > max.GetY()) { max.SetY(GetMax().GetY()); } if(GetMax().GetZ() > max.GetZ()) { max.SetZ(GetMax().GetZ()); } if(GetMin().GetX() < min.GetX()) { min.SetX(GetMin().GetX()); } if(GetMin().GetY() < min.GetY()) { min.SetY(GetMin().GetY()); } if(GetMin().GetZ() < min.GetZ()) { min.SetZ(GetMin().GetZ()); } }
/** * SphereObj * * @param objmaterial * @param newobjID * @param neworigin * @param newradius * @param MaxX * @param MinX * @param MaxY * @param MinY * @param MaxZ * @param MinZ */ public SphereObj(Material objmaterial, int newobjID, Point neworigin, double newradius, Point max, Point min) : base(objmaterial, newobjID) { Origin = neworigin; Radius = newradius; RadiusSquare = Radius * Radius; GetMax().SetX(Origin.GetX() + Radius); GetMax().SetY(Origin.GetY() + Radius); GetMax().SetZ(Origin.GetZ() + Radius); GetMin().SetX(Origin.GetX() - Radius); GetMin().SetY(Origin.GetY() - Radius); GetMin().SetZ(Origin.GetZ() - Radius); if (GetMax().GetX() > max.GetX()) { max.SetX(GetMax().GetX()); } if (GetMax().GetY() > max.GetY()) { max.SetY(GetMax().GetY()); } if (GetMax().GetZ() > max.GetZ()) { max.SetZ(GetMax().GetZ()); } if (GetMin().GetX() < min.GetX()) { min.SetX(GetMin().GetX()); } if (GetMin().GetY() < min.GetY()) { min.SetY(GetMin().GetY()); } if (GetMin().GetZ() < min.GetZ()) { min.SetZ(GetMin().GetZ()); } }
/** * GetCoord * * @param pt * @param index * @return double */ private double GetCoord(Point pt, int index) { if (index == 0) { return(pt.GetX()); } else if (index == 1) { return(pt.GetY()); } else { return(pt.GetZ()); } }
public List <Hex> GetNeibhors(Hex pos) { List <Hex> rtn = new List <Hex>(); Point cur = pos.MapPos; if (pos.Passable == false) { return(rtn); } foreach (Point p in Dirs) { Point tmp = p + cur; rtn.Add(MapManager.GetInst().GetHex(tmp.GetX(), tmp.GetY(), tmp.GetZ())); } return(rtn); }
/** * ReadSphere * * @param infile * @param ObjID * @return int */ private int ReadSphere(int ObjID) { String temp; double[] input = new double[3]; int i; double radius; Point max = new Point(MaxX, MaxY, MaxZ); Point min = new Point(MinX, MinY, MinZ); temp = readString(); temp = readString(); Material theMaterial = ReadMaterial(); temp = readString(); temp = temp.Substring(9); for (i = 0; i < 2; i++) { input[i] = (double)Double.Parse(temp.Substring(0, temp.IndexOf(' '))); temp = temp.Substring(temp.IndexOf(' ') + 1); } input[2] = (double)Double.Parse(temp); Point origin = new Point(input[0], input[1], input[2]); temp = readString(); temp = temp.Substring(9); radius = (double)Double.Parse(temp); for (i = 0; i < 7; i++) { temp = readString(); } SphereObj newsphere = new SphereObj(theMaterial, ++ObjID, origin, radius, max, min); ObjNode newnode = new ObjNode(newsphere, objects); objects = newnode; MaxX = max.GetX(); MaxY = max.GetY(); MaxZ = max.GetZ(); MinX = min.GetX(); MinY = min.GetY(); MinZ = min.GetZ(); return(1); }
/** * ReadPoly * * @param infile * @param ObjID * @return int */ private int ReadPoly(int ObjID) { String temp; double[] input = new double[3]; int i, j, k; int numpolys = 0; int numverts; bool trimesh, vertnormal; Point max = new Point(MaxX, MaxY, MaxZ); Point min = new Point(MinX, MinY, MinZ); temp = readString(); temp = readString(); Material theMaterial = ReadMaterial(); temp = readString(); if(temp.Substring(7).Equals("POLYSET_TRI_MESH")) { trimesh = true; } else { trimesh = false; } temp = readString(); if(temp.Substring(11).Equals("PER_VERTEX_NORMAL")) { vertnormal = true; } else { vertnormal = false; } for(i = 0; i < 4; i++) { temp = readString(); } temp = temp.Substring(11); numpolys = Int32.Parse(temp); ObjID++; for(i = 0; i < numpolys; i++) { temp = readString(); temp = readString(); temp = temp.Substring(16); numverts = Int32.Parse(temp); Point[] vertices = new Point[numverts]; for(j = 0; j < numverts; j++) { temp = readString(); temp = temp.Substring(8); for(k = 0; k < 2; k++) { input[k] = (double)Double.Parse(temp.Substring(0, temp.IndexOf(' '))); temp = temp.Substring(temp.IndexOf(' ') + 1); } input[2] = (double)Double.Parse(temp); vertices[j] = new Point(input[0], input[1], input[2]); if(vertnormal) { temp = readString(); } } temp = readString(); TriangleObj newtriangle; PolygonObj newpoly; ObjNode newnode; if(trimesh) { newtriangle = new TriangleObj(theMaterial, ObjID, numverts, vertices, max, min); newnode = new ObjNode(newtriangle, objects); } else { newpoly = new PolygonObj(theMaterial, ObjID, numverts, vertices, max, min); newnode = new ObjNode(newpoly, objects); } objects = newnode; } temp = readString(); MaxX = max.GetX(); MaxY = max.GetY(); MaxZ = max.GetZ(); MinX = min.GetX(); MinY = min.GetY(); MinZ = min.GetZ(); return (numpolys); }
/** * RenderScene */ public void RenderScene(Canvas canvas, int width, int section, int nsections) { Vector view = camera.GetViewDir(); Vector up = camera.GetOrthoUp(); Vector plane = new Vector(); Vector horIncr = new Vector(); Vector vertIncr = new Vector(); double ylen = camera.GetFocalDist() * (double)Math.Tan(0.5f * camera.GetFOV()); double xlen = ylen * canvas.GetWidth() / canvas.GetHeight(); Point upleft = new Point(); Point upright = new Point(); Point lowleft = new Point(); Point basepoint = new Point(); Point current; Ray eyeRay = new Ray(); int ypixel, xpixel; RayID = 1; plane.Cross(view, up); view.Scale(camera.GetFocalDist()); up.Scale(ylen); plane.Scale(-xlen); upleft.FindCorner(view, up, plane, camera.GetPosition()); plane.Negate(); upright.FindCorner(view, up, plane, camera.GetPosition()); up.Negate(); plane.Negate(); lowleft.FindCorner(view, up, plane, camera.GetPosition()); horIncr.Sub(upright, upleft); horIncr.Scale(horIncr.Length() / ((double)canvas.GetWidth())); vertIncr.Sub(lowleft, upleft); vertIncr.Scale(vertIncr.Length() / ((double)canvas.GetHeight())); basepoint.Set(upleft.GetX() + 0.5f * (horIncr.GetX() + vertIncr.GetX()), upleft.GetY() + 0.5f * (horIncr.GetY() + vertIncr.GetY()), upleft.GetZ() + 0.5f * (horIncr.GetZ() + vertIncr.GetZ())); eyeRay.SetOrigin(camera.GetPosition()); int xstart = section * width / nsections; int xend = xstart + width / nsections; Console.WriteLine("+" + xstart + " to " + (xend - 1) + " by " + canvas.GetHeight()); for(ypixel = 0; ypixel < canvas.GetHeight(); ypixel++) { current = new Point(basepoint); for(xpixel = 0; xpixel < canvas.GetWidth(); xpixel++) { if(xpixel >= xstart && xpixel < xend) { Color color = new Color(0.0f, 0.0f, 0.0f); eyeRay.GetDirection().Sub(current, eyeRay.GetOrigin()); eyeRay.GetDirection().Normalize(); eyeRay.SetID(RayID); this.RayID = this.RayID + 1; Shade(octree, eyeRay, color, 1.0f, 0, 0); canvas.Write(Brightness, xpixel, ypixel, color); } current.Add(horIncr); } basepoint.Add(vertIncr); } Console.WriteLine("-" + xstart + " to " + (xend - 1) + " by " + canvas.GetHeight()); }
/** * Point * * @param newpoint */ public Point (Point newpoint) { Set (newpoint.GetX (), newpoint.GetY (), newpoint.GetZ ()); }
public void MoveToNearUserPlayer(PlayerBase aiplayer) { PlayerManager pm = PlayerManager.GetInst(); MapManager mm = MapManager.GetInst(); PlayerBase nearUserPlayer = null; int nearDistance = 50; //근접 플레이어 서치 int i = Random.Range(1, 5); foreach (PlayerBase up in pm.Players) { if (up is UserPlayer) { int distance = mm.GetDistance(up.CurHex, aiplayer.CurHex); if (nearDistance > distance) { nearUserPlayer = up; nearDistance = distance; } } } if (aiplayer.m_type == Type.MONSTER || CostManager.GetInst().enemy_cost_num < 3) { if (nearUserPlayer != null) { List <Hex> path = mm.GetPath(aiplayer.CurHex, nearUserPlayer.CurHex); if (path == null) { PlayerManager.GetInst().TurnOver(); } else { if (path.Count > aiplayer.status.MoveRange) { path.RemoveRange(aiplayer.status.MoveRange, path.Count - aiplayer.status.MoveRange); } aiplayer.MoveHexes = path; if (nearUserPlayer.CurHex.MapPos == aiplayer.MoveHexes[aiplayer.MoveHexes.Count - 1].MapPos) { aiplayer.MoveHexes.RemoveAt(aiplayer.MoveHexes.Count - 1); } if (aiplayer.MoveHexes.Count == 0) { AtkAItoUser(aiplayer); return; } aiplayer.act = ACT.MOVING; } MapManager.GetInst().ResetMapColor(aiplayer.CurHex.MapPos); } } else if (CostManager.GetInst().enemy_cost_num >= 3 && CostManager.GetInst().enemy_cost_num < 5 && aiplayer.m_type == Type.BOSS) { List <Hex> path = mm.GetPath(aiplayer.CurHex, nearUserPlayer.CurHex); if (path == null) { PlayerManager.GetInst().TurnOver(); } Point v = aiplayer.CurHex.MapPos; int su_x = 0; int su_y = 0; for (int j = 0; j < MapManager.GetInst().MapSizeX; ++j) { for (int k = 0; k < MapManager.GetInst().MapSizeZ; ++k) { int x = Random.Range(-3, 3); int z = Random.Range(-3, 3); x = v.GetX() + x; z = v.GetZ() + z; if ((int)x > MapManager.GetInst().MapSizeX) { x = MapManager.GetInst().MapSizeX - 1; } if ((int)z > MapManager.GetInst().MapSizeZ) { z = MapManager.GetInst().MapSizeZ - 1; } if ((int)x <= 0) { x = 1; } if ((int)z <= 0) { z = 1; } if (MapManager.GetInst().Map[x][0][z].Passable == true) { su_x = x; su_y = z; break; } } } PlayerManager.GetInst().GenAIPlayer(su_x, su_y); EffectManager.GetInst().ShowEffect_Summon(aiplayer.CurHex.gameObject, 6, 0f); CostManager.GetInst().enemy_cost_num -= 3; //PlayerManager.GetInst().TurnOver(); } else if (CostManager.GetInst().enemy_cost_num < 8 && aiplayer.m_type == Type.BOSS) { aiplayer.act = ACT.CASTING; EffectManager.GetInst().ShowEffect_Summon(aiplayer.CurHex.gameObject, 9, 0.0f); CostManager.GetInst().enemy_cost_num -= 5; PlayerManager.GetInst().TurnOver(); } else { if (aiplayer.m_type == Type.BOSS) { List <Hex> path = mm.GetPath(aiplayer.CurHex, nearUserPlayer.CurHex); if (path == null) { PlayerManager.GetInst().TurnOver(); } Vector3 v = aiplayer.transform.position; if (path.Count < 5) { if (CostManager.GetInst().enemy_cost_num > 5) { aiplayer.act = ACT.CASTING; EffectManager.GetInst().ShowEffect_Summon(aiplayer.CurHex.gameObject, 9, 0.0f); CostManager.GetInst().enemy_cost_num -= 5; PlayerManager.GetInst().TurnOver(); } } else { if (nearUserPlayer != null) { if (path == null) { PlayerManager.GetInst().TurnOver(); } else { if (path.Count > aiplayer.status.MoveRange) { path.RemoveRange(aiplayer.status.MoveRange, path.Count - aiplayer.status.MoveRange); } aiplayer.MoveHexes = path; if (nearUserPlayer.CurHex.MapPos == aiplayer.MoveHexes[aiplayer.MoveHexes.Count - 1].MapPos) { aiplayer.MoveHexes.RemoveAt(aiplayer.MoveHexes.Count - 1); } if (aiplayer.MoveHexes.Count == 0) { AtkAItoUser(aiplayer); return; } aiplayer.act = ACT.MOVING; } MapManager.GetInst().ResetMapColor(aiplayer.CurHex.MapPos); } } Point p = aiplayer.CurHex.MapPos; int su_x = 0; int su_y = 0; for (i = 0; i < 2; ++i) { for (int j = 0; j < MapManager.GetInst().MapSizeX; ++j) { for (int k = 0; k < MapManager.GetInst().MapSizeZ; ++k) { int x = Random.Range(-3, 3); int z = Random.Range(-3, 3); x = p.GetX() + x; z = p.GetZ() + z; if ((int)x > MapManager.GetInst().MapSizeX) { x = MapManager.GetInst().MapSizeX - 1; } if ((int)z > MapManager.GetInst().MapSizeZ) { z = MapManager.GetInst().MapSizeZ - 1; } if ((int)x <= 0) { x = 1; } if ((int)z <= 0) { z = 1; } if (MapManager.GetInst().Map[x][0][z].Passable == true) { su_x = x; su_y = z; break; } } } PlayerManager.GetInst().GenAIPlayer(su_x, su_y); EffectManager.GetInst().ShowEffect_Summon(aiplayer.CurHex.gameObject, 6, 0f); CostManager.GetInst().enemy_cost_num -= 3; } } } }
/** * FindTreeNode * * @param point * @return OctNode */ public OctNode FindTreeNode(Point point) { OctNode found; if(point.GetX() < OctFaces[MINX].GetVert(0).GetX() || point.GetX() >= OctFaces[MAXX].GetVert(0).GetX()) { return (null); } if(point.GetY() < OctFaces[MINY].GetVert(0).GetY() || point.GetY() >= OctFaces[MAXY].GetVert(0).GetY()) { return (null); } if(point.GetZ() < OctFaces[MINZ].GetVert(0).GetZ() || point.GetZ() >= OctFaces[MAXZ].GetVert(0).GetZ()) { return (null); } if(Child[0] != null) { for(int i = 0; i < 8; i++) { found = Child[i].FindTreeNode(point); if(found != null) { return (found); } } } return (this); }
/** * ReadPoly * * @param infile * @param ObjID * @return int */ private int ReadPoly(int ObjID) { String temp; double[] input = new double[3]; int i, j, k; int numpolys = 0; int numverts; bool trimesh, vertnormal; Point max = new Point(MaxX, MaxY, MaxZ); Point min = new Point(MinX, MinY, MinZ); temp = readString(); temp = readString(); Material theMaterial = ReadMaterial(); temp = readString(); if (temp.Substring(7).Equals("POLYSET_TRI_MESH")) { trimesh = true; } else { trimesh = false; } temp = readString(); if (temp.Substring(11).Equals("PER_VERTEX_NORMAL")) { vertnormal = true; } else { vertnormal = false; } for (i = 0; i < 4; i++) { temp = readString(); } temp = temp.Substring(11); numpolys = Int32.Parse(temp); ObjID++; for (i = 0; i < numpolys; i++) { temp = readString(); temp = readString(); temp = temp.Substring(16); numverts = Int32.Parse(temp); Point[] vertices = new Point[numverts]; for (j = 0; j < numverts; j++) { temp = readString(); temp = temp.Substring(8); for (k = 0; k < 2; k++) { input[k] = (double)Double.Parse(temp.Substring(0, temp.IndexOf(' '))); temp = temp.Substring(temp.IndexOf(' ') + 1); } input[2] = (double)Double.Parse(temp); vertices[j] = new Point(input[0], input[1], input[2]); if (vertnormal) { temp = readString(); } } temp = readString(); TriangleObj newtriangle; PolygonObj newpoly; ObjNode newnode; if (trimesh) { newtriangle = new TriangleObj(theMaterial, ObjID, numverts, vertices, max, min); newnode = new ObjNode(newtriangle, objects); } else { newpoly = new PolygonObj(theMaterial, ObjID, numverts, vertices, max, min); newnode = new ObjNode(newpoly, objects); } objects = newnode; } temp = readString(); MaxX = max.GetX(); MaxY = max.GetY(); MaxZ = max.GetZ(); MinX = min.GetX(); MinY = min.GetY(); MinZ = min.GetZ(); return(numpolys); }
/** * Sub * * @param op1 * @param op2 * @return Vector */ public Vector Sub(Point op1, Point op2) { Set(op1.GetX() - op2.GetX(), op1.GetY() - op2.GetY(), op1.GetZ() - op2.GetZ()); return (this); }
/** * CreateChildren * * @param objects * @param depth */ private void CreateChildren(ObjNode objects, int depth) { double maxX = OctFaces[MAXX].GetVert(0).GetX(); double minX = OctFaces[MINX].GetVert(0).GetX(); double maxY = OctFaces[MAXY].GetVert(0).GetY(); double minY = OctFaces[MINY].GetVert(0).GetY(); double maxZ = OctFaces[MAXZ].GetVert(0).GetZ(); double minZ = OctFaces[MINZ].GetVert(0).GetZ(); Point midpt = new Point((maxX + minX) / 2.0f, (maxY + minY) / 2.0f, (maxZ + minZ) / 2.0f); Point max = new Point(); Point min = new Point(); ObjNode currentnode; int i; max.Set(maxX, maxY, maxZ); min.Set(midpt.GetX(), midpt.GetY(), midpt.GetZ()); Child[0] = new OctNode(max, min); max.Set(maxX, midpt.GetY(), maxZ); min.Set(midpt.GetX(), minY, midpt.GetZ()); Child[1] = new OctNode(max, min); max.Set(maxX, midpt.GetY(), midpt.GetZ()); min.Set(midpt.GetX(), minY, minZ); Child[2] = new OctNode(max, min); max.Set(maxX, maxY, midpt.GetZ()); min.Set(midpt.GetX(), midpt.GetY(), minZ); Child[3] = new OctNode(max, min); max.Set(midpt.GetX(), maxY, maxZ); min.Set(minX, midpt.GetY(), midpt.GetZ()); Child[4] = new OctNode(max, min); max.Set(midpt.GetX(), midpt.GetY(), maxZ); min.Set(minX, minY, midpt.GetZ()); Child[5] = new OctNode(max, min); max.Set(midpt.GetX(), midpt.GetY(), midpt.GetZ()); min.Set(minX, minY, minZ); Child[6] = new OctNode(max, min); max.Set(midpt.GetX(), maxY, midpt.GetZ()); min.Set(minX, midpt.GetY(), minZ); Child[7] = new OctNode(max, min); OctNode[] adj = this.Adjacent; OctNode[] chld = this.Child; OctNode adj0 = adj[0]; OctNode adj1 = adj[1]; OctNode adj2 = adj[2]; OctNode adj3 = adj[3]; OctNode adj4 = adj[4]; OctNode adj5 = adj[5]; OctNode chld0 = chld[0]; OctNode chld1 = chld[1]; OctNode chld2 = chld[2]; OctNode chld3 = chld[3]; OctNode chld4 = chld[4]; OctNode chld5 = chld[5]; OctNode chld6 = chld[6]; OctNode chld7 = chld[7]; Child[0].FormAdjacent(adj0, adj1, adj2, chld4, chld1, chld3); Child[1].FormAdjacent(adj0, chld0, adj2, chld5, adj4, chld2); Child[2].FormAdjacent(adj0, chld3, chld1, chld6, adj4, adj5); Child[3].FormAdjacent(adj0, adj1, chld0, chld7, chld2, adj5); Child[4].FormAdjacent(chld0, adj1, adj2, adj3, chld5, chld7); Child[5].FormAdjacent(chld1, chld4, adj2, adj3, adj4, chld6); Child[6].FormAdjacent(chld2, chld7, chld5, adj3, adj4, adj5); Child[7].FormAdjacent(chld3, adj1, chld4, adj3, chld6, adj5); if(objects != null) { currentnode = objects; } else { currentnode = ObjList; } while(currentnode != null) { ObjectType currentobj = currentnode.GetObj(); for(i = 0; i < 8; i++) { OctNode cc = chld[i]; max = cc.GetFace(0).GetVert(0); min = cc.GetFace(5).GetVert(3); if(!((currentobj.GetMin().GetX() > max.GetX()) || (currentobj.GetMax().GetX() < min.GetX()))) { if(!((currentobj.GetMin().GetY() > max.GetY()) || (currentobj.GetMax().GetY() < min.GetY()))) { if(!((currentobj.GetMin().GetZ() > max.GetZ()) || (currentobj.GetMax().GetZ() < min.GetZ()))) { ObjNode newnode = new ObjNode(currentobj, Child[i].GetList()); cc.SetList(newnode); cc.IncNumObj(); } } } } currentnode = currentnode.Next(); } if(objects == null) { NumObj = 0; ObjList = null; } if(depth < MaxDepth) { for(i = 0; i < 8; i++) { if(Child[i].GetNumObj() > MaxObj) { Child[i].CreateChildren(null, depth + 1); } } } }
/** * RenderScene */ public void RenderScene(Canvas canvas, int width, int section, int nsections) { Vector view = camera.GetViewDir(); Vector up = camera.GetOrthoUp(); Vector plane = new Vector(); Vector horIncr = new Vector(); Vector vertIncr = new Vector(); double ylen = camera.GetFocalDist() * (double)Math.Tan(0.5f * camera.GetFOV()); double xlen = ylen * canvas.GetWidth() / canvas.GetHeight(); Point upleft = new Point(); Point upright = new Point(); Point lowleft = new Point(); Point basepoint = new Point(); Point current; Ray eyeRay = new Ray(); int ypixel, xpixel; RayID = 1; plane.Cross(view, up); view.Scale(camera.GetFocalDist()); up.Scale(ylen); plane.Scale(-xlen); upleft.FindCorner(view, up, plane, camera.GetPosition()); plane.Negate(); upright.FindCorner(view, up, plane, camera.GetPosition()); up.Negate(); plane.Negate(); lowleft.FindCorner(view, up, plane, camera.GetPosition()); horIncr.Sub(upright, upleft); horIncr.Scale(horIncr.Length() / ((double)canvas.GetWidth())); vertIncr.Sub(lowleft, upleft); vertIncr.Scale(vertIncr.Length() / ((double)canvas.GetHeight())); basepoint.Set(upleft.GetX() + 0.5f * (horIncr.GetX() + vertIncr.GetX()), upleft.GetY() + 0.5f * (horIncr.GetY() + vertIncr.GetY()), upleft.GetZ() + 0.5f * (horIncr.GetZ() + vertIncr.GetZ())); eyeRay.SetOrigin(camera.GetPosition()); int xstart = section * width / nsections; int xend = xstart + width / nsections; Console.WriteLine("+" + xstart + " to " + (xend - 1) + " by " + canvas.GetHeight()); for (ypixel = 0; ypixel < canvas.GetHeight(); ypixel++) { current = new Point(basepoint); for (xpixel = 0; xpixel < canvas.GetWidth(); xpixel++) { if (xpixel >= xstart && xpixel < xend) { Color color = new Color(0.0f, 0.0f, 0.0f); eyeRay.GetDirection().Sub(current, eyeRay.GetOrigin()); eyeRay.GetDirection().Normalize(); eyeRay.SetID(RayID); this.RayID = this.RayID + 1; Shade(octree, eyeRay, color, 1.0f, 0, 0); canvas.Write(Brightness, xpixel, ypixel, color); } current.Add(horIncr); } basepoint.Add(vertIncr); } Console.WriteLine("-" + xstart + " to " + (xend - 1) + " by " + canvas.GetHeight()); }
/** * PolyTypeObj * * @param objmaterial * @param newobjID * @param numverts * @param vertices * @param MaxX * @param MinX * @param MaxY * @param MinY * @param MaxZ * @param MinZ */ protected PolyTypeObj(Material objmaterial, int newobjID, int numverts, Point[] vertices, Point max, Point min) : base(objmaterial, newobjID) { numVertices = numverts; Vertices = vertices; CalculateNormal(); Vector temp = new Vector(Vertices [0].GetX(), Vertices [0].GetY(), Vertices [0].GetZ()); D = -Normal.Dot(temp); GetMax().Set(Vertices [0].GetX(), Vertices [0].GetY(), Vertices [0].GetZ()); GetMin().Set(Vertices [0].GetX(), Vertices [0].GetY(), Vertices [0].GetZ()); for (int i = 1; i < numVertices; i++) { if (Vertices [i].GetX() > GetMax().GetX()) { GetMax().SetX(Vertices [i].GetX()); } else if (Vertices [i].GetX() < GetMin().GetX()) { GetMin().SetX(Vertices [i].GetX()); } if (Vertices [i].GetY() > GetMax().GetY()) { GetMax().SetY(Vertices [i].GetY()); } else if (Vertices [i].GetY() < GetMin().GetY()) { GetMin().SetY(Vertices [i].GetY()); } if (Vertices [i].GetZ() > GetMax().GetZ()) { GetMax().SetZ(Vertices [i].GetZ()); } else if (Vertices [i].GetZ() < GetMin().GetZ()) { GetMin().SetZ(Vertices [i].GetZ()); } } if (GetMax().GetX() > max.GetX()) { max.SetX(GetMax().GetX()); } if (GetMax().GetY() > max.GetY()) { max.SetY(GetMax().GetY()); } if (GetMax().GetZ() > max.GetZ()) { max.SetZ(GetMax().GetZ()); } if (GetMin().GetX() < min.GetX()) { min.SetX(GetMin().GetX()); } if (GetMin().GetY() < min.GetY()) { min.SetY(GetMin().GetY()); } if (GetMin().GetZ() < min.GetZ()) { min.SetZ(GetMin().GetZ()); } }
/** * GetCoord * * @param pt * @param index * @return double */ private double GetCoord(Point pt, int index) { if(index == 0) return (pt.GetX()); else if(index == 1) return (pt.GetY()); else return (pt.GetZ()); }
/** * Intersect * * @param ray * @param intersect * @param Threshold * @return OctNode */ public OctNode Intersect(Ray ray, Point intersect, double Threshold) { Vector delta = new Vector(0.0f, 0.0f, 0.0f); double current = 0.0f; double t; int[] facehits = new int[3]; facehits[0] = -1; facehits[1] = -1; facehits[2] = -1; OctNode adjacent = null; Face[] OFaces = this.OctFaces; Face MAXXF = OFaces[MAXX]; Face MAXYF = OFaces[MAXY]; Face MAXZF = OFaces[MAXZ]; Face MINXF = OFaces[MINX]; Face MINYF = OFaces[MINY]; Face MINZF = OFaces[MINZ]; if(ray.GetDirection().GetX() != 0.0) { t = -(ray.GetOrigin().GetX() - OctFaces[MAXX].GetVert(0).GetX()) / ray.GetDirection().GetX(); if(t > Threshold && t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if((intersect.GetY() <= MAXYF.GetVert(0).GetY()) && (intersect.GetY() >= MINYF.GetVert(0).GetY()) && (intersect.GetZ() <= MAXZF.GetVert(0).GetZ()) && (intersect.GetZ() >= MINZF.GetVert(0).GetZ())) { current = t; facehits[0] = MAXX; delta.SetX(Threshold); } } t = -(ray.GetOrigin().GetX() - OctFaces[MINX].GetVert(0).GetX()) / ray.GetDirection().GetX(); if(t > Threshold && t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if((intersect.GetY() <= MAXYF.GetVert(0).GetY()) && (intersect.GetY() >= MINYF.GetVert(0).GetY()) && (intersect.GetZ() <= MAXZF.GetVert(0).GetZ()) && (intersect.GetZ() >= MINZF.GetVert(0).GetZ())) { current = t; facehits[0] = MINX; delta.SetX(-Threshold); } } } if(ray.GetDirection().GetY() != 0.0) { t = -(ray.GetOrigin().GetY() - OctFaces[MAXY].GetVert(0).GetY()) / ray.GetDirection().GetY(); if(t > Threshold) { if(t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if((intersect.GetX() <= MAXXF.GetVert(0).GetX()) && (intersect.GetX() >= MINXF.GetVert(0).GetX()) && (intersect.GetZ() <= MAXZF.GetVert(0).GetZ()) && (intersect.GetZ() >= MINZF.GetVert(0).GetZ())) { current = t; facehits[0] = MAXY; delta.Set(0.0f, Threshold, 0.0f); } } else if(t == current) { facehits[1] = MAXY; delta.SetY(Threshold); } } t = -(ray.GetOrigin().GetY() - OctFaces[MINY].GetVert(0).GetY()) / ray.GetDirection().GetY(); if(t > Threshold) { if(t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if((intersect.GetX() <= MAXXF.GetVert(0).GetX()) && (intersect.GetX() >= MINXF.GetVert(0).GetX()) && (intersect.GetZ() <= MAXZF.GetVert(0).GetZ()) && (intersect.GetZ() >= MINZF.GetVert(0).GetZ())) { current = t; facehits[0] = MINY; delta.Set(0.0f, -Threshold, 0.0f); } } else if(t == current) { facehits[1] = MINY; delta.SetY(-Threshold); } } } if(ray.GetDirection().GetZ() != 0.0) { t = -(ray.GetOrigin().GetZ() - OctFaces[MAXZ].GetVert(0).GetZ()) / ray.GetDirection().GetZ(); if(t > Threshold) { if(t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if((intersect.GetX() <= MAXXF.GetVert(0).GetX()) && (intersect.GetX() >= MINXF.GetVert(0).GetX()) && (intersect.GetY() <= MAXYF.GetVert(0).GetY()) && (intersect.GetY() >= MINYF.GetVert(0).GetY())) { current = t; facehits[0] = MAXZ; delta.Set(0.0f, 0.0f, Threshold); } } else if(t == current) { if(facehits[1] < 0) { facehits[1] = MAXZ; } else { facehits[2] = MAXZ; } delta.SetZ(Threshold); } } t = -(ray.GetOrigin().GetZ() - OctFaces[MINZ].GetVert(0).GetZ()) / ray.GetDirection().GetZ(); if(t > Threshold) { if(t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if((intersect.GetX() <= MAXXF.GetVert(0).GetX()) && (intersect.GetX() >= MINXF.GetVert(0).GetX()) && (intersect.GetY() <= MAXYF.GetVert(0).GetY()) && (intersect.GetY() >= MINYF.GetVert(0).GetY())) { current = t; facehits[0] = MINZ; delta.Set(0.0f, 0.0f, -Threshold); } } else if(t == current) { if(facehits[1] < 0) { facehits[1] = MINZ; } else { facehits[2] = MINZ; } delta.SetZ(-Threshold); } } } if(facehits[0] >= MAXX) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, current); intersect.Add(delta); adjacent = Adjacent[facehits[0]]; if(facehits[1] >= MAXX) { if(adjacent != null) { adjacent = adjacent.GetAdjacent(facehits[1]); if(facehits[2] >= MAXX) { if(adjacent != null) { adjacent = adjacent.GetAdjacent(facehits[2]); } else { adjacent = null; } } } else { adjacent = null; } } } return (adjacent); }
public void AIProcess() { PlayerManager pm = PlayerManager.GetInst(); if (act == ACT.CASTING && casting == true) { Debug.Log("hh"); if (m_type == Type.GOLEM) { anim.SetTrigger("Shockwave Attack"); MapManager.GetInst().MarkShockRange(); } else { act = ACT.JUMP; MapManager.GetInst().MarkAttackRange(CurHex, 4, false); } for (int j = 0; j < pm.Players.Count; ++j) { if (pm.Players[j].CurHex.At_Marked == true) { if (pm.Players[j].m_type != Type.MONSTER && pm.Players[j].m_type != Type.BOSS && pm.Players[j].m_type != Type.GOLEM) { if (((UserPlayer)pm.Players[j]).Equip == false) { Vector3 height = pm.Players[j].transform.position; if (height.y < 2) { pm.Players[j].GetDamage(100); pm.Players[j].act = ACT.STUN; } EffectManager.GetInst().Play(pm.Players[j].CurHex.gameObject); } else { Vector3 height = pm.Players[j].transform.position; if (height.y < 2) { ((UserPlayer)pm.Players[j]).DestroyEquip(); } } } } } if (m_type == Type.GOLEM) { if (act == ACT.CASTING) { MapManager.GetInst().ResetMapColor(); act = ACT.IDLE; PlayerManager.GetInst().TurnOver(); } } casting = false; } if (act == ACT.IDLE) { anim.SetBool("attack", false); if (pm.Players[pm.CurTurnIdx] == this) { AiProc(); } } if (act == ACT.JUMP) { Vector3 gravity = new Vector3(0, -9.8f, 0); Vector3 v = transform.position; float speed = 15; if (v.y <= 10) { v.y += Time.deltaTime * speed; speed -= Time.deltaTime; transform.position = v; } else { act = ACT.JUMPDOWN; } } if (act == ACT.JUMPDOWN) { Vector3 gravity = new Vector3(0, -9.8f, 0); Vector3 v = transform.position; float speed = 12; if (v.y >= 1) { v.y -= Time.deltaTime * speed; speed += Time.deltaTime * 2; transform.position = v; if (ef_time > 0.2) { EffectManager.GetInst().ShowEffect_Summon(CurHex.gameObject, 7, v.y); ef_time = 0f; } } else { act = ACT.IDLE; EffectManager.GetInst().ShowEffect_Summon(CurHex.gameObject, 8, 1f); anim.SetBool("attack", false); PlayerManager.GetInst().TurnOver(); } } if (ACT.ATTACKING == act) { // anim.SetBool("attack", true); } if (act == ACT.MOVING) {//이동처리 if (MoveHexes.Count == 0) { act = ACT.IDLE; anim.SetBool("attack", false); PlayerManager.GetInst().TurnOver(); return; } Hex nextHex = MoveHexes[0]; if (MapManager.GetInst().MapSizeY > 0) { Point p = new Point(nextHex.MapPos.GetX(), nextHex.MapPos.GetY() + 1, nextHex.MapPos.GetZ()); if (MapManager.GetInst().Map[p.GetX()][p.GetY()][p.GetZ()].mesh_draw == true) { nextHex = MapManager.GetInst().Map[p.GetX()][p.GetY()][p.GetZ()]; jump = true; } else { jump = false; } } Vector3 v = nextHex.transform.position; v.y += m_y; float distance = Vector3.Distance(transform.position, v); if (distance >= 1.0f) //이동중 { anim.SetBool("attack", false); anim.SetBool("run", true); transform.position += (v - transform.position).normalized * 3f * Time.smoothDeltaTime; if (jump == false) { transform.rotation = Quaternion.LookRotation((v - transform.position).normalized); if (id != 1 && id != 5) { Vector3 r = transform.rotation.eulerAngles; r.y -= 90; transform.rotation = Quaternion.Euler(r); } } } else //다음 목표 hex에 도착함 { v = nextHex.transform.position; v.y += m_y; transform.position = v; MoveHexes.RemoveAt(0); if (MoveHexes.Count <= 0)//최종 dest { anim.SetBool("run", false); act = ACT.IDLE; Point temppos = new Point(nextHex.MapPos.GetX(), 0, nextHex.MapPos.GetZ()); CurHex = MapManager.GetInst().Map[temppos.GetX()][temppos.GetY()][temppos.GetZ()]; CurHex.Passable = false; anim.SetBool("attack", false); PlayerManager.GetInst().TurnOver(); } } } }
/** * Intersect * * @param ray * @param intersect * @param Threshold * @return OctNode */ public OctNode Intersect(Ray ray, Point intersect, double Threshold) { Vector delta = new Vector(0.0f, 0.0f, 0.0f); double current = 0.0f; double t; int[] facehits = new int[3]; facehits [0] = -1; facehits [1] = -1; facehits [2] = -1; OctNode adjacent = null; Face[] OFaces = this.OctFaces; Face MAXXF = OFaces [MAXX]; Face MAXYF = OFaces [MAXY]; Face MAXZF = OFaces [MAXZ]; Face MINXF = OFaces [MINX]; Face MINYF = OFaces [MINY]; Face MINZF = OFaces [MINZ]; if (ray.GetDirection().GetX() != 0.0) { t = -(ray.GetOrigin().GetX() - OctFaces [MAXX].GetVert(0).GetX()) / ray.GetDirection().GetX(); if (t > Threshold && t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if ((intersect.GetY() <= MAXYF.GetVert(0).GetY()) && (intersect.GetY() >= MINYF.GetVert(0).GetY()) && (intersect.GetZ() <= MAXZF.GetVert(0).GetZ()) && (intersect.GetZ() >= MINZF.GetVert(0).GetZ())) { current = t; facehits [0] = MAXX; delta.SetX(Threshold); } } t = -(ray.GetOrigin().GetX() - OctFaces [MINX].GetVert(0).GetX()) / ray.GetDirection().GetX(); if (t > Threshold && t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if ((intersect.GetY() <= MAXYF.GetVert(0).GetY()) && (intersect.GetY() >= MINYF.GetVert(0).GetY()) && (intersect.GetZ() <= MAXZF.GetVert(0).GetZ()) && (intersect.GetZ() >= MINZF.GetVert(0).GetZ())) { current = t; facehits [0] = MINX; delta.SetX(-Threshold); } } } if (ray.GetDirection().GetY() != 0.0) { t = -(ray.GetOrigin().GetY() - OctFaces [MAXY].GetVert(0).GetY()) / ray.GetDirection().GetY(); if (t > Threshold) { if (t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if ((intersect.GetX() <= MAXXF.GetVert(0).GetX()) && (intersect.GetX() >= MINXF.GetVert(0).GetX()) && (intersect.GetZ() <= MAXZF.GetVert(0).GetZ()) && (intersect.GetZ() >= MINZF.GetVert(0).GetZ())) { current = t; facehits [0] = MAXY; delta.Set(0.0f, Threshold, 0.0f); } } else if (t == current) { facehits [1] = MAXY; delta.SetY(Threshold); } } t = -(ray.GetOrigin().GetY() - OctFaces [MINY].GetVert(0).GetY()) / ray.GetDirection().GetY(); if (t > Threshold) { if (t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if ((intersect.GetX() <= MAXXF.GetVert(0).GetX()) && (intersect.GetX() >= MINXF.GetVert(0).GetX()) && (intersect.GetZ() <= MAXZF.GetVert(0).GetZ()) && (intersect.GetZ() >= MINZF.GetVert(0).GetZ())) { current = t; facehits [0] = MINY; delta.Set(0.0f, -Threshold, 0.0f); } } else if (t == current) { facehits [1] = MINY; delta.SetY(-Threshold); } } } if (ray.GetDirection().GetZ() != 0.0) { t = -(ray.GetOrigin().GetZ() - OctFaces [MAXZ].GetVert(0).GetZ()) / ray.GetDirection().GetZ(); if (t > Threshold) { if (t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if ((intersect.GetX() <= MAXXF.GetVert(0).GetX()) && (intersect.GetX() >= MINXF.GetVert(0).GetX()) && (intersect.GetY() <= MAXYF.GetVert(0).GetY()) && (intersect.GetY() >= MINYF.GetVert(0).GetY())) { current = t; facehits [0] = MAXZ; delta.Set(0.0f, 0.0f, Threshold); } } else if (t == current) { if (facehits [1] < 0) { facehits [1] = MAXZ; } else { facehits [2] = MAXZ; } delta.SetZ(Threshold); } } t = -(ray.GetOrigin().GetZ() - OctFaces [MINZ].GetVert(0).GetZ()) / ray.GetDirection().GetZ(); if (t > Threshold) { if (t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if ((intersect.GetX() <= MAXXF.GetVert(0).GetX()) && (intersect.GetX() >= MINXF.GetVert(0).GetX()) && (intersect.GetY() <= MAXYF.GetVert(0).GetY()) && (intersect.GetY() >= MINYF.GetVert(0).GetY())) { current = t; facehits [0] = MINZ; delta.Set(0.0f, 0.0f, -Threshold); } } else if (t == current) { if (facehits [1] < 0) { facehits [1] = MINZ; } else { facehits [2] = MINZ; } delta.SetZ(-Threshold); } } } if (facehits [0] >= MAXX) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, current); intersect.Add(delta); adjacent = Adjacent [facehits [0]]; if (facehits [1] >= MAXX) { if (adjacent != null) { adjacent = adjacent.GetAdjacent(facehits [1]); if (facehits [2] >= MAXX) { if (adjacent != null) { adjacent = adjacent.GetAdjacent(facehits [2]); } else { adjacent = null; } } } else { adjacent = null; } } } return(adjacent); }
/** * ReadSphere * * @param infile * @param ObjID * @return int */ private int ReadSphere(int ObjID) { String temp; double[] input = new double[3]; int i; double radius; Point max = new Point(MaxX, MaxY, MaxZ); Point min = new Point(MinX, MinY, MinZ); temp = readString(); temp = readString(); Material theMaterial = ReadMaterial(); temp = readString(); temp = temp.Substring(9); for(i = 0; i < 2; i++) { input[i] = (double)Double.Parse(temp.Substring(0, temp.IndexOf(' '))); temp = temp.Substring(temp.IndexOf(' ') + 1); } input[2] = (double)Double.Parse(temp); Point origin = new Point(input[0], input[1], input[2]); temp = readString(); temp = temp.Substring(9); radius = (double)Double.Parse(temp); for(i = 0; i < 7; i++) { temp = readString(); } SphereObj newsphere = new SphereObj(theMaterial, ++ObjID, origin, radius, max, min); ObjNode newnode = new ObjNode(newsphere, objects); objects = newnode; MaxX = max.GetX(); MaxY = max.GetY(); MaxZ = max.GetZ(); MinX = min.GetX(); MinY = min.GetY(); MinZ = min.GetZ(); return (1); }
/** * FindCorner * * @param view * @param up * @param plane * @param origin */ public void FindCorner (Vector view, Vector up, Vector plane, Point origin) { x = origin.GetX (); y = origin.GetY (); z = origin.GetZ (); Add (view); Add (up); Add (plane); }
/** * PolyTypeObj * * @param objmaterial * @param newobjID * @param numverts * @param vertices * @param MaxX * @param MinX * @param MaxY * @param MinY * @param MaxZ * @param MinZ */ protected PolyTypeObj(Material objmaterial, int newobjID, int numverts, Point[] vertices, Point max, Point min) : base(objmaterial, newobjID) { numVertices = numverts; Vertices = vertices; CalculateNormal(); Vector temp = new Vector(Vertices[0].GetX(), Vertices[0].GetY(), Vertices[0].GetZ()); D = -Normal.Dot(temp); GetMax().Set(Vertices[0].GetX(), Vertices[0].GetY(), Vertices[0].GetZ()); GetMin().Set(Vertices[0].GetX(), Vertices[0].GetY(), Vertices[0].GetZ()); for(int i = 1; i < numVertices; i++) { if(Vertices[i].GetX() > GetMax().GetX()) { GetMax().SetX(Vertices[i].GetX()); } else if(Vertices[i].GetX() < GetMin().GetX()) { GetMin().SetX(Vertices[i].GetX()); } if(Vertices[i].GetY() > GetMax().GetY()) { GetMax().SetY(Vertices[i].GetY()); } else if(Vertices[i].GetY() < GetMin().GetY()) { GetMin().SetY(Vertices[i].GetY()); } if(Vertices[i].GetZ() > GetMax().GetZ()) { GetMax().SetZ(Vertices[i].GetZ()); } else if(Vertices[i].GetZ() < GetMin().GetZ()) { GetMin().SetZ(Vertices[i].GetZ()); } } if(GetMax().GetX() > max.GetX()) { max.SetX(GetMax().GetX()); } if(GetMax().GetY() > max.GetY()) { max.SetY(GetMax().GetY()); } if(GetMax().GetZ() > max.GetZ()) { max.SetZ(GetMax().GetZ()); } if(GetMin().GetX() < min.GetX()) { min.SetX(GetMin().GetX()); } if(GetMin().GetY() < min.GetY()) { min.SetY(GetMin().GetY()); } if(GetMin().GetZ() < min.GetZ()) { min.SetZ(GetMin().GetZ()); } }
/** * Combine * * @param pt * @param vector * @param ptscale * @param vecscale * @return Point */ public Point Combine (Point pt, Vector vector, double ptscale, double vecscale) { x = ptscale * pt.GetX () + vecscale * vector.GetX (); y = ptscale * pt.GetY () + vecscale * vector.GetY (); z = ptscale * pt.GetZ () + vecscale * vector.GetZ (); return (this); }
/** * Point * * @param newpoint */ public Point(Point newpoint) { Set(newpoint.GetX(), newpoint.GetY(), newpoint.GetZ()); }
/** * OctNode * * @param max * @param min */ public OctNode(Point max, Point min) { Initialize(); CreateFaces(max.GetX(), min.GetX(), max.GetY(), min.GetY(), max.GetZ(), min.GetZ()); }
/** * Sub * * @param op1 * @param op2 * @return Vector */ public Vector Sub(Point op1, Point op2) { Set(op1.GetX() - op2.GetX(), op1.GetY() - op2.GetY(), op1.GetZ() - op2.GetZ()); return(this); }
void Update() { if (status.Curhp <= 0) { act = ACT.DIYING; } ShowCondition(); if (brokentime != 0) { brokentime += Time.deltaTime; if (brokentime > 1.5) { GameObject.Destroy(equip.gameObject); brokentime = 0f; } } PlayerManager pm = PlayerManager.GetInst(); if (removeTime != 0) { removeTime += Time.deltaTime; if (removeTime >= 1.5f) { for (int i = 0; i < pm.Players.Count; ++i) { if (pm.Players[i].act == ACT.DIYING) { if (pm.CurTurnIdx == i) { pm.RemoveAfter(); pm.RemovePlayer(pm.Players[i]); pm.RemoveAfter(); } else { pm.RemoveAfter(); pm.RemovePlayer(pm.Players[i]); pm.RemoveAfter(); } } } } } if (Equip == true) { Vector3 v2 = transform.position; if (equip_type == "helmet") { v2.y += 1.5f; } else { v2.y += 3.5f; } equip.transform.position = v2; } if (act == ACT.IDLE) { anim.SetBool("attack", false); anim.SetBool("run", false); // if (pm.Players[pm.CurTurnIdx] == this) // { // ///MapManager.GetInst().SetHexColor(CurHex, Color.black); // } //CurHex.Passable = true; } if (act == ACT.MOVING) {//이동처리 CameraManager.GetInst().ResetCameraTarget(); CurHex.Passable = true; Hex nextHex = MoveHexes[0]; if (MapManager.GetInst().MapSizeY > 0) { Point p = new Point(nextHex.MapPos.GetX(), nextHex.MapPos.GetY() + 1, nextHex.MapPos.GetZ()); if (MapManager.GetInst().Map[p.GetX()][p.GetY()][p.GetZ()].mesh_draw == true) { nextHex = MapManager.GetInst().Map[p.GetX()][p.GetY()][p.GetZ()]; jump = true; } else { jump = false; } } Vector3 v = nextHex.transform.position; v.y += 1.0f; float distance = Vector3.Distance(transform.position, v); if (distance >= 0.2f) //이동중 { anim.SetBool("run", true); transform.position += (v - transform.position).normalized * status.MoveSpeed * Time.smoothDeltaTime; if (jump == false) { Quaternion s = Quaternion.LookRotation((v - transform.position).normalized); Vector3 r = s.eulerAngles; r.y -= 90; if (Equip == true) { equip.transform.rotation = Quaternion.Euler(r); } transform.rotation = Quaternion.Euler(r); } } else //다음 목표 hex에 도착함 { anim.SetBool("run", false); Hex temp = nextHex; v = nextHex.transform.position; v.y += 1.0f; transform.position = v; MoveHexes.RemoveAt(0); if (MoveHexes.Count <= 0)//최종 dest { Manager.GetInst().MoveCamPos(nextHex); CameraManager.GetInst().InitPos.x = nextHex.x; CameraManager.GetInst().InitPos.z = nextHex.z; CostManager.GetInst().CostDecrease(1); Point temppos = new Point(nextHex.MapPos.GetX(), 0, nextHex.MapPos.GetZ()); CurHex = MapManager.GetInst().Map[temppos.GetX()][temppos.GetY()][temppos.GetZ()]; CurHex.Passable = false; act = ACT.IDLE; if (CurHex.obj_id == 5) { EquipHelmet(); } //PlayerManager.GetInst().TurnOver(); } } } }
/** * CreateChildren * * @param objects * @param depth */ private void CreateChildren(ObjNode objects, int depth) { double maxX = OctFaces [MAXX].GetVert(0).GetX(); double minX = OctFaces [MINX].GetVert(0).GetX(); double maxY = OctFaces [MAXY].GetVert(0).GetY(); double minY = OctFaces [MINY].GetVert(0).GetY(); double maxZ = OctFaces [MAXZ].GetVert(0).GetZ(); double minZ = OctFaces [MINZ].GetVert(0).GetZ(); Point midpt = new Point((maxX + minX) / 2.0f, (maxY + minY) / 2.0f, (maxZ + minZ) / 2.0f); Point max = new Point(); Point min = new Point(); ObjNode currentnode; int i; max.Set(maxX, maxY, maxZ); min.Set(midpt.GetX(), midpt.GetY(), midpt.GetZ()); Child [0] = new OctNode(max, min); max.Set(maxX, midpt.GetY(), maxZ); min.Set(midpt.GetX(), minY, midpt.GetZ()); Child [1] = new OctNode(max, min); max.Set(maxX, midpt.GetY(), midpt.GetZ()); min.Set(midpt.GetX(), minY, minZ); Child [2] = new OctNode(max, min); max.Set(maxX, maxY, midpt.GetZ()); min.Set(midpt.GetX(), midpt.GetY(), minZ); Child [3] = new OctNode(max, min); max.Set(midpt.GetX(), maxY, maxZ); min.Set(minX, midpt.GetY(), midpt.GetZ()); Child [4] = new OctNode(max, min); max.Set(midpt.GetX(), midpt.GetY(), maxZ); min.Set(minX, minY, midpt.GetZ()); Child [5] = new OctNode(max, min); max.Set(midpt.GetX(), midpt.GetY(), midpt.GetZ()); min.Set(minX, minY, minZ); Child [6] = new OctNode(max, min); max.Set(midpt.GetX(), maxY, midpt.GetZ()); min.Set(minX, midpt.GetY(), minZ); Child [7] = new OctNode(max, min); OctNode[] adj = this.Adjacent; OctNode[] chld = this.Child; OctNode adj0 = adj [0]; OctNode adj1 = adj [1]; OctNode adj2 = adj [2]; OctNode adj3 = adj [3]; OctNode adj4 = adj [4]; OctNode adj5 = adj [5]; OctNode chld0 = chld [0]; OctNode chld1 = chld [1]; OctNode chld2 = chld [2]; OctNode chld3 = chld [3]; OctNode chld4 = chld [4]; OctNode chld5 = chld [5]; OctNode chld6 = chld [6]; OctNode chld7 = chld [7]; Child [0].FormAdjacent(adj0, adj1, adj2, chld4, chld1, chld3); Child [1].FormAdjacent(adj0, chld0, adj2, chld5, adj4, chld2); Child [2].FormAdjacent(adj0, chld3, chld1, chld6, adj4, adj5); Child [3].FormAdjacent(adj0, adj1, chld0, chld7, chld2, adj5); Child [4].FormAdjacent(chld0, adj1, adj2, adj3, chld5, chld7); Child [5].FormAdjacent(chld1, chld4, adj2, adj3, adj4, chld6); Child [6].FormAdjacent(chld2, chld7, chld5, adj3, adj4, adj5); Child [7].FormAdjacent(chld3, adj1, chld4, adj3, chld6, adj5); if (objects != null) { currentnode = objects; } else { currentnode = ObjList; } while (currentnode != null) { ObjectType currentobj = currentnode.GetObj(); for (i = 0; i < 8; i++) { OctNode cc = chld [i]; max = cc.GetFace(0).GetVert(0); min = cc.GetFace(5).GetVert(3); if (!((currentobj.GetMin().GetX() > max.GetX()) || (currentobj.GetMax().GetX() < min.GetX()))) { if (!((currentobj.GetMin().GetY() > max.GetY()) || (currentobj.GetMax().GetY() < min.GetY()))) { if (!((currentobj.GetMin().GetZ() > max.GetZ()) || (currentobj.GetMax().GetZ() < min.GetZ()))) { ObjNode newnode = new ObjNode(currentobj, Child [i].GetList()); cc.SetList(newnode); cc.IncNumObj(); } } } } currentnode = currentnode.Next(); } if (objects == null) { NumObj = 0; ObjList = null; } if (depth < MaxDepth) { for (i = 0; i < 8; i++) { if (Child [i].GetNumObj() > MaxObj) { Child [i].CreateChildren(null, depth + 1); } } } }
void RepositionDesert2Checkpoint() { rb.velocity = new Vector3(0, 0, 0); carInGame.transform.position = new Vector3(coordinates.GetX(), coordinates.GetY(), coordinates.GetZ()); //1537, 0, 348 carInGame.SendMessage("updateTimeByRepositionDesert2"); //carInGame.transform.rotation = Quaternion.Euler (0.0f, -54.658f, 0.0f); Debug.Log("riposizionato"); }
void OnMouseDown() { PlayerManager pm = PlayerManager.GetInst(); PlayerBase pb = pm.Players[pm.CurTurnIdx]; Debug.Log(MapPos + "OnMouseDown"); if (pb.act == ACT.MAGIC) { if (magic.GetInst().type == "wall") { MapManager.GetInst().MarkWall(this.MapPos); } if (At_Marked == true && magic.GetInst().type == "wall") { if (MapManager.GetInst().wallpos.GetX() >= MapPos.GetX()) { for (int i = 0; i < 3; ++i) { if (MapManager.GetInst().Map[MapPos.GetX() - i][MapPos.GetY()][MapPos.GetZ()].Passable == true) { obj = (GameObject)GameObject.Instantiate(magic.GetInst().magics[2]); Vector3 v = transform.position; obj.transform.position = new Vector3(v.x, 1, v.z - i); obj = (GameObject)GameObject.Instantiate(magic.GetInst().magics[2]); MapManager.GetInst().Map[MapPos.GetX()][MapPos.GetY()][MapPos.GetZ() - i].Passable = false; } } obj.transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0)); MapManager.GetInst().ResetMapColor(); CameraManager.GetInst().ResetCameraTarget(); MapManager.GetInst().wall = false; } else { for (int i = 0; i < 3; ++i) { if (MapManager.GetInst().Map[MapPos.GetX() - i][MapPos.GetY()][MapPos.GetZ()].Passable == true) { obj = (GameObject)GameObject.Instantiate(magic.GetInst().magics[2]); Vector3 v = transform.position; obj.transform.position = new Vector3(v.x - i, 1, v.z); obj.transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0)); obj = (GameObject)GameObject.Instantiate(magic.GetInst().magics[2]); MapManager.GetInst().Map[MapPos.GetX() - i][MapPos.GetY()][MapPos.GetZ()].Passable = false; } } MapManager.GetInst().wall = false; MapManager.GetInst().ResetMapColor(); CameraManager.GetInst().ResetCameraTarget(); } } } if (pb.act == ACT.SUMMONES) { if (Passable == true && At_Marked == true) { PlayerManager.GetInst().GenPlayer(MapPos.GetX(), MapPos.GetZ()); pb.act = ACT.IDLE; EffectManager.GetInst().ShowEffect_Summon(pb.CurHex.gameObject, 3, 1.2f); CameraManager.GetInst().ResetCameraTarget(); MapManager.GetInst().ResetMapColor(); } } if (pb.act == ACT.IDLE) { } else if (pb.act == ACT.MOVEHILIGHT) { if (Passable == true) { pm.MovePlayer(pm.Players[pm.CurTurnIdx].CurHex, this); } } }