OSDN Git Service

f8ee9dd194c3e7716097e85d2534f47d15d93da4
[mikutoga/TogaGem.git] / src / main / java / jp / sourceforge / mikutoga / pmd / model / RigidInfo.java
1 /*
2  * rigid information
3  *
4  * License : The MIT License
5  * Copyright(c) 2010 MikuToga Partners
6  */
7
8 package jp.sourceforge.mikutoga.pmd.model;
9
10 import jp.sourceforge.mikutoga.pmd.model.DynamicsInfo;
11 import jp.sourceforge.mikutoga.pmd.model.BoneInfo;
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import jp.sourceforge.mikutoga.corelib.I18nText;
15 import jp.sourceforge.mikutoga.corelib.SerialNumbered;
16 import jp.sourceforge.mikutoga.pmd.Pos3d;
17 import jp.sourceforge.mikutoga.pmd.Rad3d;
18 import jp.sourceforge.mikutoga.pmd.RigidBehaviorType;
19
20 /**
21  * 個別の剛体の情報。
22  */
23 public class RigidInfo implements SerialNumbered {
24
25     private final I18nText rigidName = new I18nText();
26
27     private RigidBehaviorType behaviorType = RigidBehaviorType.FOLLOWBONE;
28
29     private final RigidShape rigidShape = new RigidShape();
30     private final Pos3d position = new Pos3d();
31     private final Rad3d rotation = new Rad3d();
32
33     private BoneInfo linkedBone;
34
35     private final DynamicsInfo dynamicsInfo = new DynamicsInfo();
36
37     private final Collection<RigidGroup> throughGroupColl =
38             new ArrayList<RigidGroup>();
39
40     private RigidGroup rigidGroup;
41
42     private int serialNo = -1;
43
44     /**
45      * コンストラクタ。
46      */
47     public RigidInfo(){
48         super();
49         return;
50     }
51
52     /**
53      * 剛体名を返す。
54      * @return 剛体名
55      */
56     public I18nText getRigidName(){
57         return this.rigidName;
58     }
59
60     /**
61      * 剛体の振る舞い種別を返す。
62      * @return 剛体の振る舞い種別
63      */
64     public RigidBehaviorType getBehaviorType(){
65         return this.behaviorType;
66     }
67
68     /**
69      * 剛体の振る舞い種別を設定する。
70      * @param type 剛体の振る舞い種別。
71      * @throws NullPointerException 引数がnull
72      */
73     public void setBehaviorType(RigidBehaviorType type)
74             throws NullPointerException{
75         if(type == null) throw new NullPointerException();
76         this.behaviorType = type;
77         return;
78     }
79
80     /**
81      * 剛体形状を返す。
82      * @return 剛体形状
83      */
84     public RigidShape getRigidShape(){
85         return this.rigidShape;
86     }
87
88     /**
89      * 剛体位置を返す。
90      * @return 剛体位置
91      */
92     public Pos3d getPosition(){
93         return this.position;
94     }
95
96     /**
97      * 剛体姿勢を返す。
98      * @return 剛体姿勢
99      */
100     public Rad3d getRotation(){
101         return this.rotation;
102     }
103
104     /**
105      * 接続ボーンを返す。
106      * @return 接続ボーン
107      */
108     public BoneInfo getLinkedBone(){
109         return this.linkedBone;
110     }
111
112     /**
113      * 接続ボーンを設定する。
114      * @param bone 接続ボーン
115      */
116     public void setLinkedBone(BoneInfo bone){
117         this.linkedBone = bone;
118         return;
119     }
120
121     /**
122      * 剛体の力学パラメータを返す。
123      * @return 力学パラメータ
124      */
125     public DynamicsInfo getDynamicsInfo(){
126         return this.dynamicsInfo;
127     }
128
129     /**
130      * 非衝突グループ集合を返す。
131      * @return 非衝突グループ集合
132      */
133     public Collection<RigidGroup> getThroughGroupColl(){
134         return this.throughGroupColl;
135     }
136
137     /**
138      * 所属する剛体グループを返す。
139      * @return 所属する剛体グループ
140      */
141     public RigidGroup getRigidGroup(){
142         return this.rigidGroup;
143     }
144
145     /**
146      * 所属する剛体グループを設定する。
147      * @param group 所属する剛体グループ
148      */
149     public void setRigidGroup(RigidGroup group){
150         this.rigidGroup = group;
151         return;
152     }
153
154     /**
155      * {@inheritDoc}
156      * @param num {@inheritDoc}
157      */
158     @Override
159     public void setSerialNumber(int num){
160         this.serialNo = num;
161         return;
162     }
163
164     /**
165      * {@inheritDoc}
166      * @return {@inheritDoc}
167      */
168     @Override
169     public int getSerialNumber(){
170         return this.serialNo;
171     }
172
173     /**
174      * {@inheritDoc}
175      * @return {@inheritDoc}
176      */
177     @Override
178     public String toString(){
179         StringBuilder result = new StringBuilder();
180
181         String boneName;
182         if(this.linkedBone == null){
183             boneName = "NOBONE";
184         }else{
185             boneName = this.linkedBone.getBoneName().toString();
186         }
187
188         result.append("Rigid(").append(this.rigidName).append(") ");
189         result.append("[=>")
190               .append(boneName)
191               .append("bone]");
192         result.append(" [").append(this.rigidShape).append("]");
193         result.append(" ").append(this.position);
194         result.append(" ").append(this.rotation);
195         result.append(" [").append(this.dynamicsInfo).append("]");
196         result.append("  [").append(this.behaviorType).append("]");
197
198         result.append(" through[");
199         boolean dumped = false;
200         for(RigidGroup group : this.throughGroupColl){
201             if(dumped) result.append(" ");
202             result.append(group.getGroupNumber());
203             dumped = true;
204         }
205         result.append("]");
206
207         return result.toString();
208     }
209
210 }