• R/O
  • SSH
  • HTTPS

nlgp1: Commit


Commit MetaInfo

Revision715 (tree)
Zeit2011-02-17 10:05:27
Autormassa_senohito

Log Message

Gamemainを一応更新
CalcfromShape.csを追加
CevTestの処理を進める

Ändern Zusammenfassung

Diff

--- trunk/Nlgp1/Nlgp1.B2DX/Gamemain.cs (revision 714)
+++ trunk/Nlgp1/Nlgp1.B2DX/Gamemain.cs (revision 715)
@@ -57,7 +57,7 @@
5757 bool keyflag = false;
5858 //サイズは半径で設定する
5959 //todo IBoxインターフェイスからIBox.MakeShapeとか呼びだして、構成すれば処理を分けられるはず
60- DynamicRigid d = new DynamicRigid(new Vec2(42, 170), 90 * pi / 180, world, 16, 16, false,
60+ DynamicRigid d = new DynamicRigid(new Vec2(42, 170), 0 * pi / 180, world, 16, 16, false,
6161 new Dictionary<UserDataKind, string>()
6262 {
6363 { UserDataKind.Name, "player" },
@@ -126,7 +126,7 @@
126126
127127 while (DX.ProcessMessage())
128128 {
129-
129+ c1.ApplyImpulse(new Vec2(3, 0));
130130 //List<Shape> shape = d2.Shapelist;
131131 //このインデックスをSetFilterに渡す
132132 //Shape.GetBody().GetUserData();がユーザーデータ
@@ -156,7 +156,7 @@
156156 DX.DrawString(2, 27, world.Gravity.Y.ToString(), new DX.COLOR_U8(0xffffff));
157157
158158 DX.DrawRotaGraph((int)d.Position.X, (int)d.Position.Y, 1, d.Angle, mech, true, true);
159- DX.DrawRotaGraph((int)s.Position.X, (int)s.Position.Y, 1, 0, mech, false);
159+ DX.DrawRotaGraph((int)s.Position.X, (int)s.Position.Y, 1, s.Angle, mech, false);
160160
161161 //試しのRaycast,自分の下から30から10だけ下に光を伸ばす
162162 d2.color = Colors.Red;
--- trunk/Nlgp1/Nlgp1.B2DX/CalcfromShape.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1.B2DX/CalcfromShape.cs (revision 715)
@@ -0,0 +1,44 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Text;
4+using Box2DX.Collision;
5+using Box2DX.Dynamics;
6+using Box2DX.Common;
7+
8+
9+namespace Nlgp1.B2DX
10+{
11+ public static class CalcfromShape
12+ {
13+ public static float GetUpper(Shape s)
14+ {
15+ AABB aabb;
16+ Caabb(out aabb, s);
17+ return aabb.LowerBound.Y;
18+ }
19+ public static float GetBottom(Shape s)
20+ {
21+ AABB aabb;
22+ Caabb(out aabb, s);
23+ return aabb.UpperBound.Y;
24+ }
25+ public static float GetLeft(Shape s)
26+ {
27+ AABB aabb;
28+ Caabb(out aabb, s);
29+ return aabb.LowerBound.X;
30+ }
31+ public static float GetRight(Shape s)
32+ {
33+ AABB aabb;
34+ Caabb(out aabb, s);
35+ return aabb.UpperBound.X;
36+ }
37+
38+ static void Caabb(out AABB aabb, Shape s)
39+ {
40+ XForm x = new XForm(s.GetBody().GetPosition(), new Mat22(s.GetBody().GetAngle()));
41+ s.ComputeAABB(out aabb, x);
42+ }
43+ }
44+}
--- trunk/Nlgp1/Nlgp1.B2DX.Test/CevTest.cs (revision 714)
+++ trunk/Nlgp1/Nlgp1.B2DX.Test/CevTest.cs (revision 715)
@@ -2,16 +2,18 @@
22 using System.Collections.Generic;
33 using System.Text;
44 using DxLibDLL;
5-using Nlgp1.B2DX;
5+
66 using Box2DX.Dynamics.Controllers;
77 using Box2DX.Collision;
88 using Box2DX.Dynamics;
99 using Box2DX.Common;
1010
11-namespace Nlgp1.B2DX.Test
11+namespace Nlgp1.B2DX
1212 {
1313 public class CevTest : ContactEvent
1414 {
15+ public static bool isRaycast=false;
16+
1517 public override void Persist(ContactPoint point)
1618 {
1719 base.Persist(point);
@@ -24,20 +26,27 @@
2426 public override void Add(ContactPoint point)
2527 {
2628 base.Add(point);
27- if (((myUserData)point.Shape1.GetBody().GetUserData()).name == "player")
28- playerhit(point.Shape1,point.Shape2);
29- if (((myUserData)point.Shape2.GetBody().GetUserData()).name == "player")
30- playerhit(point.Shape2,point.Shape1);
29+ Shape s1 = point.Shape1, s2 = point.Shape2;
30+ if (((myUserData)s1.GetBody().GetUserData()).name == "player" && ((float)(int)point.Position.Y == CalcfromShape.GetBottom(s2)))
31+ playerhit(s1,s2);
32+ if (((myUserData)s2.GetBody().GetUserData()).name == "player" && ((float)(int)point.Position.Y == CalcfromShape.GetBottom(s1)))
33+ playerhit(s2,s1);
3134 }
3235 void playerhit(Shape player,Shape another)
3336 {
3437 if (((myUserData)another.GetBody().GetUserData()).name == "sail")
3538 //todo myUserdataにRaycastとかさせるべきか
39+
3640 {
37- myUserData data=(myUserData)another.GetBody().GetUserData();
38- //dataはsailである、下から当たった場合、sailはマスクビットを変更する、
41+ myUserData data=(myUserData)player.GetBody().GetUserData();
42+ data.filter.MaskBits = Convert.ToUInt16("100001", 2);
43+ isRaycast = true;
44+ //dataはplayerである、下から当たった場合、playerはマスクビットを変更する、
3945 //当たった物の高さ分上にRayをあて、Rayに当たったものがそれなら、マスクビットを元に戻す
4046 }
4147 }
48+
49+
50+
4251 }
4352 }
\ No newline at end of file
--- trunk/Nlgp1/Nlgp1.B2DX.Test/Gamemain.cs (nonexistent)
+++ trunk/Nlgp1/Nlgp1.B2DX.Test/Gamemain.cs (revision 715)
@@ -0,0 +1,176 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Text;
4+using DxLibDLL;
5+using Box2DX.Collision;
6+using Box2DX.Common;
7+using Box2DX.Dynamics;
8+using System.Collections;
9+
10+namespace Nlgp1.B2DX.Test
11+{
12+ internal class Gamemain
13+ {
14+
15+
16+ static void Main()//Mainにするとこちらがコンパイルできる
17+ {
18+ try
19+ {
20+ DX.SetWindowSize(512, 384);
21+ DX.ChangeWindowMode(true);
22+ DX.SetAlwaysRunFlag(false);
23+ DX.DxLib_Init();
24+
25+
26+
27+ //画像読み込み
28+ DX.Graph mech;
29+ const float pi = (float)(System.Math.PI);
30+
31+ mech = DX.LoadGraph("mech.png");
32+
33+ AABB worldBox = new AABB();
34+ //左上座標の定義
35+ worldBox.LowerBound = new Vec2(0, 0);
36+ //右下座標の定義
37+ worldBox.UpperBound = new Vec2(500, 400);
38+ //重力の定義
39+ Vec2 grav = new Vec2(0, 0);
40+
41+ World world = new World(worldBox, grav, false);
42+ DebugDraw dd = new Debug();
43+ dd.AppendFlags(DebugDraw.DrawFlags.Shape);
44+ world.SetDebugDraw(dd);
45+
46+ world.SetContactListener(new ContactEvent());
47+
48+
49+ Vec2[] gravAr = new Vec2[]
50+ {
51+ new Vec2(0, -18),
52+ new Vec2(18, 0),
53+ new Vec2(-18,0),
54+ new Vec2(0,18)
55+ };
56+
57+ bool keyflag = false;
58+ //サイズは半径で設定する
59+ //todo IBoxインターフェイスからIBox.MakeShapeとか呼びだして、構成すれば処理を分けられるはず
60+ DynamicRigid d = new DynamicRigid(new Vec2(42, 170), 0 * pi / 180, world, 16, 16, false,
61+ new Dictionary<UserDataKind, string>()
62+ {
63+ { UserDataKind.Name, "player" },
64+ { UserDataKind.CategoryBits,"111" },
65+ {UserDataKind.MaskBits,"111"},
66+ {UserDataKind.GroupIndex,"10"}
67+ },
68+ new Dictionary<ObjectDataKind,float>(),
69+ true);
70+ StaticRigid s = new StaticRigid(new Vec2(240, 202), 0, world, 16, 16, true, new Dictionary<UserDataKind, string>() { { UserDataKind.Name, "enemy" }, { UserDataKind.Filter, "111" } }
71+ ,false);
72+ StaticRigid wall = new StaticRigid(new Vec2(250, 16), 0, world, 250, 16, true,
73+ new Dictionary<UserDataKind, string>()
74+ {
75+ { UserDataKind.Name, "wall" },
76+ { UserDataKind.Filter, "110" },
77+ {UserDataKind.GroupIndex,"1"}
78+ }
79+ ,false);
80+ StaticRigid floor = new StaticRigid(new Vec2(500, 168), 0, world, 16, 150, true,
81+ new Dictionary<UserDataKind, string>()
82+ {
83+ { UserDataKind.Name, "floor" },
84+ { UserDataKind.Filter, "101" }
85+ }
86+ ,false);
87+
88+ //dに新しいボディを定義する
89+ //最初にこれ以上新しいボディは作らないと宣言する、さもないとボディは作られない
90+ d.Alregene = false;
91+ float friction = 0, density = 2, restitution = 0;
92+ Polygondef2 p2 = new Polygondef2(friction, restitution, density,new myUserData());
93+ p2.SetAsBox(3, 3, new Vec2(20, 1), 0);
94+ d.Addtolist(p2);
95+ d.MakeBody(world);
96+
97+ //自キャラとの距離を固定する
98+ //Joints joints = new Joints(d.SelfBody, s.SelfBody);
99+ //world.CreateJoint(joints.MakeDistanceJoint());
100+
101+ //ObjectDataKindのAngularDampingは無視されます
102+ float angularDamping = 0.3f, lineardamping = 0.5f, fric2 = 0.4f, rest2 = 2f, dens2 = 1;
103+ FilterData f=new FilterData();
104+ f.CategoryBits = 1;
105+ f.GroupIndex = 1; f.MaskBits = 1;
106+ DynamicRigid d2 = new DynamicRigid(new Vec2(50, 60), 0 * pi / 180, lineardamping, angularDamping);
107+ d2.SetAsBox(16, 16, new Polygondef2(fric2, rest2, dens2, new myUserData("d2", 1, f, 2)), false);
108+ Polygondef2 d2p = new Polygondef2(friction, restitution, density, new myUserData("d2p", 3, f, 2));
109+ d2p.SetAsBox(24, 12, new Vec2(-20, 1), 0);
110+ d2p.Fil();
111+
112+ d2.Addtolist(d2p);
113+ d2.NoRotate = false;
114+ d2.MakeBody(world);
115+
116+ DynamicRigid c1 = new DynamicRigid(new Vec2(300, 90), 0, 0, 0);
117+ c1.SetAsCircle(new CircleDef2(new Vec2(), 20, 0, 0, 1, new myUserData()), false);
118+ c1.MakeBody(world);
119+
120+ DX.SetDrawScreen(DX.DX_SCREEN_BACK);
121+
122+ //todo GetNameAndIdとかやりたい,worldを継承?
123+ //GetNameAndId(); --> Dic<int,string> {{1,"player"},{2,"wall"}}
124+ //GetName(2); -->"player"
125+ //GetIdArr("enemy"); -->["1","4"]
126+
127+ while (DX.ProcessMessage())
128+ {
129+ c1.ApplyImpulse(new Vec2(3, 0));
130+ //List<Shape> shape = d2.Shapelist;
131+ //このインデックスをSetFilterに渡す
132+ //Shape.GetBody().GetUserData();がユーザーデータ
133+ //Shape.Get
134+ f.MaskBits=1;
135+ d2.SetFilter(f, 1);
136+
137+ if (DX.CheckHitKey(DX.KEY_INPUT.RETURN) && !keyflag)
138+ {
139+ //瞬間的にある方向に力を加える(270度が設定されているのでオブジェクトから見て真上へ)
140+ d.ApplyImpulse(new Vec2(0, -990));
141+ }
142+
143+ if (!DX.CheckHitKey(DX.KEY_INPUT.RETURN))
144+ {
145+ keyflag = false;
146+ }
147+
148+ if (DX.CheckHitKey(DX.KEY_INPUT.LEFT))
149+ {
150+ d.ApplyRelativeImpulse(new Vec2(-3 * d.Mass, 0),90);
151+ //d.SelfBody.ApplyTorque(20*d.SelfBody.GetMass());
152+ }
153+ DX.ClearDrawScreen();
154+ DX.ProcessActKeyInput();
155+ DX.DrawString(2, 7, world.Gravity.X.ToString(), new DX.COLOR_U8(0xffffff));
156+ DX.DrawString(2, 27, world.Gravity.Y.ToString(), new DX.COLOR_U8(0xffffff));
157+
158+ DX.DrawRotaGraph((int)d.Position.X, (int)d.Position.Y, 1, d.Angle, mech, true, true);
159+ DX.DrawRotaGraph((int)s.Position.X, (int)s.Position.Y, 1, s.Angle, mech, false);
160+
161+ //試しのRaycast,自分の下から30から10だけ下に光を伸ばす
162+ d2.color = Colors.Red;
163+ Shape[] hit = d2.Raycast(new Vec2(0, 30), new Vec2(0, 50));
164+ world.Step(1 / 60f, 8, 1);
165+
166+ DX.ScreenFlip();
167+ } DX.DxLib_End();
168+ } catch (Exception e)
169+ {
170+ System.Console.Write(e.ToString());
171+ }
172+ }
173+
174+
175+ }
176+}
--- trunk/Nlgp1/Nlgp1.B2DX.Test/Program.cs (revision 714)
+++ trunk/Nlgp1/Nlgp1.B2DX.Test/Program.cs (revision 715)
@@ -8,7 +8,7 @@
88 using Box2DX.Dynamics;
99 using Box2DX.Common;
1010
11-namespace Nlgp1.B2DX.Test
11+namespace Nlgp1.B2DX
1212 {
1313 class Program
1414 {
@@ -46,14 +46,15 @@
4646 f.CategoryBits = 1;
4747 f.GroupIndex = 1; f.MaskBits = 1;
4848 DynamicRigid d2 = new DynamicRigid(new Vec2(50, 60), 45 * pi / 180, lineardamping, angularDamping);
49- d2.SetAsBox(16, 32, new Polygondef2(fric2, rest2, dens2, new myUserData("player", 1, f, 2)), false);
49+ d2.SetAsBox(16, 32, new Polygondef2(fric2, rest2, dens2, new myUserData("player", 1, f, 2, d2)), false);
5050 //以下の4行は飛び出ている方のBoxの定義です、コメントアウトするとなくなります
51+ /*
5152 Polygondef2 d2p = new Polygondef2(friction, restitution, density, new myUserData("d2p", 3, f, 2));
5253 d2p.SetAsBox(24, 12, new Vec2(-20, 1), 0);
5354 d2p.Fil();
5455 d2.Addtolist(d2p);
55-
56- d2.NoRotate = false;
56+ */
57+ d2.NoRotate = true;
5758 d2.MakeBody(world);
5859 //床の定義です
5960 StaticRigid ground = new StaticRigid(new Vec2(250, 350), 0, 0, 0);
@@ -62,7 +63,7 @@
6263 ground.MakeBody(world);
6364
6465 StaticRigid sail = new StaticRigid(new Vec2(250, 120), 0, 0, 0);
65- sail.SetAsBox(250, 25, new Polygondef2(3, 0, 0, new myUserData("sail",0,f,2)), false);
66+ sail.SetAsBox(250, 25, new Polygondef2(3, 0, 0, new myUserData("sail", 0, f, 2, sail)), false);
6667 sail.MakeBody(world);
6768 //Joints joints = new Joints(d1.SelfBody, d2.SelfBody);
6869 //world.CreateJoint(joints.MakeDistanceJoint());
Show on old repository browser