OSDN Git Service

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