OSDN Git Service

591bc3d217e613df110b3831bf0c6745c10c1a66
[mikutoga/Pmd2XML.git] / src / main / java / jp / sfjp / mikutoga / pmd / model / RigidShape.java
1 /*
2  * rigid shape 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 jp.sfjp.mikutoga.pmd.RigidShapeType;
11
12 /**
13  * 剛体形状に関する情報。
14  * 球及びカプセルの半径と箱の幅は同じ値が用いられる。
15  */
16 public class RigidShape {
17
18     private RigidShapeType type = RigidShapeType.BOX;
19     private float width  = 0.1f;
20     private float height = 0.1f;
21     private float depth  = 0.1f;
22
23     /**
24      * コンストラクタ。
25      */
26     public RigidShape(){
27         super();
28         return;
29     }
30
31     /**
32      * 剛体形状種別を返す。
33      * @return 剛体形状種別
34      */
35     public RigidShapeType getShapeType(){
36         return this.type;
37     }
38
39     /**
40      * 剛体形状種別を設定する。
41      * @param typeArg 剛体形状種別
42      * @throws NullPointerException 引数がnull
43      */
44     public void setShapeType(RigidShapeType typeArg)
45             throws NullPointerException{
46         if(typeArg == null) throw new NullPointerException();
47         this.type = typeArg;
48         return;
49     }
50
51     /**
52      * 箱の幅を返す。
53      * @return 箱の幅
54      */
55     public float getWidth(){
56         return this.width;
57     }
58
59     /**
60      * 箱の幅を設定する。
61      * @param width 箱の幅
62      */
63     public void setWidth(float width){
64         this.width = width;
65         return;
66     }
67
68     /**
69      * 箱及びカプセルの高さを返す。
70      * @return 箱及びカプセルの高さ
71      */
72     public float getHeight(){
73         return this.height;
74     }
75
76     /**
77      * 箱及びカプセルの高さを設定する。
78      * @param height 箱及びカプセルの高さ
79      */
80     public void setHeight(float height){
81         this.height = height;
82         return;
83     }
84
85     /**
86      * 箱の奥行きを返す。
87      * @return 箱の奥行き
88      */
89     public float getDepth(){
90         return this.depth;
91     }
92
93     /**
94      * 箱の奥行きを設定する。
95      * @param depth 箱の奥行き
96      */
97     public void setDepth(float depth){
98         this.depth = depth;
99         return;
100     }
101
102     /**
103      * 球及びカプセルの半径を返す。
104      * @return 球及びカプセルの半径
105      */
106     public float getRadius(){
107         return this.width;
108     }
109
110     /**
111      * 球及びカプセルの半径を設定する。
112      * @param radius 球及びカプセルの半径
113      */
114     public void setRadius(float radius){
115         this.width = radius;
116         return;
117     }
118
119     /**
120      * {@inheritDoc}
121      * @return {@inheritDoc}
122      */
123     @Override
124     public String toString(){
125         StringBuilder result = new StringBuilder();
126
127         result.append(this.type).append(' ');
128
129         switch(this.type){
130         case SPHERE:
131             result.append("r=").append(this.width);
132             break;
133         case BOX:
134             result.append("w=").append(this.width).append(", ");
135             result.append("h=").append(this.height).append(", ");
136             result.append("d=").append(this.depth);
137             break;
138         case CAPSULE:
139             result.append("r=").append(this.width).append(", ");
140             result.append("h=").append(this.height);
141             break;
142         default:
143             assert false;
144             throw new AssertionError();
145         }
146
147         return  result.toString();
148     }
149
150 }