• R/O
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

FreeTrainの進化系を目指す


Commit MetaInfo

Revision28 (tree)
Time2014-10-13 00:01:37
Authorc477

Log Message

マウスポインタ位置の地形ポリゴンを検出、バグ修正済み

Change Summary

Incremental Difference

--- trunk/core/core/geometry/TerrainUtil.cs (revision 27)
+++ trunk/core/core/geometry/TerrainUtil.cs (revision 28)
@@ -128,11 +128,15 @@
128128 }
129129
130130 static public bool IsInnerPoint2D(Point[] triangle_vertex, Point testpos) {
131+ double c,c2=0.0;
131132 for (int i=0; i<3; i++) {
132133 Point p = triangle_vertex[i];
133134 Point v1 = SubVector(testpos, p);
134135 Point v2 = SubVector(p, triangle_vertex[(i + 2) % 3]);
135- if (GetOuterProduct2D(v1, v2) < 0) return false;
136+ c = GetOuterProduct2D(v1, v2);
137+ if (c == 0) return true; // On the line
138+ if (c2 != 0 && c2 * c < 0) return false; // Out of triangle
139+ c2 = c;
136140 }
137141 return true;
138142 }
--- trunk/core/impl/view/SceneBuilder.cs (revision 27)
+++ trunk/core/impl/view/SceneBuilder.cs (revision 28)
@@ -34,7 +34,7 @@
3434
3535 public SceneBuilder(GameImpl g) {
3636 this.game = g;
37- SetViewFactor(new ViewFactor(InterCardinalDirection.NORTHEAST, ZoomScale.x2));
37+ SetViewFactor(new ViewFactor(InterCardinalDirection.NORTHEAST));
3838 }
3939
4040 public SceneBuilder(GameImpl g, ISurface s) : this(g){
@@ -274,8 +274,8 @@
274274 }
275275
276276 protected Point WorldPosToGrid(PointF3D p3d) {
277- int isx = (int)Math.Floor(p3d.X / Geocon.UnitWidthPixel);
278- int isy = (int)Math.Floor(p3d.Y / Geocon.UnitWidthPixel);
277+ int isx = (int)Math.Round(p3d.X / Geocon.UnitWidthPixel);
278+ int isy = (int)Math.Round(p3d.Y / Geocon.UnitWidthPixel);
279279 int d = (int)Math.Ceiling(p3d.Z / Geocon.HalfOf_UnitWidthPixel);
280280 return new Point(isx - d, isy - d);
281281 }
@@ -283,6 +283,7 @@
283283 public object GetObjectAt(Point spos) {
284284 ITerrainPolygon pol;
285285 PointF3D p3dv;
286+ marker0 = null;
286287 if (DrawIndexUtil.ResolveTerrain(this, spos, out pol, out p3dv)) {
287288
288289 return pol;
@@ -290,14 +291,14 @@
290291 return null;
291292 }
292293
293- public object GetObjectAt_old(Point spos) {
294+ public object GetGroundAt(Point spos) {
294295 PointF3D p3d = surface.ToWorldPosition(spos);
295296 #if DEBUG
296297 Debug.Write("mouse(" + spos.X + "," + spos.Y + ")");
297298 //Debug.Write("world(" + (int)p3d.X + "," + (int)p3d.Y + "," + (int)p3d.Z + ")");
298299 #endif
299- int isx = (int)Math.Floor(p3d.X / Geocon.UnitWidthPixel);
300- int isy = (int)Math.Floor(p3d.Y / Geocon.UnitWidthPixel);
300+ int isx = (int)Math.Round(p3d.X / Geocon.UnitWidthPixel);
301+ int isy = (int)Math.Round(p3d.Y / Geocon.UnitWidthPixel);
301302 object ret = null;
302303 TerrainMapImpl map = game.TerrainMap;
303304 // 標高の高い地表セルは画面上方に表示される。
@@ -323,15 +324,15 @@
323324 #endif
324325 marker0 = null;
325326 while(true){
326- //Debug.Write("(" + l1.X + "," + l1.Y + ")");
327327 if (l2.X >= 0 && l2.Y >= 0 && l2.X < sz.sx && l2.Y < sz.sy) {
328+ //Debug.Write("l2(" + l2.X + "," + l2.Y + ")");
328329 HitTest(l2, spos, out ret);
329330 if (ret != null) break;
330331 }
331332 if (l1.X >= 0 && l1.Y >= 0 && l1.X < sz.sx && l1.Y < sz.sy) {
332- if (HitTest(l1, spos, out ret)) {
333- break;
334- }
333+ //Debug.Write("l1(" + l1.X + "," + l1.Y + ")");
334+ HitTest(l1, spos, out ret);
335+ if (ret != null) break;
335336 }
336337 if (isx < l1.X) {
337338 //Debug.Write("exit3");
@@ -379,22 +380,21 @@
379380 Point rep = surface.ToScreenPosition(p3d);
380381 //Debug.Write(":rep(" + rep.X + "," + rep.Y + ")");
381382 // ビューのY座標は上に行くほど小さくなることに注意
382- //Debug.Write(":h="+h);
383383 if (rep.Y < vw_p.Y) { // 指定ポイントより上=絶対ヒットしない
384384 //Debug.Write("HitTest at=" + iso_p);
385385 //Debug.WriteLine(":e1=" + (rep.Y - vw_p.Y));
386386 return true;
387387 }
388- int xoff = rep.X - vw_p.X;
388+ int xoff = vw_p.X - rep.X;
389389 int yoff = 0;
390390 //Debug.WriteLine("HitTest at=" + iso_p);
391391 bool cliff = false;
392- //rep.Y -= (Geocon.TerrainMaxHeightInPixel + Geocon.HalfOf_UnitWidthPixel);
393- foreach (ITerrainPiece p in map[iso_p.X, iso_p.Y, upperDir]) {
392+ //rep.Y += (Geocon.TerrainMaxHeightInPixel + Geocon.HalfOf_UnitWidthPixel);
393+ Location l = cdUtil.IsometricGridToLocation(iso_p.X, iso_p.Y, 0);
394+ foreach (ITerrainPiece p in map[l.X, l.Y, upperDir]) {
394395 int h1 = p.BaseHeight * Geocon.UnitHeightPixel;
395396 yoff = vw_p.Y - rep.Y + h1;
396397 //Debug.Write(",off(" + xoff + "," + yoff + ")");
397- //Debug.Write(",h1="+h1);
398398 if (yoff > 0 ) {
399399 cliff = true; //おそらく手前の崖を差している
400400 continue;
@@ -404,10 +404,20 @@
404404 TerrainPieceTemplate.TerrainPolygonSet tpset = p.Template.GetPolygons(upperDir);
405405 if (tpset.Ground.IsVisible) {
406406 //Debug.Write("!");
407- if (TerrainUtil.IsInnerPoint2D(tpset.Ground.GetVerticis(scaler), new Point(xoff,yoff))) {
407+ Debug.Write("["+iso_p.X+","+iso_p.Y+"]+(" + xoff + "," + yoff + ")");
408+ if (TerrainUtil.IsInnerPoint2D(tpset.Ground.GetVerticis(scaler), new Point(xoff, yoff))) {
409+#if false //DEBUG
410+ Debug.Write("%");
411+ foreach (Point bp in tpset.Ground.GetVerticis(scaler)) {
412+ Debug.Write("<"+bp.X+","+bp.Y+">");
413+ }
414+ Debug.Write("%");
415+#endif
408416 ret = tpset.Ground;
417+ //Debug.Write("vw.Y=" + vw_p.Y + ", rp.Y=" + rep.Y + ", h1=" + h1);
409418 //Debug.WriteLine("");
410- marker0 = new TerrainMarker(iso_p, tpset, true);
419+ //marker0 = new TerrainMarker(iso_p, tpset, true);
420+ CreateMarker(iso_p.X, iso_p.Y, TrMk_Ground);
411421 return true;
412422 }
413423 }
--- trunk/core/impl/view/DrawIndexUtil.cs (revision 27)
+++ trunk/core/impl/view/DrawIndexUtil.cs (revision 28)
@@ -59,53 +59,57 @@
5959 if (AdjustPointForGround(ref p3dv, idx)) {
6060 int gx = (int)Math.Round(p3dv.X / Geocon.UnitWidthPixel);
6161 int gy = (int)Math.Round(p3dv.Y / Geocon.UnitWidthPixel);
62- Debug.Write("->(" + p3dv.X + "," + p3dv.Y + ") : grid[" + gx + "," + gy + "]");
63- foreach (ITerrainPiece p in map[gx, gy, sb.upperDir]) {
62+ Debug.Write(":Ground->(" + p3dv.X + "," + p3dv.Y + ") : grid[" + gx + "," + gy + "]");
63+ Location l = sb.cdUtil.IsometricGridToLocation(gx, gy, 0);
64+ foreach (ITerrainPiece p in map[l.X, l.Y, sb.upperDir]) {
6465 TerrainPieceTemplate.TerrainPolygonSet tpset = p.Template.GetPolygons(sb.upperDir);
6566 if (tpset.Ground.IsVisible) {
66- Point rep = sb.surface.ToScreenPosition(p3dv);
67+ PointF3D p3d = new PointF3D(gx * Geocon.UnitWidthPixel, gy * Geocon.UnitWidthPixel, 0);
68+ Point rep = sb.surface.ToScreenPosition(p3d);
6769 int xoff = mousePos.X - rep.X;
6870 int yoff = mousePos.Y - rep.Y;
71+ int h1 = p.BaseHeight * Geocon.UnitHeightPixel;
72+ yoff += h1;
6973 //Debug.Write("!");
7074 if (TerrainUtil.IsInnerPoint2D(tpset.Ground.GetVerticis(sb.scaler), new Point(xoff, yoff))) {
75+ Debug.WriteLine("+(" + xoff + "," + yoff + ")");
7176 pol = tpset.Ground;
72- Debug.WriteLine(": Ground hit 1 off(" + xoff + ", yoff=" + yoff + ")");
77+ sb.CreateMarker(gx, gy, SceneBuilder.TrMk_Ground);
7378 break;
74- } else if (pol == null) {
75- Debug.WriteLine(": Ground hit 2 off(" + xoff + ", yoff=" + yoff + ")");
76- pol = tpset.Ground;
79+ //} else if (pol == null) {
80+ // pol = tpset.Ground;
7781 }
7882 }
79- sb.CreateMarker(gx, gy, SceneBuilder.TrMk_Ground);
8083 }
81- Debug.WriteLineIf(pol == null, "WTF!?");
84+ //Debug.WriteLineIf(pol == null, "WTF!?");
8285 return pol != null;
8386 } else if (AdjustPointForCliff(ref p3dv, idx)) {
8487 int gx = (int)Math.Round(p3dv.X / Geocon.UnitWidthPixel);
8588 int gy = (int)Math.Round(p3dv.Y / Geocon.UnitWidthPixel);
86- Debug.Write("->(" + p3dv.X + "," + p3dv.Y + ") : grid[" + gx + "," + gy + "]");
87- foreach (ITerrainPiece p in map[gx, gy, sb.upperDir]) {
89+ Debug.Write(":Cliff->(" + p3dv.X + "," + p3dv.Y + ") : grid[" + gx + "," + gy + "]");
90+ Location l = sb.cdUtil.IsometricGridToLocation(gx, gy, 0);
91+ foreach (ITerrainPiece p in map[l.X, l.Y, sb.upperDir]) {
8892 //if (p.BaseHeight < p3dv.Z) continue;
8993 TerrainPieceTemplate.TerrainPolygonSet tpset = p.Template.GetPolygons(sb.upperDir);
9094 UInt32 testval = (idx & Mask_CliffPolygon_D);
9195 if (testval == Mask_CliffPolygon_D) {
92- Debug.WriteLine(": Cliff(Diagonal)");
96+ Debug.WriteLine(":Diagonal");
9397 pol = tpset.CliffDiagonal;
9498 sb.CreateMarker(gx, gy, SceneBuilder.TrMk_CliffDiag);
9599 } else if (testval == Mask_CliffPolygon_R) {
96- Debug.WriteLine(": Cliff(Right)");
100+ Debug.WriteLine(":Right");
97101 pol = tpset.CliffRight;
98102 sb.CreateMarker(gx, gy, SceneBuilder.TrMk_CliffRight);
99103 } else {
100- Debug.WriteLine(": Cliff(Left)");
104+ Debug.WriteLine(":Left");
101105 pol = tpset.CliffLeft;
102106 sb.CreateMarker(gx, gy, SceneBuilder.TrMk_CliffLeft);
103107 }
104108 }
105- Debug.WriteLineIf(pol == null, "WTF2!?");
109+ //Debug.WriteLineIf(pol == null, "WTF2!?");
106110 return pol != null;
107111 }
108- Debug.WriteLine("--");
112+ //Debug.WriteLine("--");
109113 return false;
110114 }
111115
--- trunk/framework/framework/drawing/I3DObject.cs (revision 27)
+++ trunk/framework/framework/drawing/I3DObject.cs (revision 28)
@@ -26,7 +26,7 @@
2626 Point minP = new Point(int.MaxValue, int.MaxValue);
2727 Point maxP = new Point(int.MinValue, int.MinValue);
2828 for (int i = 0; i < n; i++) {
29- int x = locs[i].Y - locs[i].X;
29+ int x = locs[i].X - locs[i].Y;
3030 int y = -locs[i].Z - (locs[i].X + locs[i].Y) / 2;
3131 minP.X = Math.Min(minP.X, x);
3232 maxP.X = Math.Max(maxP.X, x);