• R/O
  • SSH
  • HTTPS

nlgp1: Commit


Commit MetaInfo

Revision845 (tree)
Zeit2011-03-09 16:31:14
Autormassa_senohito

Log Message

コンタクトをとる(まだ未完成)

Ändern Zusammenfassung

Diff

--- trunk/Nlgp1/Nlgp1/Parameters/SpriteContact.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteContact.cs (revision 845)
@@ -0,0 +1,31 @@
1+
2+namespace Nlgp1.Parameters
3+{
4+ class SpriteContact:ISpriteContact
5+ {
6+ public SpriteContact(SpriteShape source, SpriteShape target)
7+ {
8+ Source = source;
9+ Target = target;
10+ }
11+
12+ public SpriteShape Source
13+ {
14+ get;
15+ protected set;
16+ }
17+ public SpriteShape Target
18+ {
19+ get;
20+ protected set;
21+ }
22+ #region ISpriteContact メンバ
23+
24+ public ISpriteContact Other
25+ {
26+ get { return this; }
27+ }
28+
29+ #endregion
30+ }
31+}
--- trunk/Nlgp1/Nlgp1/Parameters/SpriteShape.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteShape.cs (revision 845)
@@ -0,0 +1,44 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using Box2DX.Dynamics;
6+using Box2DX.Collision;
7+
8+namespace Nlgp1.Parameters
9+{
10+ abstract class SpriteShape:ISpriteShape
11+ {
12+ protected const float epsilon = (1 / (float)(1 << 12));//θepsilon=2pi*2^-14
13+ public SpriteShape(SpriteBody body, SpriteShapeFilter filter)
14+ {
15+ this.Body = body;
16+ this.Filter = filter;
17+ }
18+
19+ public abstract void PointRaise(Shape shape,Vector contactpos);
20+
21+ #region ISpriteShape メンバ
22+
23+
24+ public ISpriteBody Body
25+ {
26+ get;
27+ private set;
28+ }
29+
30+ public SpriteShapeFilter Filter
31+ {
32+ get;
33+ private set;
34+ }
35+
36+ public SpriteShapeType Type
37+ {
38+ get;
39+ protected set;
40+ }
41+
42+ #endregion
43+ }
44+}
--- trunk/Nlgp1/Nlgp1/Parameters/PolygonSpriteShape.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Parameters/PolygonSpriteShape.cs (revision 845)
@@ -0,0 +1,131 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using Box2DX.Collision;
6+using Nlgp1.Common.Parameters;
7+
8+namespace Nlgp1.Parameters
9+{
10+ class PolygonSpriteShape:SpriteShape,IPolygonSpriteShape
11+ {
12+ //List<int> seagmentIndexes = new List<int>();
13+ int seagmentIndex = -1;
14+ int vertexIndex = -1;
15+ List<float> vertexTheta;
16+ Vector center;
17+ //List<Vector> allContactPos = new List<Vector>();
18+ Vector contactPos;
19+
20+ public PolygonSpriteShape(Polygon area,SpriteBody sb,SpriteShapeFilter ssf)
21+ :base(sb,ssf)
22+ {
23+ Area = area;
24+ Type = SpriteShapeType.Polygon;
25+ #region ルックアップテーブル
26+ vertexTheta = new List<float>(area.Vertices.Length);
27+
28+ for (int i = 0; i < Area.Vertices.Length; i++)
29+ {
30+ center += Area.Vertices[i];
31+
32+ }
33+ center /= Area.Vertices.Length;
34+
35+
36+ for (int i = 0; i < Area.Vertices.Length; i++)
37+ {
38+ Vector nowVertex = Area.Vertices[i];
39+ int k = (i + 1) % Area.Vertices.Length;
40+ Vector nextVertex = Area.Vertices[k];
41+ float nowTheta = MathF.Atan2((nowVertex - center).Y, (nowVertex - center).X);
42+ float nextTheta = MathF.Atan2((nextVertex - center).Y, (nextVertex - center).X);
43+ vertexTheta.Add(nextTheta - nowTheta);
44+ }
45+
46+ #endregion
47+
48+ }
49+
50+ public override void PointRaise(Shape shape, Vector contactpos)
51+ {
52+ PolygonSpriteContact spritecontact;
53+
54+
55+ for (int i = 0; i < Area.Vertices.Length; i++)
56+ {
57+ //
58+ int next = (i + 1) % Area.Vertices.Length;
59+
60+ float nowTheta = MathF.Atan2((contactpos - center).Y, (contactpos - center).X);
61+ if ((vertexTheta[next] - epsilon) < nowTheta &&
62+ nowTheta < (vertexTheta[i] + epsilon))
63+ //頂点付近ならVertexIndexに
64+ {
65+ //allContactPos.Add(contactpos);
66+ //seagmentIndexes.Add(i);
67+ spritecontact = new PolygonSpriteContact(
68+ this, ((SpriteUserData)shape.GetBody().GetUserData()).SpriteShape, contactpos,seagmentIndex, vertexIndex);
69+ }
70+
71+
72+ #region なくなった
73+ /*
74+ Vector vertex = Area.Vertices[i] * 100;
75+ Vector nVertex = Area.Vertices[(i + 1) % Area.Vertices.Length] * 100;
76+ bool VertexXisOrder=(vertex.X >= nVertex.X);
77+ bool VertexYisOrder = (vertex.Y >= nVertex.Y);
78+ bool isinXsegment = false;
79+
80+ if (VertexXisOrder && ((int)vertex.X <= contactpos.X) && (contactpos.X <= nVertex.X))
81+ {
82+ isinXsegment = true;
83+ }
84+ else
85+ if (!VertexXisOrder && (nVertex.X <= contactpos.X) && (contactpos.X <= vertex.X))
86+ {
87+ isinXsegment = true;
88+ }
89+ if (isinXsegment)
90+ {
91+ if (VertexYisOrder && (vertex.Y <= contactpos.Y) && (contactpos.Y <= nVertex.Y))
92+ seagmentindexes.Add(i);
93+ if (!VertexYisOrder && (nVertex.Y >= contactpos.Y) && (contactpos.Y <= vertex.Y))
94+ seagmentindexes.Add(i);
95+ }
96+ */
97+ #endregion
98+
99+ }
100+
101+ }
102+
103+ public void OnStepped(object sender, PolygonSpriteShapeSteppedEventArgs e)
104+ {
105+ if (Stepped != null)
106+ {
107+ Stepped(sender, e);
108+
109+ }
110+ }
111+
112+
113+ #region IPolygonSpriteShape メンバ
114+
115+ public event EventHandler<PolygonSpriteShapeSteppedEventArgs> Stepped;
116+ //
117+ public IEnumerable<IPolygonSpriteContact> Contacts
118+ {
119+ get;
120+ private set;
121+ }
122+
123+ public Polygon Area
124+ {
125+ get;
126+ private set;
127+ }
128+
129+ #endregion
130+ }
131+}
--- trunk/Nlgp1/Nlgp1/Parameters/SpriteUserData.cs (revision 844)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteUserData.cs (revision 845)
@@ -10,9 +10,9 @@
1010 {
1111 class SpriteUserData:myUserData
1212 {
13- public ISpriteShape SpriteShape;
13+ public SpriteShape SpriteShape;
1414 //
15- public SpriteUserData(ISpriteShape ss)
15+ public SpriteUserData(SpriteShape ss)
1616 : base()
1717 {
1818 SpriteShape = ss;
--- trunk/Nlgp1/Nlgp1/Parameters/ISpriteShape.cs (revision 844)
+++ trunk/Nlgp1/Nlgp1/Parameters/ISpriteShape.cs (revision 845)
@@ -15,6 +15,8 @@
1515 /// </summary>
1616 ISpriteBody Body { get; }
1717
18+ SpriteShapeType Type { get; }
19+
1820 /// <summary>
1921 /// 衝突フィルター
2022 /// </summary>
--- trunk/Nlgp1/Nlgp1/Parameters/PolygonShapeContact.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Parameters/PolygonShapeContact.cs (revision 845)
@@ -0,0 +1,43 @@
1+
2+using System.Collections.Generic;
3+
4+namespace Nlgp1.Parameters
5+{
6+ class PolygonSpriteContact : SpriteContact,IPolygonSpriteContact
7+ {
8+ public PolygonSpriteContact(SpriteShape source, SpriteShape target,
9+ Vector position,int edgeIndice,int vertexIndice):base(source,target)
10+ {
11+ Position = position;
12+ EdgeIndice = edgeIndice;
13+ VertexIndice = vertexIndice;
14+ }
15+
16+ Vector position;
17+ int edgeindice;
18+ int vertexindice;
19+
20+ #region IPolygonSpriteContact メンバ
21+
22+ public Vector Position
23+ {
24+ get { return position; }
25+ private set { position = value; }
26+ }
27+
28+ public int EdgeIndice
29+ {
30+ get { return edgeindice; }
31+ private set { edgeindice = value; }
32+ }
33+
34+ public int VertexIndice
35+ {
36+ get { return vertexindice; }
37+ private set { vertexindice = value; }
38+ }
39+
40+ #endregion
41+ }
42+}
43+
--- trunk/Nlgp1/Nlgp1/Parameters/SpriteBody.cs (revision 844)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteBody.cs (revision 845)
@@ -102,7 +102,6 @@
102102 {
103103 if (this.chara is DynamicRigid)
104104 {
105- ////todo どちらにするかまだ保留中
106105 ////((DynamicRigid)chara).ApplyImpulse(normalgravity);
107106 //chara.SelfBody.SetLinearVelocity(normalgravity);
108107 }
--- trunk/Nlgp1/Nlgp1/Parameters/SpriteContactListener.cs (revision 844)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteContactListener.cs (revision 845)
@@ -40,58 +40,67 @@
4040 void PointRaise(ContactPoint cp)
4141 {
4242 allcontacts++;
43-
44- Shape s1=cp.Shape1,s2=cp.Shape2;
45- Vector s1pos=s1.GetBody().GetPosition(),s2pos=s2.GetBody().GetPosition();
4643
44+ Shape s1 = cp.Shape1, s2 = cp.Shape2;
45+ Vector s1pos = s1.GetBody().GetPosition(), s2pos = s2.GetBody().GetPosition();
46+
4747 if (DoubledCheck(s1, s2)) return;
4848 shape1s.Add(s1); shape2s.Add(s2);
4949 contactPoints.Add(cp);
50+ SpriteUserData nud1 = cp.Shape1.GetBody().GetUserData() as SpriteUserData;
51+ SpriteUserData nud2 = cp.Shape2.GetBody().GetUserData() as SpriteUserData;
5052
51- //seagmentindexes1.Add(
52- //間違ってるかもしれないので用検証
53+ nud1.SpriteShape.PointRaise(cp.Shape1, cp.Position);
54+ nud2.SpriteShape.PointRaise(cp.Shape2, cp.Position);
55+ //else{return;}
56+ // if(nud2.SpriteShape.Type==SpriteShapeType.Polygon)
57+ // {
58+ // p2=((PolygonSpriteShape)nud1.SpriteShape).Area;
59+ // }
5360
54- float upper, lower;
55- //if (s1dirs[eventcontacts] == Direction.Left || s1dirs[eventcontacts] == Direction.Right)
56- {
61+ // seagmentindexes1.Add(se
5762
58- if (s1pos.Y > s2pos.Y)
59- {
60- upper = CalcfromShape.GetBottom(s2); lower = CalcfromShape.GetUpper(s1);
61- }
62- else
63- {
64- upper = CalcfromShape.GetBottom(s1); lower = CalcfromShape.GetUpper(s2);
65- }
66- }
67- //else
68- {
69- if (s1pos.X > s2pos.X)
70- {
71- upper = CalcfromShape.GetRight(s1); lower = CalcfromShape.GetLeft(s2);
72- }
73- else
74- {
75- upper = CalcfromShape.GetRight(s2); lower = CalcfromShape.GetLeft(s1);
76- }
77- }
7863
79- SpriteUserData nud1 = cp.Shape1.GetBody().GetUserData() as SpriteUserData;
80- SpriteUserData nud2 = cp.Shape2.GetBody().GetUserData() as SpriteUserData;
81- ////このフレームで今までのすべてのコンタクト数とワールドのコンタクト数を比べる
82- //if (GameMap.World.GetContactCount() != allcontacts)
83- //{
64+ // float upper, lower;
65+ // //if (s1dirs[eventcontacts] == Direction.Left || s1dirs[eventcontacts] == Direction.Right)
66+ // {
8467
85- //}
86-
87- //配列とかコレクションを渡す、まさにコンタクツ
88- //nud1.SpriteShape.Contacts=
89- ////衝突辺が水平なら各頂点のX座標、垂直ならY座標Upper,Lower
90- //SpriteShapeHittedEventArgs e = new SpriteShapeHittedEventArgs(nud1.SpriteShape, nud2.SpriteShape, s1dirs[cont2], lower, upper);
91- //nud1.SpriteShape.OnHitted(this, e);
92- //SpriteShapeHittedEventArgs e2 = new SpriteShapeHittedEventArgs(nud2.SpriteShape, nud1.SpriteShape, s1dirs[cont2], lower, upper);
93- //nud2.SpriteShape.OnHitted(this, e2);
94- eventcontacts++;
68+ // if (s1pos.Y > s2pos.Y)
69+ // {
70+ // upper = CalcfromShape.GetBottom(s2); lower = CalcfromShape.GetUpper(s1);
71+ // }
72+ // else
73+ // {
74+ // upper = CalcfromShape.GetBottom(s1); lower = CalcfromShape.GetUpper(s2);
75+ // }
76+ // }
77+ // //else
78+ // {
79+ // if (s1pos.X > s2pos.X)
80+ // {
81+ // upper = CalcfromShape.GetRight(s1); lower = CalcfromShape.GetLeft(s2);
82+ // }
83+ // else
84+ // {
85+ // upper = CalcfromShape.GetRight(s2); lower = CalcfromShape.GetLeft(s1);
86+ // }
87+ // }
88+
89+
90+ // ////このフレームで今までのすべてのコンタクト数とワールドのコンタクト数を比べる
91+ // //if (GameMap.World.GetContactCount() != allcontacts)
92+ // //{
93+
94+ // //}
95+
96+ // //配列とかコレクションを渡す、まさにコンタクツ
97+ // //nud1.SpriteShape.Contacts=
98+ // ////衝突辺が水平なら各頂点のX座標、垂直ならY座標Upper,Lower
99+ // //SpriteShapeHittedEventArgs e = new SpriteShapeHittedEventArgs(nud1.SpriteShape, nud2.SpriteShape, s1dirs[cont2], lower, upper);
100+ // //nud1.SpriteShape.OnHitted(this, e);
101+ // //SpriteShapeHittedEventArgs e2 = new SpriteShapeHittedEventArgs(nud2.SpriteShape, nud1.SpriteShape, s1dirs[cont2], lower, upper);
102+ // //nud2.SpriteShape.OnHitted(this, e2);
103+ // eventcontacts++;
95104 }
96105
97106 bool DoubledCheck(Shape s,Shape s2)
@@ -121,14 +130,8 @@
121130 return Direction.Bottom;
122131 }
123132
124- int segmentCheck(Shape shape, Vector pos)
125- {
126- //Userdata追加?
127- Vector spos = shape.GetBody().GetPosition();
128- //if(shape.
129- return 0;
130- }
131133
134+
132135 Vector getUpperLower(Shape s1, Shape s2, Direction dir)
133136 {
134137 float upper, lower;
--- trunk/Nlgp1/Nlgp1/Parameters/SpriteShapeType.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Parameters/SpriteShapeType.cs (revision 845)
@@ -0,0 +1,13 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+
6+namespace Nlgp1.Parameters
7+{
8+ public enum SpriteShapeType
9+ {
10+ Polygon,
11+ Circle,
12+ }
13+}
--- trunk/Nlgp1/Nlgp1/Parameters/IPolygonSpriteContact.cs (revision 844)
+++ trunk/Nlgp1/Nlgp1/Parameters/IPolygonSpriteContact.cs (revision 845)
@@ -12,16 +12,16 @@
1212 /// <summary>
1313 /// Sourceからみた相対的な衝突位置
1414 /// </summary>
15- IEnumerable<Vector> Positions { get; }
15+ Vector Position { get; }
1616
1717 /// <summary>
1818 /// 衝突辺のインデックス群
1919 /// </summary>
20- IEnumerable<int> EdgeIndices { get; }
20+ int EdgeIndice { get; }
2121
2222 /// <summary>
2323 /// 衝突頂点のインデックス群
2424 /// </summary>
25- IEnumerable<int> VertexIndices { get; }
25+ int VertexIndice { get; }
2626 }
2727 }
--- trunk/Nlgp1/Nlgp1/Parameters/CircleSpriteContact.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Parameters/CircleSpriteContact.cs (revision 845)
@@ -0,0 +1,37 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+
6+namespace Nlgp1.Parameters
7+{
8+ class CircleSpriteContact:SpriteContact,ICircleSpriteContact
9+ {
10+ public CircleSpriteContact(SpriteShape source, SpriteShape target,
11+ Vector position,float angle)
12+ : base(source, target)
13+ {
14+
15+ }
16+
17+ #region ICircleSpriteContact メンバ
18+
19+ public ICircleSpriteShape Shape
20+ {
21+ //todo 後で
22+ get { throw new NotImplementedException(); }
23+ }
24+
25+ public Vector Position
26+ {
27+ get { throw new NotImplementedException(); }
28+ }
29+
30+ public float Angle
31+ {
32+ get { throw new NotImplementedException(); }
33+ }
34+
35+ #endregion
36+ }
37+}
--- trunk/Nlgp1/Nlgp1/Parameters/CircleSpriteShape.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1/Parameters/CircleSpriteShape.cs (revision 845)
@@ -0,0 +1,40 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+
6+namespace Nlgp1.Parameters
7+{
8+ class CircleSpriteShape:SpriteShape, ICircleSpriteShape
9+ {
10+ public CircleSpriteShape(Circle area,SpriteBody sb,SpriteShapeFilter ssf)
11+ :base(sb,ssf)
12+ {
13+ Area = area;
14+ Type = SpriteShapeType.Circle;
15+ }
16+
17+ public override void PointRaise(global::Box2DX.Collision.Shape shape, Vector contactpos)
18+ {
19+ throw new NotImplementedException();
20+ }
21+
22+ #region ICircleSpriteShape メンバ
23+
24+ public Circle Area
25+ {
26+ get;
27+ private set;
28+ }
29+
30+ public event EventHandler<CircleSpriteShapeSteppedEventArgs> Stepped;
31+
32+ public IEnumerable<ICircleSpriteContact> Contacts
33+ {
34+ get;
35+ set;
36+ }
37+
38+ #endregion
39+ }
40+}
--- trunk/Nlgp1/Nlgp1.Box2DX.Test/CevTest.cs (revision 844)
+++ trunk/Nlgp1/Nlgp1.Box2DX.Test/CevTest.cs (revision 845)
@@ -42,7 +42,7 @@
4242 void playerhit(Shape player, Shape another)
4343 {
4444 if (((myUserData)another.GetBody().GetUserData()).name == "sail")
45- //todo myUserdataにRaycastとかさせるべきか
45+
4646 //todo RigidBodyにisRayCastの定義を加え、Rayをコントロールする
4747 {
4848 myUserData data = (myUserData)player.GetBody().GetUserData();
--- trunk/Nlgp1/Nlgp1.Box2DX/ContactEvent.cs (revision 844)
+++ trunk/Nlgp1/Nlgp1.Box2DX/ContactEvent.cs (revision 845)
@@ -28,8 +28,6 @@
2828
2929 void contactRaise(ContactPoint p)
3030 {
31- /*todo GetBodyを参照しないといけない理由
32- */
3331 myUserData u = p.Shape1.GetBody().GetUserData() as myUserData;
3432 myUserData u2 = p.Shape2.GetBody().GetUserData() as myUserData;
3533 //何故かはわからないが、shape1は必ずあたった方になる
--- trunk/Nlgp1/Nlgp1.Common/Parameters/MathF.cs (revision 844)
+++ trunk/Nlgp1/Nlgp1.Common/Parameters/MathF.cs (revision 845)
@@ -6,8 +6,8 @@
66
77 public const float PI = ( float )( Math.PI );
88
9- public static float Atan2( float x , float y ) {
10- return ( float )( Math.Atan2( x , y ) );
9+ public static float Atan2( float y , float x ) {
10+ return ( float )( Math.Atan2( y , x ) );
1111 }
1212
1313 public static float Ceiling( float f ) {
Show on old repository browser