• R/O
  • SSH
  • HTTPS

nlgp1: Commit


Commit MetaInfo

Revision844 (tree)
Zeit2011-03-04 11:44:40
Autormassa_senohito

Log Message

PolygonShape等の編集

Ändern Zusammenfassung

Diff

--- trunk/Nlgp1/Nlgp1/Characters/SpriteFactory.cs (revision 843)
+++ trunk/Nlgp1/Nlgp1/Characters/SpriteFactory.cs (revision 844)
@@ -125,9 +125,9 @@
125125 #region 10秒アイテム
126126 sprite.Shape.Stepped += ( sender ,e ) => {
127127 foreach( ISpriteContact contact in e.Shape.Contacts ) {
128- if( ( ( IPolygonSpriteShape )( contact.Other ) ).Shape == PlayerStatus.Player.Sprite.Shape ) {
129- PlayerStatus.TimerInitialize();
130- }
128+ //if( ( ( IPolygonSpriteContact )( contact.Other ) ).Shape == PlayerStatus.Player.Sprite.Shape ) {
129+ // PlayerStatus.TimerInitialize();
130+ //}
131131 }
132132 };
133133 #endregion
--- trunk/Nlgp1/Nlgp1/Parameters/StageWorld.cs (revision 843)
+++ trunk/Nlgp1/Nlgp1/Parameters/StageWorld.cs (revision 844)
@@ -19,7 +19,7 @@
1919
2020 public ISpriteBody CreateSpriteBody(bool isMovable, Vector position)
2121 {
22- throw new NotImplementedException();
22+ return new SpriteBody(isMovable,position, this);
2323 }
2424
2525 public void Step(Action action)
@@ -30,6 +30,11 @@
3030 this.debugDraw.Step();
3131 }
3232
33+ public World World
34+ {
35+ get { return world; }
36+ }
37+
3338 private readonly World world;
3439 private readonly SpriteContactListener listener;
3540 private readonly StageDebugDraw debugDraw;
--- trunk/Nlgp1/Nlgp1/Parameters/SpriteBodyFactory.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteBodyFactory.cs (revision 844)
@@ -0,0 +1,28 @@
1+using System;
2+using System.Collections.Generic;
3+using Box2DX.Common;
4+using Nlgp1.Sprites;
5+
6+namespace Nlgp1.Parameters
7+{
8+ /// <summary>
9+ /// ISpriteBodyを作成する
10+ /// </summary>
11+ public static class SpriteBodyFactory
12+ {
13+ /// <summary>
14+ /// ISpriteBodyを作成する
15+ /// </summary>
16+ /// <param name="sprite">作成元のSprite</param>
17+ /// <param name="position">位置</param>
18+ /// <returns>作成されたオブジェクト</returns>
19+ public static ISpriteBody CreateBody(Sprite sprite, Vec2 position)
20+ {
21+ ISpriteBody chara;
22+
23+
24+ //return chara;
25+ throw new NotImplementedException();
26+ }
27+ }
28+}
--- trunk/Nlgp1/Nlgp1/Parameters/SpriteBody.cs (revision 843)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteBody.cs (revision 844)
@@ -1,5 +1,6 @@
11 using System;
22 using System.Collections.Generic;
3+using System.Linq;
34 using Box2DX.Collision;
45 using Box2DX.Dynamics;
56 using Nlgp1.Box2DX;
@@ -6,6 +7,7 @@
67 using Nlgp1.Sprites;
78 using Nlgp1.Stages;
89 using Nlgp1.Utilities;
10+using Box2DX.Common;
911
1012 namespace Nlgp1.Parameters
1113 {
@@ -13,79 +15,87 @@
1315 {
1416 RigidBody chara;
1517 Vector normalgravity = new Vector(0,193);
18+ StageWorld Stage;
1619 //IEnumerable<SpriteShape> bodyshapes;
20+ Sprite sprite;
1721 //Unloadで削除する
22+ //
23+
1824
1925 float liniervelocity = 0.5f, angulervelocity = 0, friction = 0f, restitution = 0, density = 0.1f;
20- //public SpriteBody(Sprite sprite, IEnumerable<SpriteShape> shapes, VectorF position)
21- //{
22-
23- // //臨時ストッパー
24- // /*
25- // if (GameMap.World.GetBodyCount() > 511)
26- // {
27- // //ログ残したい,throw Exception?
28- // return;
29- // }
30- // */
31- // this.bodyshapes = shapes;
32- // this.sprite = sprite;
26+ public SpriteBody(bool isMovable, Vector position,StageWorld w)
27+ {
28+ //
29+ //臨時ストッパー
30+ /*
31+ if (GameMap.World.GetBodyCount() > 511)
32+ {
33+ //ログ残したい,throw Exception?
34+ return;
35+ }
36+ */
37+
38+ this.Stage = w;
39+ //
3340
34- // switch (sprite.LayerType)
35- // {
36- // //キャラクターの場合、sprite.Shape.Width, sprite.Shape.Heightから値をとっている
37- // //myUserDataは決まっていない
38- // case Nlgp1.Common.LayerType.Character:
39- // foreach (SpriteShape ss in shapes)
40- // {
41- // VectorF lb = ss.Rectangle.Upper - ss.Rectangle.Lower;
42- // lb.X /= 2; lb.Y /= 2;
43- // chara = new DynamicRigid(position, 0, liniervelocity, angulervelocity);
44- // chara.SetAsBox(lb.X, lb.Y, new Polygondef2(friction, restitution, density, new SpriteUserData(ss)), false);
45- // chara.MakeBody(GameMap.World);
46- // chara.Massdata = new MassData {
47- // Mass = 1,
48- // };
49- // }
50- // break;
51- // case Nlgp1.Common.LayerType.Front:
52- // foreach (SpriteShape ss in shapes)
53- // {
54- // VectorF lb = ss.Rectangle.Upper - ss.Rectangle.Lower;
55- // lb.X /= 2; lb.Y /= 2;
56- // chara = new StaticRigid(position, 0, 0, 0);
57- // chara.SetAsBox(lb.X, lb.Y, new Polygondef2(3,0,0, new SpriteUserData(ss)), false);
58- // chara.MakeBody(GameMap.World);
59- // }
60- // break;
61- // default:
62- // break;
63- // }
41+ if (isMovable)
42+ {
43+
44+ chara = new DynamicRigid(position, 0, liniervelocity, angulervelocity);
45+ chara.Massdata = new MassData
46+ {
47+ Mass = 1,
48+ };
49+ }
50+ else
51+ {
52+ chara = new StaticRigid(position, 0, 0, 0);
53+ }
54+
6455
65- //}
56+ }
6657
58+
6759 public IPolygonSpriteShape CreatePolygonSpriteShape(SpriteShapeFilter filter, Polygon area)
6860 {
69- throw new NotImplementedException();
61+
62+ Polygondef2 pd = new Polygondef2(friction, restitution, density, new SpriteUserData(new PolygonSpriteShape(area,this,filter)));
63+ pd.Vertices = area.Vertices.Cast<Vec2>().ToArray<Vec2>();
64+ chara.Addtolist(pd);
65+ return (IPolygonSpriteShape)((SpriteUserData)pd.User).SpriteShape;
7066 }
71-
67+ /*asでもキャストでも*/
7268 public ICircleSpriteShape CreateCircleSpriteShape(SpriteShapeFilter filter, Circle area)
7369 {
74- throw new NotImplementedException();
70+ CircleDef2 cd = new CircleDef2(area.Center, area.Radius, friction, restitution, density, new SpriteUserData(new CircleSpriteShape(area,this,filter)));
71+ chara.Addtolist(cd);
72+ return (ICircleSpriteShape)((SpriteUserData)cd.User).SpriteShape;
7573 }
7674
75+ //public ISpriteShape CreateSpriteShape(SpriteShapeFilter filter, Octagon area)
76+ //{
77+ // SpriteShape ss = new SpriteShape(this, filter, area);
78+ // Polygondef2 pd = new Polygondef2(friction, restitution, density, new SpriteUserData(ss));
79+ // pd.VertexCount = 8;
80+ // pd.Vertices = area.ToVec2Vertices();
81+ // chara.Addtolist(pd);
82+
83+ // return ((SpriteUserData)chara.UserData).SpriteShape;
84+ //}
85+
7786 public void Load()
7887 {
79- throw new NotImplementedException();
88+ chara.MakeBody(Stage.World);
8089 }
8190
8291 public void Unload()
8392 {
84- ////スプライトが破棄されると呼ばれる
85- ////画面外に出ると削除
86- //GameMap.World.DestroyBody(this.chara.SelfBody);
93+ Stage.World.DestroyBody(chara.SelfBody);
94+
95+
8796 //this.bodyshapes = null;
88-
97+ this.sprite = null;
98+ this.chara = null;
8999 }
90100
91101 public void Step()
@@ -96,11 +106,8 @@
96106 ////((DynamicRigid)chara).ApplyImpulse(normalgravity);
97107 //chara.SelfBody.SetLinearVelocity(normalgravity);
98108 }
99- //foreach (SpriteShape ss in bodyshapes)
100- //{
101- // //すべてのShape毎にする共通処理
102- //}
103109
110+
104111 }
105112
106113 public void ApplyForce(Vector force)
@@ -112,6 +119,14 @@
112119
113120 }
114121
122+ public Sprite Sprite
123+ {
124+ get
125+ {
126+ return this.sprite;
127+ }
128+ }
129+
115130 public Vector Position
116131 {
117132 get
@@ -128,5 +143,6 @@
128143 return this.chara.LinearVelocity;
129144 }
130145 }
146+
131147 }
132148 }
--- trunk/Nlgp1/Nlgp1/Parameters/SpriteContactListener.cs (revision 843)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteContactListener.cs (revision 844)
@@ -14,8 +14,8 @@
1414 {
1515 List<Shape> shape1s=new List<Shape>();
1616 List<Shape> shape2s=new List<Shape>();
17- List<Direction> s1dirs = new List<Direction>();
18- List<Direction> s2dirs = new List<Direction>();
17+ List<int> vertexindexes = new List<int>();
18+ List<int> seagmentindexes1 = new List<int>(), seagmentindexes2 = new List<int>();
1919 List<ContactPoint> contactPoints = new List<ContactPoint>();
2020
2121 int allcontacts = 0, eventcontacts = 0;
@@ -48,12 +48,11 @@
4848 shape1s.Add(s1); shape2s.Add(s2);
4949 contactPoints.Add(cp);
5050
51- s1dirs.Add(dircheck(s1, cp.Position));
52- s2dirs.Add(dircheck(s2, cp.Position));
51+ //seagmentindexes1.Add(
5352 //間違ってるかもしれないので用検証
5453
5554 float upper, lower;
56- if (s1dirs[eventcontacts] == Direction.Left || s1dirs[eventcontacts] == Direction.Right)
55+ //if (s1dirs[eventcontacts] == Direction.Left || s1dirs[eventcontacts] == Direction.Right)
5756 {
5857
5958 if (s1pos.Y > s2pos.Y)
@@ -65,7 +64,7 @@
6564 upper = CalcfromShape.GetBottom(s1); lower = CalcfromShape.GetUpper(s2);
6665 }
6766 }
68- else
67+ //else
6968 {
7069 if (s1pos.X > s2pos.X)
7170 {
@@ -122,6 +121,14 @@
122121 return Direction.Bottom;
123122 }
124123
124+ int segmentCheck(Shape shape, Vector pos)
125+ {
126+ //Userdata追加?
127+ Vector spos = shape.GetBody().GetPosition();
128+ //if(shape.
129+ return 0;
130+ }
131+
125132 Vector getUpperLower(Shape s1, Shape s2, Direction dir)
126133 {
127134 float upper, lower;
@@ -224,7 +231,7 @@
224231 //ss.Contacts = sc;
225232 }
226233 shape1s.Clear(); shape2s.Clear();
227- s1dirs.Clear(); s2dirs.Clear();
234+ //s1dirs.Clear(); s2dirs.Clear();
228235 eventcontacts = 0; allcontacts = 0;
229236 }
230237 }
--- trunk/Nlgp1/Nlgp1/Parameters/Octagon.cs (revision 843)
+++ trunk/Nlgp1/Nlgp1/Parameters/Octagon.cs (revision 844)
@@ -1,4 +1,5 @@
11 using System;
2+using Box2DX.Common;
23
34 namespace Nlgp1.Parameters
45 {
@@ -50,6 +51,11 @@
5051 return new Vector[] { this.Vertex1, this.Vertex2, this.Vertex3, this.Vertex4, this.Vertex5, this.Vertex6, this.Vertex7, this.Vertex8 };
5152 }
5253
54+ public Vec2[] ToVec2Vertices()
55+ {
56+ return new Vec2[] { this.Vertex1, this.Vertex2, this.Vertex3, this.Vertex4, this.Vertex5, this.Vertex6, this.Vertex7, this.Vertex8 };
57+ }
58+
5359 public Vector Vertex1;
5460 public Vector Vertex2;
5561 public Vector Vertex3;
--- trunk/Nlgp1/Nlgp1/Parameters/SpriteUserData.cs (revision 843)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteUserData.cs (revision 844)
@@ -10,12 +10,12 @@
1010 {
1111 class SpriteUserData:myUserData
1212 {
13- //public SpriteShape SpriteShape;
14-
15- //public SpriteUserData(SpriteShape ss)
16- // : base()
17- //{
18- // SpriteShape = ss;
19- //}
13+ public ISpriteShape SpriteShape;
14+ //
15+ public SpriteUserData(ISpriteShape ss)
16+ : base()
17+ {
18+ SpriteShape = ss;
19+ }
2020 }
2121 }
--- trunk/Nlgp1/Nlgp1/Parameters/IPolygonSpriteShape.cs (revision 843)
+++ trunk/Nlgp1/Nlgp1/Parameters/IPolygonSpriteShape.cs (revision 844)
@@ -9,15 +9,12 @@
99 /// </summary>
1010 public interface IPolygonSpriteShape : ISpriteShape
1111 {
12- /// <summary>
13- /// 衝突元のIPolygonSpriteShape
14- /// </summary>
15- IPolygonSpriteShape Shape { get; }
12+
1613
1714 /// <summary>
1815 /// 衝突範囲
1916 /// </summary>
20- IEnumerable<Polygon> Area { get; }
17+ Polygon Area { get; }
2118
2219 /// <summary>
2320 /// IStageWorld.Step後に実行されるイベント
Show on old repository browser