OSDN Git Service

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