OSDN Git Service

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